Skip to content

Commit 2cd5cf5

Browse files
authored
Merge pull request #489 from jingxu97/April/buildx
Add build rule for Windows container
2 parents a0c8fa2 + 10026de commit 2cd5cf5

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

Dockerfile.Windows

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG BASE_IMAGE
2+
ARG BASE_IMAGE_TAG
3+
4+
FROM mcr.microsoft.com/windows/${BASE_IMAGE}:${BASE_IMAGE_TAG}
5+
LABEL description="PD CSI driver"
6+
COPY bin/gce-pd-csi-driver.exe /gce-pd-csi-driver.exe
7+
8+
USER ContainerAdministrator
9+
ENTRYPOINT ["/gce-pd-csi-driver.exe"]

Makefile

+25-13
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,47 @@
1414

1515
# Args:
1616
# GCE_PD_CSI_STAGING_IMAGE: Staging image repository
17-
17+
REV=$(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
18+
ifdef GCE_PD_CSI_STAGING_VERSION
19+
STAGINGVERSION=${GCE_PD_CSI_STAGING_VERSION}
20+
else
21+
STAGINGVERSION=${REV}
22+
endif
1823
STAGINGIMAGE=${GCE_PD_CSI_STAGING_IMAGE}
19-
STAGINGVERSION=${GCE_PD_CSI_STAGING_VERSION}
2024
DRIVERBINARY=gce-pd-csi-driver
2125
DRIVERWINDOWSBINARY=${DRIVERBINARY}.exe
2226

2327
all: gce-pd-driver
2428
gce-pd-driver:
2529
mkdir -p bin
26-
ifndef GCE_PD_CSI_STAGING_VERSION
27-
$(error "Must set environment variable GCE_PD_CSI_STAGING_VERSION to staging version")
28-
endif
2930
go build -ldflags "-X main.vendorVersion=${STAGINGVERSION}" -o bin/${DRIVERBINARY} ./cmd/
3031

31-
build-windows:
32+
gce-pd-driver-windows:
3233
mkdir -p bin
33-
ifndef GCE_PD_CSI_STAGING_VERSION
34-
$(error "Must set environment variable GCE_PD_CSI_STAGING_VERSION to staging version")
35-
endif
36-
GOOS=windows go build -ldflags "-X main.vendorVersion=${STAGINGVERSION}" -o bin/${DRIVERWINDOWSBINARY} ./cmd/
34+
GOOS=windows go build -ldflags -X=main.vendorVersion=$(STAGINGVERSION) -o bin/${DRIVERWINDOWSBINARY} ./cmd/
3735

3836
build-container:
3937
ifndef GCE_PD_CSI_STAGING_IMAGE
4038
$(error "Must set environment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository")
41-
endif
42-
ifndef GCE_PD_CSI_STAGING_VERSION
43-
$(error "Must set environment variable GCE_PD_CSI_STAGING_VERSION to staging version")
4439
endif
4540
docker build --build-arg TAG=$(STAGINGVERSION) -t $(STAGINGIMAGE):$(STAGINGVERSION) .
4641

42+
build-and-push-windows-container-ltsc2019:
43+
ifndef GCE_PD_CSI_STAGING_IMAGE
44+
$(error "Must set enviroment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository")
45+
endif
46+
@sh init-buildx.sh; \
47+
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --file=Dockerfile.Windows --platform=windows \
48+
-t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore --build-arg BASE_IMAGE_TAG=ltsc2019 --push .
49+
50+
build-and-push-windows-container-1909:
51+
ifndef GCE_PD_CSI_STAGING_IMAGE
52+
$(error "Must set enviroment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository")
53+
endif
54+
@sh init-buildx.sh; \
55+
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --file=Dockerfile.Windows --platform=windows \
56+
-t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore --build-arg BASE_IMAGE_TAG=1909 --push .
57+
4758
push-container: build-container
4859
gcloud docker -- push $(STAGINGIMAGE):$(STAGINGVERSION)
4960

@@ -52,3 +63,4 @@ test-sanity: gce-pd-driver
5263

5364
test-k8s-integration:
5465
go build -o bin/k8s-integration-test ./test/k8s-integration
66+

init-buildx.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
#!/usr/bin/env bash
3+
# Copyright 2020 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit -o nounset -o pipefail
18+
19+
export DOCKER_CLI_EXPERIMENTAL=enabled
20+
21+
# Ensure we use a builder that can leverage it (the default on linux will not)
22+
docker buildx rm windows-builder || true
23+
docker buildx create --use --name=windows-builder

0 commit comments

Comments
 (0)