Skip to content

Add build rule for Windows container #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Dockerfile.Windows
Original file line number Diff line number Diff line change
@@ -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"]
38 changes: 25 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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

test-k8s-integration:
go build -o bin/k8s-integration-test ./test/k8s-integration

23 changes: 23 additions & 0 deletions init-buildx.sh
Original file line number Diff line number Diff line change
@@ -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