Skip to content
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

Add support for windows multi-image tag builds #145

Closed
mauriciopoppe opened this issue Apr 29, 2021 · 2 comments · Fixed by #150
Closed

Add support for windows multi-image tag builds #145

mauriciopoppe opened this issue Apr 29, 2021 · 2 comments · Fixed by #150

Comments

@mauriciopoppe
Copy link
Member

mauriciopoppe commented Apr 29, 2021

When doing a multiarch build (make push-multiarch) we might need to override additional args that might be set in the Dockerfile.Windows file for a multi-image build, for example

https://github.com/kubernetes-csi/node-driver-registrar/blob/bd1ad6268a014dceaa36c71c14a3fc0ad8240b58/Dockerfile.Windows#L1-L15

ARG CORE_IMAGE=servercore
ARG CORE_IMAGE_TAG=1809
ARG BUILD_IMAGE=nanoserver
ARG BUILD_IMAGE_TAG=1809
ARG REGISTRY=mcr.microsoft.com/windows

FROM ${REGISTRY}/${CORE_IMAGE}:${CORE_IMAGE_TAG} as core
FROM ${REGISTRY}/${BUILD_IMAGE}:${BUILD_IMAGE_TAG}
LABEL description="CSI Node driver registrar"

COPY ./bin/csi-node-driver-registrar.exe /csi-node-driver-registrar.exe
COPY --from=core /Windows/System32/netapi32.dll /Windows/System32/netapi32.dll

USER ContainerAdministrator
ENTRYPOINT ["/csi-node-driver-registrar.exe"]

We can override BUILD_IMAGE and BUILD_IMAGE_TAG before building the docker image e.g.

docker build \
   --build-arg BUILD_IMAGE=X \
   --build-arg BUILD_IMAGE_TAG=Y \
   -f Dockerfile.windows .

The existing Makefile has support for https://github.com/kubernetes-csi/csi-release-tools/blob/master/prow.sh#L80 BUILD_PLATFORMS="linux amd64; windows amd64 .exe; ..., in the Makefile this string is split by ; and used in this fragment:

		echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix; do \
			docker buildx build --push \
				--tag $(IMAGE_NAME):$$arch-$$os-$$tag \
				--platform=$$os/$$arch \
				--file $$(eval echo \$${dockerfile_$$os}) \
				--build-arg binary=./bin/$*$$suffix \
				--build-arg ARCH=$$arch \
				--label revision=$(REV) \
				.; \
		done; \

We'd like to include additional build args when calling docker build


One approach that I've seen in PD CSI is to have multiple targets per windows build https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/blob/cfe67c8322c9094030bdf28737a50eb5b1c2a542/Makefile#L51-L78, an approach would be to split BUILD_PLATFORMS to LINUX_BUILD_PLATFORMS and WINDOWS_BUILD_PLATFORMS and then do:

LINUX_BUILD_PLATFORMS="linux ppc64le -ppc64le; linux s390x -s390x; linux arm64 -arm64 ..."
WINDOWS_BUILD_PLATFORMS="windows amd64 nanoserver:1809; windows amd64 servercore:20H2 ..."
	echo "$$linux_build_platforms" | tr ';' '\n' | while read -r os arch suffix; do \
		docker buildx build --push \
			--tag $(IMAGE_NAME):$$arch-$$os-$$tag \
			--platform=$$os/$$arch \
			--file $$(eval echo \$${dockerfile_$$os}) \
			--build-arg binary=./bin/$*$$suffix \
			--build-arg ARCH=$$arch \
			--label revision=$(REV) \
			.; \
	done; \
	echo "$$windows_build_platforms" | tr ';' '\n' | while read -r os arch base_image; do \
		docker buildx build --push \
			--tag $(IMAGE_NAME):$$arch-$$os-$$tag \
			--platform=$$os/$$arch \
			--file $$(eval echo \$${dockerfile_$$os}) \
			--build-arg binary=./bin/$*.exe \
            --build-arg BASE_IMAGE=$$base_image \
			--build-arg ARCH=$$arch \
			--label revision=$(REV) \
			.; \
	done; \

Another approach would be to add more tokens to the string (I'm not sure if at the end to make it backwards compatible) for windows e.g.

BUILD_PLATFORMS="windows amd64 .exe nanoserver:1909; ..."


		echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix base_image; do \
			docker buildx build --push \
				--tag $(IMAGE_NAME):$$arch-$$os-$$tag \
				--platform=$$os/$$arch \
				--file $$(eval echo \$${dockerfile_$$os}) \
				--build-arg binary=./bin/$*$$suffix \
                --build-arg BASE_IMAGE=$$base_image \
				--build-arg ARCH=$$arch \
				--label revision=$(REV) \
				.; \
		done; \

These are just a few approaches, any feedback would be appreciated!

Also ref kubernetes-csi/node-driver-registrar#135

cc @jingxu97

@jingxu97
Copy link

cc @pohly

@pohly
Copy link
Contributor

pohly commented Apr 30, 2021

I prefer extending BUILD_PLATFORMS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants