From 10026dedac7d83474d552b664268a35157e693a7 Mon Sep 17 00:00:00 2001 From: Jing Xu Date: Tue, 14 Apr 2020 16:32:22 -0700 Subject: [PATCH] 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 --- Dockerfile.Windows | 9 +++++++++ Makefile | 38 +++++++++++++++++++++++++------------- init-buildx.sh | 23 +++++++++++++++++++++++ 3 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 Dockerfile.Windows create mode 100755 init-buildx.sh diff --git a/Dockerfile.Windows b/Dockerfile.Windows new file mode 100644 index 000000000..12587e170 --- /dev/null +++ b/Dockerfile.Windows @@ -0,0 +1,9 @@ +ARG BASE_IMAGE +ARG BASE_IMAGE_TAG + +FROM mcr.microsoft.com/windows/${BASE_IMAGE}:${BASE_IMAGE_TAG} +LABEL description="PD CSI driver" +COPY bin/gce-pd-csi-driver.exe /gce-pd-csi-driver.exe + +USER ContainerAdministrator +ENTRYPOINT ["/gce-pd-csi-driver.exe"] diff --git a/Makefile b/Makefile index 1d898fcc4..027e14be9 100644 --- a/Makefile +++ b/Makefile @@ -14,36 +14,47 @@ # Args: # GCE_PD_CSI_STAGING_IMAGE: Staging image repository - +REV=$(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD) +ifdef GCE_PD_CSI_STAGING_VERSION + STAGINGVERSION=${GCE_PD_CSI_STAGING_VERSION} +else + STAGINGVERSION=${REV} +endif STAGINGIMAGE=${GCE_PD_CSI_STAGING_IMAGE} -STAGINGVERSION=${GCE_PD_CSI_STAGING_VERSION} DRIVERBINARY=gce-pd-csi-driver DRIVERWINDOWSBINARY=${DRIVERBINARY}.exe all: gce-pd-driver gce-pd-driver: mkdir -p bin -ifndef GCE_PD_CSI_STAGING_VERSION - $(error "Must set environment variable GCE_PD_CSI_STAGING_VERSION to staging version") -endif go build -ldflags "-X main.vendorVersion=${STAGINGVERSION}" -o bin/${DRIVERBINARY} ./cmd/ -build-windows: +gce-pd-driver-windows: mkdir -p bin -ifndef GCE_PD_CSI_STAGING_VERSION - $(error "Must set environment variable GCE_PD_CSI_STAGING_VERSION to staging version") -endif - GOOS=windows go build -ldflags "-X main.vendorVersion=${STAGINGVERSION}" -o bin/${DRIVERWINDOWSBINARY} ./cmd/ + GOOS=windows go build -ldflags -X=main.vendorVersion=$(STAGINGVERSION) -o bin/${DRIVERWINDOWSBINARY} ./cmd/ build-container: ifndef GCE_PD_CSI_STAGING_IMAGE $(error "Must set environment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository") -endif -ifndef GCE_PD_CSI_STAGING_VERSION - $(error "Must set environment variable GCE_PD_CSI_STAGING_VERSION to staging version") endif docker build --build-arg TAG=$(STAGINGVERSION) -t $(STAGINGIMAGE):$(STAGINGVERSION) . +build-and-push-windows-container-ltsc2019: +ifndef GCE_PD_CSI_STAGING_IMAGE + $(error "Must set enviroment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository") +endif + @sh init-buildx.sh; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --file=Dockerfile.Windows --platform=windows \ + -t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore --build-arg BASE_IMAGE_TAG=ltsc2019 --push . + +build-and-push-windows-container-1909: +ifndef GCE_PD_CSI_STAGING_IMAGE + $(error "Must set enviroment variable GCE_PD_CSI_STAGING_IMAGE to staging image repository") +endif + @sh init-buildx.sh; \ + DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --file=Dockerfile.Windows --platform=windows \ + -t $(STAGINGIMAGE):$(STAGINGVERSION) --build-arg BASE_IMAGE=servercore --build-arg BASE_IMAGE_TAG=1909 --push . + push-container: build-container gcloud docker -- push $(STAGINGIMAGE):$(STAGINGVERSION) @@ -52,3 +63,4 @@ test-sanity: gce-pd-driver test-k8s-integration: go build -o bin/k8s-integration-test ./test/k8s-integration + diff --git a/init-buildx.sh b/init-buildx.sh new file mode 100755 index 000000000..624d5a5c7 --- /dev/null +++ b/init-buildx.sh @@ -0,0 +1,23 @@ +#!/bin/bash +#!/usr/bin/env bash +# Copyright 2020 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -o errexit -o nounset -o pipefail + +export DOCKER_CLI_EXPERIMENTAL=enabled + +# Ensure we use a builder that can leverage it (the default on linux will not) +docker buildx rm windows-builder || true +docker buildx create --use --name=windows-builder