Skip to content

Commit

Permalink
Merge pull request #322 from andyzhangx/windows-image-build
Browse files Browse the repository at this point in the history
chore: refactor Windows image build and add test
  • Loading branch information
k8s-ci-robot committed May 23, 2022
2 parents ec9b26b + af10d5f commit 3de9bdb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml → .github/workflows/linux.yml
@@ -1,4 +1,4 @@
name: Go
name: Linux Unit Test

on:
push:
Expand Down
15 changes: 7 additions & 8 deletions Makefile
Expand Up @@ -21,8 +21,6 @@ GOVERSION ?= 1.17
LINUX_ARCH ?= amd64
WINDOWS_DISTROS ?=

WINDOWS_BASE_IMAGES=$(addprefix mcr.microsoft.com/windows/nanoserver:,$(WINDOWS_DISTROS))

DOCKER=DOCKER_CLI_EXPERIMENTAL=enabled docker
STAGINGVERSION=${VERSION}
STAGINGIMAGE=${REGISTRY}/local-volume-provisioner
Expand All @@ -35,11 +33,6 @@ _pos = $(if $(findstring $1,$2),$(call _pos,$1,\
$(wordlist 2,$(words $2),$2),x $3),$3)
pos = $(words $(call _pos,$1,$2))

# $(call lookup,wanted,list1,list2)
# finds the index of `wanted` in list1, then, it returns the element of `list2`
# at that index
lookup = $(word $(call pos,$1,$2),$3)

all: build-container-linux-amd64
.PHONY: all

Expand Down Expand Up @@ -69,6 +62,12 @@ build-container-linux-%:
--build-arg OS=linux \
--build-arg ARCH=$* .

build-container-windows-%:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -ldflags='-extldflags="-static" -X="main.version=${STAGINGVERSION}"' -mod vendor -o _output/windows/amd64/local-volume-provisioner.exe ./cmd/local-volume-provisioner
$(DOCKER) buildx build --file=./deployment/docker/Dockerfile.Windows --platform=windows/amd64 \
-t $(STAGINGIMAGE):$(STAGINGVERSION)_windows_$* --output=type=$(OUTPUT_TYPE) \
--build-arg OSVERSION=$* .

build-and-push-container-linux-%: init-buildx
CGO_ENABLED=0 GOOS=linux GOARCH=$* go build -a -ldflags '-extldflags "-static"' -mod vendor -o _output/linux/$*/local-volume-provisioner ./cmd/local-volume-provisioner
$(DOCKER) buildx build --file=./deployment/docker/Dockerfile --platform=linux/$* \
Expand All @@ -81,7 +80,7 @@ build-and-push-container-windows-%: init-buildx
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -a -ldflags='-extldflags="-static" -X="main.version=${STAGINGVERSION}"' -mod vendor -o _output/windows/amd64/local-volume-provisioner.exe ./cmd/local-volume-provisioner
$(DOCKER) buildx build --file=./deployment/docker/Dockerfile.Windows --platform=windows/amd64 \
-t $(STAGINGIMAGE):$(STAGINGVERSION)_windows_$* \
--build-arg BASE_IMAGE=$(call lookup,$*,$(WINDOWS_DISTROS),$(WINDOWS_BASE_IMAGES)) \
--build-arg OSVERSION=$* \
--push .

test: build-container-linux-amd64
Expand Down
4 changes: 2 additions & 2 deletions deployment/docker/Dockerfile.Windows
Expand Up @@ -11,8 +11,8 @@
# 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.
ARG BASE_IMAGE
FROM ${BASE_IMAGE}
ARG OSVERSION
FROM mcr.microsoft.com/windows/nanoserver:${OSVERSION}
LABEL description="Local Volume Provisioner"

ARG OS=windows
Expand Down

0 comments on commit 3de9bdb

Please sign in to comment.