1717# specific language governing permissions and limitations
1818# under the License.
1919#
20- set -e
20+ set -euo pipefail
2121
2222PULSAR_IMAGE=${PULSAR_IMAGE:- " streamnative/sn-platform" }
2323PULSAR_IMAGE_TAG=${PULSAR_IMAGE_TAG:- " 2.7.1" }
@@ -34,53 +34,137 @@ PULSARCTL_PYTHON_RUNNER="pulsar-functions-pulsarctl-python-runner"
3434RUNNER_TAG=${RUNNER_TAG:- $PULSAR_IMAGE_TAG }
3535KIND_PUSH=${KIND_PUSH:- false}
3636CI_TEST=${CI_TEST:- false}
37+ PLATFORMS=${PLATFORMS:- " linux/amd64" }
38+ PRIMARY_PLATFORM=${PLATFORMS%% ,* }
39+ RUNNER_BASE_IMAGE=" ${DOCKER_REPO} /${RUNNER_BASE} :${RUNNER_TAG} "
40+ PULSARCTL_RUNNER_BASE_IMAGE=" ${DOCKER_REPO} /${PULSARCTL_RUNNER_BASE} :${RUNNER_TAG} "
41+ JAVA_RUNNER_IMAGE=" ${DOCKER_REPO} /${JAVA_RUNNER} :${RUNNER_TAG} "
42+ PULSARCTL_JAVA_RUNNER_IMAGE=" ${DOCKER_REPO} /${PULSARCTL_JAVA_RUNNER} :${RUNNER_TAG} "
43+ GO_RUNNER_IMAGE=" ${DOCKER_REPO} /${GO_RUNNER} :${RUNNER_TAG} "
44+ PULSARCTL_GO_RUNNER_IMAGE=" ${DOCKER_REPO} /${PULSARCTL_GO_RUNNER} :${RUNNER_TAG} "
45+ PYTHON_RUNNER_IMAGE=" ${DOCKER_REPO} /${PYTHON_RUNNER} :${RUNNER_TAG} "
46+ PULSARCTL_PYTHON_RUNNER_IMAGE=" ${DOCKER_REPO} /${PULSARCTL_PYTHON_RUNNER} :${RUNNER_TAG} "
47+
48+ MULTI_PLATFORM=false
49+ if [[ " ${PLATFORMS} " == * ,* ]]; then
50+ MULTI_PLATFORM=true
51+ fi
52+
53+ PUSH_DEFAULT=false
54+ if [[ " ${DOCKER_REPO} " == " localhost:5000" || " ${MULTI_PLATFORM} " == " true" ]]; then
55+ PUSH_DEFAULT=true
56+ fi
57+ PUSH=${PUSH:- $PUSH_DEFAULT }
58+
59+ if [[ " ${MULTI_PLATFORM} " == " true" && " ${PUSH} " != " true" ]]; then
60+ echo " multi-platform builds require PUSH=true so dependent images can resolve their base images" >&2
61+ exit 1
62+ fi
63+
64+ if [[ " ${MULTI_PLATFORM} " == " true" && " ${KIND_PUSH} " == " true" ]]; then
65+ echo " KIND_PUSH=true is only supported for single-platform builds" >&2
66+ exit 1
67+ fi
68+
69+ build_image () {
70+ local image=$1
71+ local context=$2
72+ shift 2
73+
74+ if [[ " ${MULTI_PLATFORM} " == " true" ]]; then
75+ docker buildx build --platform " ${PLATFORMS} " --push -t " ${image} " " $@ " " ${context} "
76+ else
77+ docker build --platform " ${PRIMARY_PLATFORM} " -t " ${image} " " $@ " " ${context} "
78+ fi
79+ }
80+
81+ tag_local_aliases () {
82+ local source_image=$1
83+ local local_name=$2
84+
85+ if [[ " ${MULTI_PLATFORM} " != " true" ]]; then
86+ docker tag " ${source_image} " " ${local_name} :latest"
87+ fi
88+ }
3789
3890echo " build runner base"
39- docker build --platform linux/amd64 -t ${RUNNER_BASE} images/pulsar-functions-base-runner --build-arg PULSAR_IMAGE=" $PULSAR_IMAGE " --build-arg PULSAR_IMAGE_TAG=" $PULSAR_IMAGE_TAG " --progress=plain
40- docker build --platform linux/amd64 -t ${PULSARCTL_RUNNER_BASE} images/pulsar-functions-base-runner -f images/pulsar-functions-base-runner/pulsarctl.Dockerfile --build-arg PULSAR_IMAGE=" $PULSAR_IMAGE " --build-arg PULSAR_IMAGE_TAG=" $PULSAR_IMAGE_TAG " --progress=plain
41- docker tag ${RUNNER_BASE} " ${DOCKER_REPO} " /${RUNNER_BASE} :" ${RUNNER_TAG} "
42- docker tag ${PULSARCTL_RUNNER_BASE} " ${DOCKER_REPO} " /${PULSARCTL_RUNNER_BASE} :" ${RUNNER_TAG} "
91+ build_image " ${RUNNER_BASE_IMAGE} " images/pulsar-functions-base-runner \
92+ --build-arg PULSAR_IMAGE=" ${PULSAR_IMAGE} " \
93+ --build-arg PULSAR_IMAGE_TAG=" ${PULSAR_IMAGE_TAG} " \
94+ --progress=plain
95+ build_image " ${PULSARCTL_RUNNER_BASE_IMAGE} " images/pulsar-functions-base-runner \
96+ -f images/pulsar-functions-base-runner/pulsarctl.Dockerfile \
97+ --build-arg PULSAR_IMAGE=" ${PULSAR_IMAGE} " \
98+ --build-arg PULSAR_IMAGE_TAG=" ${PULSAR_IMAGE_TAG} " \
99+ --progress=plain
100+ tag_local_aliases " ${RUNNER_BASE_IMAGE} " " ${RUNNER_BASE} "
101+ tag_local_aliases " ${PULSARCTL_RUNNER_BASE_IMAGE} " " ${PULSARCTL_RUNNER_BASE} "
43102
44103echo " build java runner"
45- docker build --platform linux/amd64 -t ${JAVA_RUNNER} images/pulsar-functions-java-runner --build-arg PULSAR_IMAGE=" $PULSAR_IMAGE " --build-arg PULSAR_IMAGE_TAG=" $PULSAR_IMAGE_TAG " --progress=plain
46- docker build --platform linux/amd64 -t ${PULSARCTL_JAVA_RUNNER} images/pulsar-functions-java-runner -f images/pulsar-functions-java-runner/pulsarctl.Dockerfile --build-arg PULSAR_IMAGE=" $PULSAR_IMAGE " --build-arg PULSAR_IMAGE_TAG=" $PULSAR_IMAGE_TAG " --progress=plain
47- docker tag ${JAVA_RUNNER} " ${DOCKER_REPO} " /${JAVA_RUNNER} :" ${RUNNER_TAG} "
48- docker tag ${PULSARCTL_JAVA_RUNNER} " ${DOCKER_REPO} " /${PULSARCTL_JAVA_RUNNER} :" ${RUNNER_TAG} "
104+ build_image " ${JAVA_RUNNER_IMAGE} " images/pulsar-functions-java-runner \
105+ --build-arg BASE_IMAGE=" ${RUNNER_BASE_IMAGE} " \
106+ --build-arg PULSAR_IMAGE=" ${PULSAR_IMAGE} " \
107+ --build-arg PULSAR_IMAGE_TAG=" ${PULSAR_IMAGE_TAG} " \
108+ --progress=plain
109+ build_image " ${PULSARCTL_JAVA_RUNNER_IMAGE} " images/pulsar-functions-java-runner \
110+ -f images/pulsar-functions-java-runner/pulsarctl.Dockerfile \
111+ --build-arg BASE_IMAGE=" ${PULSARCTL_RUNNER_BASE_IMAGE} " \
112+ --build-arg PULSAR_IMAGE=" ${PULSAR_IMAGE} " \
113+ --build-arg PULSAR_IMAGE_TAG=" ${PULSAR_IMAGE_TAG} " \
114+ --progress=plain
115+ tag_local_aliases " ${JAVA_RUNNER_IMAGE} " " ${JAVA_RUNNER} "
116+ tag_local_aliases " ${PULSARCTL_JAVA_RUNNER_IMAGE} " " ${PULSARCTL_JAVA_RUNNER} "
49117
50118echo " build python runner"
51- docker build --platform linux/amd64 -t ${PYTHON_RUNNER} images/pulsar-functions-python-runner --build-arg PULSAR_IMAGE=" $PULSAR_IMAGE " --build-arg PULSAR_IMAGE_TAG=" $PULSAR_IMAGE_TAG " --progress=plain
52- docker build --platform linux/amd64 -t ${PULSARCTL_PYTHON_RUNNER} images/pulsar-functions-python-runner -f images/pulsar-functions-python-runner/pulsarctl.Dockerfile --build-arg PULSAR_IMAGE=" $PULSAR_IMAGE " --build-arg PULSAR_IMAGE_TAG=" $PULSAR_IMAGE_TAG " --build-arg PYTHON_VERSION=" $PYTHON_VERSION " --progress=plain
53- docker tag ${PYTHON_RUNNER} " ${DOCKER_REPO} " /${PYTHON_RUNNER} :" ${RUNNER_TAG} "
54- docker tag ${PULSARCTL_PYTHON_RUNNER} " ${DOCKER_REPO} " /${PULSARCTL_PYTHON_RUNNER} :" ${RUNNER_TAG} "
119+ build_image " ${PYTHON_RUNNER_IMAGE} " images/pulsar-functions-python-runner \
120+ --build-arg BASE_IMAGE=" ${RUNNER_BASE_IMAGE} " \
121+ --build-arg PULSAR_IMAGE=" ${PULSAR_IMAGE} " \
122+ --build-arg PULSAR_IMAGE_TAG=" ${PULSAR_IMAGE_TAG} " \
123+ --progress=plain
124+ build_image " ${PULSARCTL_PYTHON_RUNNER_IMAGE} " images/pulsar-functions-python-runner \
125+ -f images/pulsar-functions-python-runner/pulsarctl.Dockerfile \
126+ --build-arg PULSAR_IMAGE=" ${PULSAR_IMAGE} " \
127+ --build-arg PULSAR_IMAGE_TAG=" ${PULSAR_IMAGE_TAG} " \
128+ --build-arg PYTHON_VERSION=" ${PYTHON_VERSION} " \
129+ --progress=plain
130+ tag_local_aliases " ${PYTHON_RUNNER_IMAGE} " " ${PYTHON_RUNNER} "
131+ tag_local_aliases " ${PULSARCTL_PYTHON_RUNNER_IMAGE} " " ${PULSARCTL_PYTHON_RUNNER} "
55132
56133echo " build go runner"
57- docker build --platform linux/amd64 -t ${GO_RUNNER} images/pulsar-functions-go-runner --progress=plain # go runner is almost the same as runner base, so we no need to given build args for go runner
58- docker build --platform linux/amd64 -t ${PULSARCTL_GO_RUNNER} images/pulsar-functions-go-runner -f images/pulsar-functions-go-runner/pulsarctl.Dockerfile --progress=plain # go runner is almost the same as runner base, so we no need to given build args for go runner
59- docker tag ${GO_RUNNER} " ${DOCKER_REPO} " /${GO_RUNNER} :" ${RUNNER_TAG} "
60- docker tag ${PULSARCTL_GO_RUNNER} " ${DOCKER_REPO} " /${PULSARCTL_GO_RUNNER} :" ${RUNNER_TAG} "
134+ build_image " ${GO_RUNNER_IMAGE} " images/pulsar-functions-go-runner \
135+ --build-arg BASE_IMAGE=" ${RUNNER_BASE_IMAGE} " \
136+ --progress=plain
137+ build_image " ${PULSARCTL_GO_RUNNER_IMAGE} " images/pulsar-functions-go-runner \
138+ -f images/pulsar-functions-go-runner/pulsarctl.Dockerfile \
139+ --build-arg BASE_IMAGE=" ${PULSARCTL_RUNNER_BASE_IMAGE} " \
140+ --progress=plain
141+ tag_local_aliases " ${GO_RUNNER_IMAGE} " " ${GO_RUNNER} "
142+ tag_local_aliases " ${PULSARCTL_GO_RUNNER_IMAGE} " " ${PULSARCTL_GO_RUNNER} "
61143
62144if [ " $KIND_PUSH " = true ] ; then
63145 echo " push images to kind"
64146 clusters=$( kind get clusters)
65147 echo $clusters
66148 for cluster in $clusters
67149 do
68- kind load docker-image " ${DOCKER_REPO} " / ${JAVA_RUNNER} : " ${RUNNER_TAG }" --name $cluster
69- kind load docker-image " ${DOCKER_REPO} " / ${PULSARCTL_JAVA_RUNNER} : " ${RUNNER_TAG }" --name $cluster
70- kind load docker-image " ${DOCKER_REPO} " / ${PYTHON_RUNNER} : " ${RUNNER_TAG }" --name $cluster
71- kind load docker-image " ${DOCKER_REPO} " / ${PULSARCTL_PYTHON_RUNNER} : " ${RUNNER_TAG }" --name $cluster
72- kind load docker-image " ${DOCKER_REPO} " / ${GO_RUNNER} : " ${RUNNER_TAG }" --name $cluster
73- kind load docker-image " ${DOCKER_REPO} " / ${PULSARCTL_GO_RUNNER} : " ${RUNNER_TAG }" --name $cluster
150+ kind load docker-image " ${JAVA_RUNNER_IMAGE } " --name $cluster
151+ kind load docker-image " ${PULSARCTL_JAVA_RUNNER_IMAGE } " --name $cluster
152+ kind load docker-image " ${PYTHON_RUNNER_IMAGE } " --name $cluster
153+ kind load docker-image " ${PULSARCTL_PYTHON_RUNNER_IMAGE } " --name $cluster
154+ kind load docker-image " ${GO_RUNNER_IMAGE } " --name $cluster
155+ kind load docker-image " ${PULSARCTL_GO_RUNNER_IMAGE } " --name $cluster
74156 done
75157fi
76158
77- if [ " $DOCKER_REPO " = " localhost:5000" ]; then
78- docker push " ${DOCKER_REPO} " /${JAVA_RUNNER} :" ${RUNNER_TAG} "
79- docker push " ${DOCKER_REPO} " /${PULSARCTL_JAVA_RUNNER} :" ${RUNNER_TAG} "
80- docker push " ${DOCKER_REPO} " /${PYTHON_RUNNER} :" ${RUNNER_TAG} "
81- docker push " ${DOCKER_REPO} " /${PULSARCTL_PYTHON_RUNNER} :" ${RUNNER_TAG} "
82- docker push " ${DOCKER_REPO} " /${GO_RUNNER} :" ${RUNNER_TAG} "
83- docker push " ${DOCKER_REPO} " /${PULSARCTL_GO_RUNNER} :" ${RUNNER_TAG} "
159+ if [[ " ${PUSH} " == " true" && " ${MULTI_PLATFORM} " != " true" ]]; then
160+ docker push " ${RUNNER_BASE_IMAGE} "
161+ docker push " ${PULSARCTL_RUNNER_BASE_IMAGE} "
162+ docker push " ${JAVA_RUNNER_IMAGE} "
163+ docker push " ${PULSARCTL_JAVA_RUNNER_IMAGE} "
164+ docker push " ${PYTHON_RUNNER_IMAGE} "
165+ docker push " ${PULSARCTL_PYTHON_RUNNER_IMAGE} "
166+ docker push " ${GO_RUNNER_IMAGE} "
167+ docker push " ${PULSARCTL_GO_RUNNER_IMAGE} "
84168fi
85169#
86170# if [ "$CI_TEST" = true ] ; then
93177# kind load docker-image "${DOCKER_REPO}"/${PYTHON_RUNNER}:"${RUNNER_TAG}" --name $cluster
94178# kind load docker-image "${DOCKER_REPO}"/${GO_RUNNER}:"${RUNNER_TAG}" --name $cluster
95179# done
96- # fi
180+ # fi
0 commit comments