Closed mauriciopoppe closed 3 years ago
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
make push-multiarch
Dockerfile.Windows
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.
BUILD_IMAGE
BUILD_IMAGE_TAG
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:
BUILD_PLATFORMS="linux amd64; windows amd64 .exe; ...
;
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
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:
BUILD_PLATFORMS
LINUX_BUILD_PLATFORMS
WINDOWS_BUILD_PLATFORMS
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 https://github.com/kubernetes-csi/node-driver-registrar/issues/135
cc @jingxu97
cc @pohly
I prefer extending BUILD_PLATFORMS.
When doing a multiarch build (
make push-multiarch
) we might need to override additional args that might be set in theDockerfile.Windows
file for a multi-image build, for examplehttps://github.com/kubernetes-csi/node-driver-registrar/blob/bd1ad6268a014dceaa36c71c14a3fc0ad8240b58/Dockerfile.Windows#L1-L15
We can override
BUILD_IMAGE
andBUILD_IMAGE_TAG
before building the docker image e.g.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: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
toLINUX_BUILD_PLATFORMS
andWINDOWS_BUILD_PLATFORMS
and then do: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.
These are just a few approaches, any feedback would be appreciated!
Also ref https://github.com/kubernetes-csi/node-driver-registrar/issues/135
cc @jingxu97