Skip to content

Commit bfbb6f3

Browse files
committed
add parameter base_image and addon_image to BUILD_PARAMETERS
1 parent 7b96bea commit bfbb6f3

File tree

3 files changed

+49
-19
lines changed

3 files changed

+49
-19
lines changed

Diff for: build.make

+38-11
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
# force the usage of /bin/bash instead of /bin/sh
16+
SHELL := /bin/bash
17+
1518
.PHONY: build-% build container-% container push-% push clean test
1619

1720
# A space-separated list of all commands in the repository, must be
@@ -63,26 +66,35 @@ endif
6366
# Specific packages can be excluded from each of the tests below by setting the *_FILTER_CMD variables
6467
# to something like "| grep -v 'github.com/kubernetes-csi/project/pkg/foobar'". See usage below.
6568

66-
# BUILD_PLATFORMS contains a set of <os> <arch> <suffix> triplets,
69+
# BUILD_PLATFORMS contains a set of tuples [os arch suffix base_image addon_image]
6770
# separated by semicolon. An empty variable or empty entry (= just a
6871
# semicolon) builds for the default platform of the current Go
6972
# toolchain.
7073
BUILD_PLATFORMS =
7174

7275
# Add go ldflags using LDFLAGS at the time of compilation.
73-
IMPORTPATH_LDFLAGS = -X main.version=$(REV)
76+
IMPORTPATH_LDFLAGS = -X main.version=$(REV)
7477
EXT_LDFLAGS = -extldflags "-static"
75-
LDFLAGS =
78+
LDFLAGS =
7679
FULL_LDFLAGS = $(LDFLAGS) $(IMPORTPATH_LDFLAGS) $(EXT_LDFLAGS)
7780
# This builds each command (= the sub-directories of ./cmd) for the target platform(s)
7881
# defined by BUILD_PLATFORMS.
7982
$(CMDS:%=build-%): build-%: check-go-version-go
8083
mkdir -p bin
81-
echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch suffix; do \
84+
# os_arch_seen captures all of the $$os-$$arch seen for the current binary
85+
# that we want to build, if we've seen an $$os-$$arch before it means that
86+
# we don't need to build it again, this is done to avoid building
87+
# the windows binary multiple times (see the default value of $$BUILD_PLATFORMS)
88+
export os_arch_seen="" && echo '$(BUILD_PLATFORMS)' | tr ';' '\n' | while read -r os arch suffix base_image addon_image; do \
89+
os_arch_seen_pre=$${os_arch_seen%%$$os-$$arch*}; \
90+
if ! [ $${#os_arch_seen_pre} = $${#os_arch_seen} ]; then \
91+
continue; \
92+
fi; \
8293
if ! (set -x; CGO_ENABLED=0 GOOS="$$os" GOARCH="$$arch" go build $(GOFLAGS_VENDOR) -a -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*$$suffix" ./cmd/$*); then \
8394
echo "Building $* for GOOS=$$os GOARCH=$$arch failed, see error(s) above."; \
8495
exit 1; \
8596
fi; \
97+
os_arch_seen+=";$$os-$$arch"; \
8698
done
8799

88100
$(CMDS:%=container-%): container-%: build-%
@@ -131,30 +143,46 @@ DOCKER_BUILDX_CREATE_ARGS ?=
131143
# the tag for the resulting multiarch image.
132144
$(CMDS:%=push-multiarch-%): push-multiarch-%: check-pull-base-ref build-%
133145
set -ex; \
134-
DOCKER_CLI_EXPERIMENTAL=enabled; \
135-
export DOCKER_CLI_EXPERIMENTAL; \
146+
export DOCKER_CLI_EXPERIMENTAL=enabled; \
136147
docker buildx create $(DOCKER_BUILDX_CREATE_ARGS) --use --name multiarchimage-buildertest; \
137148
trap "docker buildx rm multiarchimage-buildertest" EXIT; \
138149
dockerfile_linux=$$(if [ -e ./cmd/$*/Dockerfile ]; then echo ./cmd/$*/Dockerfile; else echo Dockerfile; fi); \
139150
dockerfile_windows=$$(if [ -e ./cmd/$*/Dockerfile.Windows ]; then echo ./cmd/$*/Dockerfile.Windows; else echo Dockerfile.Windows; fi); \
140151
if [ '$(BUILD_PLATFORMS)' ]; then build_platforms='$(BUILD_PLATFORMS)'; else build_platforms="linux amd64"; fi; \
141152
if ! [ -f "$$dockerfile_windows" ]; then \
142-
build_platforms="$$(echo "$$build_platforms" | sed -e 's/windows *[^ ]* *.exe//g' -e 's/; *;/;/g')"; \
153+
build_platforms="$$(echo "$$build_platforms" | sed -e 's/windows *[^ ]* *.exe *[^ ]* *[^ ]*//g' -e 's/; *;/;/g' -e 's/;[ ]*$//')"; \
143154
fi; \
144155
pushMultiArch () { \
145156
tag=$$1; \
146-
echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix; do \
157+
echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix base_image addon_image; do \
158+
escaped_base_image=$${base_image/:/-}; \
159+
if ! [ -z $$escaped_base_image ]; then escaped_base_image+="-"; fi; \
147160
docker buildx build --push \
148-
--tag $(IMAGE_NAME):$$arch-$$os-$$tag \
161+
--tag $(IMAGE_NAME):$$arch-$$os-$$escaped_base_image$$tag \
149162
--platform=$$os/$$arch \
150163
--file $$(eval echo \$${dockerfile_$$os}) \
151164
--build-arg binary=./bin/$*$$suffix \
152165
--build-arg ARCH=$$arch \
166+
--build-arg BASE_IMAGE=$$base_image \
167+
--build-arg ADDON_IMAGE=$$addon_image \
153168
--label revision=$(REV) \
154169
.; \
155170
done; \
156-
images=$$(echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix; do echo $(IMAGE_NAME):$$arch-$$os-$$tag; done); \
171+
images=$$(echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix base_image addon_image; do \
172+
escaped_base_image=$${base_image/:/-}; \
173+
if ! [ -z $$escaped_base_image ]; then escaped_base_image+="-"; fi; \
174+
echo $(IMAGE_NAME):$$arch-$$os-$$escaped_base_image$$tag; \
175+
done); \
157176
docker manifest create --amend $(IMAGE_NAME):$$tag $$images; \
177+
echo "$$build_platforms" | tr ';' '\n' | while read -r os arch suffix base_image addon_image; do \
178+
if [ $$os = "windows" ]; then \
179+
escaped_base_image=$${base_image/:/-}; \
180+
if ! [ -z $$escaped_base_image ]; then escaped_base_image+="-"; fi; \
181+
image=$(IMAGE_NAME):$$arch-$$os-$$escaped_base_image$$tag; \
182+
os_version=$$(docker manifest inspect mcr.microsoft.com/windows/$${base_image} | grep "os.version" | head -n 1 | awk '{print $$2}' | sed -e 's/"//g') || true; \
183+
docker manifest annotate --os-version $$os_version $(IMAGE_NAME):$$tag $$image; \
184+
fi; \
185+
done; \
158186
docker manifest push -p $(IMAGE_NAME):$$tag; \
159187
}; \
160188
if [ $(PULL_BASE_REF) = "master" ]; then \
@@ -288,4 +316,3 @@ test-spelling:
288316
test-boilerplate:
289317
@ echo; echo "### $@:"
290318
@ ./release-tools/verify-boilerplate.sh "$(pwd)"
291-

Diff for: cloudbuild.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ steps:
2727
# The image must contain bash and curl. Ideally it should also contain
2828
# the desired version of Go (currently defined in release-tools/prow.sh),
2929
# but that just speeds up the build and is not required.
30-
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20200421-a2bf5f8'
30+
- name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20210331-c732583'
3131
entrypoint: ./.cloudbuild.sh
3232
env:
3333
- GIT_TAG=${_GIT_TAG}

Diff for: prow.sh

+10-7
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ version_to_git () {
7777
esac
7878
}
7979

80-
configvar CSI_PROW_BUILD_PLATFORMS "linux amd64; windows amd64 .exe; linux ppc64le -ppc64le; linux s390x -s390x; linux arm64 -arm64" "Go target platforms (= GOOS + GOARCH) and file suffix of the resulting binaries"
80+
# the list of windows versions was matched from:
81+
# - https://hub.docker.com/_/microsoft-windows-nanoserver
82+
# - https://hub.docker.com/_/microsoft-windows-servercore
83+
configvar CSI_PROW_BUILD_PLATFORMS "linux amd64; linux ppc64le -ppc64le; linux s390x -s390x; linux arm64 -arm64; windows amd64 .exe nanoserver:1809 servercore:ltsc2019; windows amd64 .exe nanoserver:1909 servercore:1909; windows amd64 .exe nanoserver:2004 servercore:2004; windows amd64 .exe nanoserver:20H2 servercore:20H2" "Go target platforms (= GOOS + GOARCH) and file suffix of the resulting binaries"
8184

8285
# If we have a vendor directory, then use it. We must be careful to only
8386
# use this for "make" invocations inside the project's repo itself because
@@ -723,7 +726,7 @@ install_csi_driver () {
723726
fi
724727
}
725728

726-
# Installs all nessesary snapshotter CRDs
729+
# Installs all nessesary snapshotter CRDs
727730
install_snapshot_crds() {
728731
# Wait until volumesnapshot CRDs are in place.
729732
CRD_BASE_DIR="https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/${CSI_SNAPSHOTTER_VERSION}/client/config/crd"
@@ -770,7 +773,7 @@ install_snapshot_controller() {
770773
fi
771774
echo "$(date +%H:%M:%S)" "waiting for snapshot RBAC setup complete, attempt #$cnt"
772775
cnt=$((cnt + 1))
773-
sleep 10
776+
sleep 10
774777
done
775778

776779
SNAPSHOT_CONTROLLER_YAML="${CONTROLLER_DIR}/deploy/kubernetes/snapshot-controller/setup-snapshot-controller.yaml"
@@ -839,7 +842,7 @@ install_snapshot_controller() {
839842
fi
840843
echo "$(date +%H:%M:%S)" "waiting for snapshot controller deployment to complete, attempt #$cnt"
841844
cnt=$((cnt + 1))
842-
sleep 10
845+
sleep 10
843846
done
844847
}
845848
@@ -979,7 +982,7 @@ run_sanity () (
979982
kubectl exec "${CSI_PROW_SANITY_POD}" -c "${CSI_PROW_SANITY_CONTAINER}" -- mkdir "\$@" && echo "\$@"
980983
EOF
981984
# Using "rm -rf" as fallback for "rmdir" is a workaround for:
982-
# Node Service
985+
# Node Service
983986
# should work
984987
# /nvme/gopath.tmp/src/github.com/kubernetes-csi/csi-test/pkg/sanity/node.go:624
985988
# STEP: reusing connection to CSI driver at dns:///172.17.0.2:30896
@@ -1143,7 +1146,7 @@ make_test_to_junit () {
11431146
# version_gt 1.3.1 v1.2.0 (returns true)
11441147
# version_gt 1.1.1 release-1.2.0 (returns false)
11451148
# version_gt 1.2.0 1.2.2 (returns false)
1146-
function version_gt() {
1149+
function version_gt() {
11471150
versions=$(for ver in "$@"; do ver=${ver#release-}; ver=${ver#kubernetes-}; echo "${ver#v}"; done)
11481151
greaterVersion=${1#"release-"};
11491152
greaterVersion=${greaterVersion#"kubernetes-"};
@@ -1206,7 +1209,7 @@ main () {
12061209
if [ "$rbac_file_path" == "" ]; then
12071210
rbac_file_path="$(pwd)/deploy/kubernetes/rbac.yaml"
12081211
fi
1209-
1212+
12101213
if [ -e "$rbac_file_path" ]; then
12111214
# This is one of those components which has its own RBAC rules (like external-provisioner).
12121215
# We are testing a locally built image and also want to test with the the current,

0 commit comments

Comments
 (0)