Skip to content

Commit 0904417

Browse files
committed
Add build rule for Windows container
Add build rule for windows container. Here we try to enable buildx for buiding windows container image on a linux VM
1 parent a0c8fa2 commit 0904417

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

Makefile

+14-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ STAGINGIMAGE=${GCE_PD_CSI_STAGING_IMAGE}
1919
STAGINGVERSION=${GCE_PD_CSI_STAGING_VERSION}
2020
DRIVERBINARY=gce-pd-csi-driver
2121
DRIVERWINDOWSBINARY=${DRIVERBINARY}.exe
22+
REV=$(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
2223

2324
all: gce-pd-driver
2425
gce-pd-driver:
@@ -28,12 +29,9 @@ ifndef GCE_PD_CSI_STAGING_VERSION
2829
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=$(REV) -o bin/${DRIVERWINDOWSBINARY} ./cmd/
3735

3836
build-container:
3937
ifndef GCE_PD_CSI_STAGING_IMAGE
@@ -44,6 +42,16 @@ ifndef GCE_PD_CSI_STAGING_VERSION
4442
endif
4543
docker build --build-arg TAG=$(STAGINGVERSION) -t $(STAGINGIMAGE):$(STAGINGVERSION) .
4644

45+
build-push-windows-container:
46+
ifndef GCE_PD_CSI_STAGING_IMAGE
47+
$(error "Must set enviroment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository")
48+
endif
49+
ifndef GCE_PD_CSI_STAGING_VERSION
50+
$(error "Must set enviroment variable GCE_PD_CSI_STAGING_VERSION to staging version")
51+
endif
52+
@sh init-buildx.sh; \
53+
DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build -f Dockerfile.Windows --platform=windows -t $(STAGINGIMAGE):$(STAGINGVERSION) --push .
54+
4755
push-container: build-container
4856
gcloud docker -- push $(STAGINGIMAGE):$(STAGINGVERSION)
4957

@@ -52,3 +60,4 @@ test-sanity: gce-pd-driver
5260

5361
test-k8s-integration:
5462
go build -o bin/k8s-integration-test ./test/k8s-integration
63+

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)