File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,48 @@ function write_e2e_env(){
231231
232232}
233233
234+ # # build_image - Builds and pushes the proxy container image using local source.
235+ # # Usage: ./build.sh build_image [image-url]
236+ function build_image() {
237+ local image_url=" ${1:- } "
238+ local push_arg=" "
239+
240+ if [[ -n " $image_url " ]]; then
241+ push_arg=" --push"
242+ echo " Preparing to build and push proxy image: $image_url "
243+ else
244+ echo " Preparing to build proxy image (no push)..."
245+ push_arg=" --load"
246+ image_url=" cloud-sql-proxy:local"
247+ fi
248+
249+ function cleanup_build() {
250+ rm -f cloud-sql-proxy Dockerfile.local
251+ }
252+ trap cleanup_build EXIT
253+
254+ echo " Building binary locally..."
255+ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags " -X github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/cmd.metadataString=container" -o cloud-sql-proxy
256+
257+ echo " Creating temporary Dockerfile..."
258+ cat > Dockerfile.local << EOF
259+ FROM gcr.io/distroless/static:nonroot
260+ COPY cloud-sql-proxy /cloud-sql-proxy
261+ USER 65532
262+ ENTRYPOINT ["/cloud-sql-proxy"]
263+ EOF
264+
265+ echo " Building Docker image..."
266+ docker buildx build \
267+ --platform " linux/amd64" \
268+ -f Dockerfile.local \
269+ -t " $image_url " \
270+ $push_arg \
271+ .
272+
273+ echo " Done."
274+ }
275+
234276# # help - prints the help details
235277# #
236278function help() {
You can’t perform that action at this time.
0 commit comments