Skip to content

Commit

Permalink
Create a common shared script for docker images
Browse files Browse the repository at this point in the history
Create shared script build-upload-a-docker-image.sh, other scripts
could call it to build and upload multi-arch docker images.

Signed-off-by: Kun-Lu <kun.lu@ibm.com>
  • Loading branch information
kun-lu20 committed Jun 14, 2021
1 parent 54ba010 commit 027376a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 158 deletions.
5 changes: 3 additions & 2 deletions docker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ CERT_IMAGE := alpine:3.13
GOLANG_IMAGE := golang:1.15-alpine

BASE_IMAGE := localhost:5000/baseimg:$(VERSION)-$(shell echo $(ROOT_IMAGE) | tr : -)
DEBUG_IMAGE := localhost/debugimg:$(VERSION)-$(shell echo $(GOLANG_IMAGE) | tr : -)
DEBUG_IMAGE := localhost:5000/debugimg:$(VERSION)-$(shell echo $(GOLANG_IMAGE) | tr : -)
PLATFORMS := linux/amd64,linux/s390x

create-baseimg-debugimg: create-baseimg create-debugimg
Expand All @@ -17,6 +17,7 @@ create-baseimg:
docker/base

create-debugimg:
docker build -t $(DEBUG_IMAGE) \
docker buildx build -t $(DEBUG_IMAGE) --push \
--build-arg golang_image=$(GOLANG_IMAGE) \
--platform=linux/amd64 \
docker/debug
61 changes: 15 additions & 46 deletions scripts/build-all-in-one-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,56 +34,25 @@ run_integration_test() {
docker kill $CID
}

build_upload_to_docker(){
local multiarch=$2
# Only push the docker image to dockerhub/quay.io for master/release branch
if [[ "$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "upload $1 to dockerhub/quay.io"
bash scripts/docker-login.sh
if [[ "$multiarch" == "Y" ]]; then
IMAGE_TAGS=$(bash scripts/compute-tags.sh $1)
docker buildx build --output "type=image, push=true" \
--progress=plain --target release \
--build-arg base_image=$BASE_IMAGE \
--build-arg debug_image="golang:1.15-alpine" \
--platform=$PLATFORMS \
--file cmd/all-in-one/Dockerfile \
${IMAGE_TAGS} \
cmd/all-in-one
else
bash scripts/upload-to-registry.sh $1
fi
else
echo 'skip docker images upload for PR'
fi
}
make create-baseimg-debugimg

make build-all-in-one GOOS=linux GOARCH=amd64
make build-all-in-one GOOS=linux GOARCH=s390x

PLATFORMS="linux/amd64,linux/s390x"
make create-baseimg-debugimg
platforms="linux/amd64,linux/s390x"
repo=jaegertracing/all-in-one
BASE_IMAGE="localhost:5000/baseimg:1.0.0-alpine-3.13"

docker buildx build --push \
--progress=plain --target release \
--build-arg base_image=$BASE_IMAGE \
--build-arg debug_image="golang:1.15-alpine" \
--platform=$PLATFORMS \
--file cmd/all-in-one/Dockerfile \
--tag localhost:5000/$repo:latest \
cmd/all-in-one
base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg:1.0.0-alpine-3.13 --build-arg debug_image=golang:1.15-alpine "
#build all-in-one image locally for integration test
bash scripts/build-upload-a-docker-image.sh -l -c all-in-one -b "${base_debug_img_arg}" -d cmd/all-in-one -p "${platforms}" -t release
run_integration_test localhost:5000/$repo
build_upload_to_docker $repo "Y"
#build all-in-one image and upload to dockerhub/quay.io
bash scripts/build-upload-a-docker-image.sh -c all-in-one -b "${base_debug_img_arg}" -d cmd/all-in-one -p "${platforms}" -t release


make build-all-in-one-debug GOOS=linux GOARCH=$GOARCH
repo=jaegertracing/all-in-one-debug
docker build -f cmd/all-in-one/Dockerfile \
--target debug \
--tag $repo:latest cmd/all-in-one \
--build-arg base_image=$BASE_IMAGE \
--build-arg debug_image=localhost/debugimg:1.0.0-golang-1.15-alpine \
--build-arg TARGETARCH=$GOARCH
run_integration_test $repo
build_upload_to_docker $repo "N"
repo=${repo}-debug
base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg:1.0.0-alpine-3.13 --build-arg debug_image=localhost:5000/debugimg:1.0.0-golang-1.15-alpine "
#build all-in-one-debug image locally for integration test
bash scripts/build-upload-a-docker-image.sh -l -c all-in-one-debug -b "${base_debug_img_arg}" -d cmd/all-in-one -t debug
run_integration_test localhost:5000/$repo
#build all-in-one-debug image and upload to dockerhub/quay.io
bash scripts/build-upload-a-docker-image.sh -c all-in-one-debug -b "${base_debug_img_arg}" -d cmd/all-in-one -t debug
70 changes: 70 additions & 0 deletions scripts/build-upload-a-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

set -exu

base_debug_img_arg=""
docker_file_arg="Dockerfile"
target_arg=""
local_test_only='N'
platforms="linux/amd64"
name_space="jaegertracing"

while getopts "lc:b:d:f:p:t:" opt; do
case "${opt}" in
c)
component_name=${OPTARG}
;;
b)
base_debug_img_arg=${OPTARG}
;;
d)
dir_arg=${OPTARG}
;;
f)
docker_file_arg=${OPTARG}
;;
p)
platforms=${OPTARG}
;;
t)
target_arg=${OPTARG}
;;
l)
local_test_only='Y'
;;
esac
done

if [ ! -z ${target_arg} ]; then
target_arg="--target ${target_arg}"
fi

docker_file_arg="${dir_arg}/${docker_file_arg}"

IMAGE_TAGS=$(bash scripts/compute-tags.sh "${name_space}/${component_name}")
upload_flag=""

if [[ "${local_test_only}" = "Y" ]]; then
IMAGE_TAGS="--tag localhost:5000/${name_space}/${component_name}:latest"
PUSHTAG="type=image, push=true"
else
# Only push multi-arch images to dockerhub/quay.io for master branch or for release tags vM.N.P
if [[ "$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "build docker images and upload to dockerhub/quay.io, BRANCH=$BRANCH"
bash scripts/docker-login.sh
PUSHTAG="type=image, push=true"
upload_flag=" and uploading"
else
echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)'
PUSHTAG="type=image, push=false"
fi
fi

docker buildx build --output "${PUSHTAG}" \
--progress=plain ${target_arg} ${base_debug_img_arg}\
--platform=${platforms} \
--file ${docker_file_arg} \
${IMAGE_TAGS} \
${dir_arg}

echo "Finished building${upload_flag} jager-${component_name} =============="
104 changes: 28 additions & 76 deletions scripts/build-upload-docker-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,41 @@

set -euxf -o pipefail

docker_buildx_build(){
local component_name=$1
local dir_arg=$2
local docker_file_arg=$3
make create-baseimg-debugimg

if [[ "$4" == "N" ]]; then
local target_arg=""
else
local target_arg="--target $4 "
fi

if [[ "$5" == "N" ]]; then
local base_debug_img_arg=""
else
local base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg:1.0.0-alpine-3.13 --build-arg debug_image=golang:1.15-alpine "
fi

docker buildx build --output "${PUSHTAG}" \
--progress=plain ${target_arg} ${base_debug_img_arg}\
--platform=${PLATFORMS} \
${docker_file_arg} \
$(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/${component_name}/g") \
${dir_arg}

echo "Finished building multiarch jager-${component_name} =============="
}

build_upload_multiarch_images(){
PLATFORMS="linux/amd64,linux/s390x"
IMAGE_TAGS=$(bash scripts/compute-tags.sh "jaegertracing/jaeger-JAEGERCOMP")
# build multi-arch binaries
make build-binaries-linux
make build-binaries-s390x

# build/upload images for Jaeger backend components
for component in agent collector query ingester
do
docker_buildx_build "${component}" "cmd/${component}" "--file cmd/${component}/Dockerfile" "release" "Y"
done
platforms="linux/amd64,linux/s390x"
base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg:1.0.0-alpine-3.13 --build-arg debug_image=golang:1.15-alpine "

# build/upload images for jaeger-es-index-cleaner and jaeger-es-rollover
docker_buildx_build "es-index-cleaner" "plugin/storage/es" "--file plugin/storage/es/Dockerfile" "N" "N"
docker_buildx_build "es-rollover" "plugin/storage/es" "--file plugin/storage/es/Dockerfile.rollover" "N" "N"
# build/upload images for release version of Jaeger backend components
for component in agent collector query ingester
do
bash scripts/build-upload-a-docker-image.sh -c "jaeger-${component}" -b "${base_debug_img_arg}" -d "cmd/${component}" -p "${platforms}" -t release
done

# build/upload images for jaeger-tracegen and jaeger-anonymizer
for component in tracegen anonymizer
do
docker_buildx_build "${component}" "cmd/${component}" "--file cmd/${component}/Dockerfile" "N" "N"
done
}
# build/upload images for jaeger-es-index-cleaner and jaeger-es-rollover
bash scripts/build-upload-a-docker-image.sh -c jaeger-es-index-cleaner -d plugin/storage/es -p "${platforms}"
bash scripts/build-upload-a-docker-image.sh -c jaeger-es-rollover -d plugin/storage/es -f Dockerfile.rollover -p "${platforms}"

upload_docker_images(){
# upload amd64 docker images
jaeger_components=(
agent-debug
cassandra-schema
collector-debug
query-debug
ingester-debug
)
# build/upload images for jaeger-tracegen and jaeger-anonymizer
for component in tracegen anonymizer
do
bash scripts/build-upload-a-docker-image.sh -c "jaeger-${component}" -d "cmd/${component}" -p "${platforms}"
done

for component in "${jaeger_components[@]}"
do
REPO="jaegertracing/jaeger-${component}"
bash scripts/upload-to-registry.sh $REPO
done
}

# build multi-arch binaries
make build-binaries-linux
make build-binaries-s390x
# build amd64 docker images
make docker-images-jaeger-backend-debug
make docker-images-cassandra

# Only push multi-arch images to dockerhub/quay.io for master branch or for release tags vM.N.P
if [[ "$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "build docker images and upload to dockerhub/quay.io, BRANCH=$BRANCH"
bash scripts/docker-login.sh
upload_docker_images
PUSHTAG="type=image, push=true"
else
echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)'
PUSHTAG="type=image, push=false"
fi
build_upload_multiarch_images

platforms="linux/amd64"
base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg:1.0.0-alpine-3.13 --build-arg debug_image=localhost:5000/debugimg:1.0.0-golang-1.15-alpine "

# build/upload images for debug version of Jaeger backend components
for component in agent collector query ingester
do
bash scripts/build-upload-a-docker-image.sh -c "jaeger-${component}-debug" -b "${base_debug_img_arg}" -d "cmd/${component}" -p "${platforms}" -t debug
done

# build/upload images for jaeger-cassandra-schema
bash scripts/build-upload-a-docker-image.sh -c jaeger-cassandra-schema -d plugin/storage/cassandra/ -p "${platforms}"
23 changes: 4 additions & 19 deletions scripts/hotrod-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ make build-examples GOOS=linux GOARCH=amd64
make build-examples GOOS=linux GOARCH=s390x

REPO=jaegertracing/example-hotrod
PLATFORMS="linux/amd64,linux/s390x"

docker buildx build --push \
--progress=plain \
--platform=$PLATFORMS \
--tag localhost:5000/$REPO:latest \
examples/hotrod
platforms="linux/amd64,linux/s390x"
#build image locally for integration test
bash scripts/build-upload-a-docker-image.sh -l -c example-hotrod -d examples/hotrod -p "${platforms}"

export CID=$(docker run -d -p 8080:8080 localhost:5000/$REPO:latest)
i=0
Expand All @@ -30,15 +26,4 @@ docker rm -f $CID
BRANCH=${BRANCH:?'missing BRANCH env var'}

# Only push images to dockerhub/quay.io for master branch or for release tags vM.N.P
if [[ "$BRANCH" == "master" || $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "upload to dockerhub/quay.io, BRANCH=$BRANCH"
IMAGE_TAGS=$(bash scripts/compute-tags.sh $REPO)
bash scripts/docker-login.sh
docker buildx build --push \
--progress=plain \
--platform=$PLATFORMS \
${IMAGE_TAGS} \
examples/hotrod
else
echo "skip docker images upload, only allowed for tagged releases or master (latest tag)"
fi
bash scripts/build-upload-a-docker-image.sh -c example-hotrod -d examples/hotrod -p "${platforms}"
15 changes: 0 additions & 15 deletions scripts/upload-to-registry.sh

This file was deleted.

0 comments on commit 027376a

Please sign in to comment.