From bae83d304a3d0a4114a2582a96e18438a25852da Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Fri, 19 Mar 2021 14:54:07 -0400 Subject: [PATCH 01/12] Add s390x support on multiarch docker images This change is to add s390x support on multiarch Jaeger docker images Signed-off-by: Kun Lu Signed-off-by: Kun-Lu --- .github/workflows/ci-all-in-one-build.yml | 13 ++- .github/workflows/ci-docker-build.yml | 18 +++- .github/workflows/ci-release.yml | 19 ++-- Makefile | 86 ++++++++++++++++- cmd/agent/Dockerfile | 2 +- cmd/all-in-one/Dockerfile | 4 +- cmd/anonymizer/Dockerfile | 2 +- cmd/collector/Dockerfile | 2 +- cmd/ingester/Dockerfile | 2 +- cmd/query/Dockerfile | 2 +- cmd/tracegen/Dockerfile | 2 +- plugin/storage/es/Dockerfile.rollover | 5 +- scripts/build-all-in-one-image.sh | 109 ++++++++++++++++++++-- scripts/build-upload-docker-images.sh | 99 ++++++++++++++++++++ scripts/upload-all-docker-images.sh | 39 -------- 15 files changed, 333 insertions(+), 71 deletions(-) create mode 100644 scripts/build-upload-docker-images.sh delete mode 100755 scripts/upload-all-docker-images.sh diff --git a/.github/workflows/ci-all-in-one-build.yml b/.github/workflows/ci-all-in-one-build.yml index 5e90c315ac9..46fb6198d4f 100644 --- a/.github/workflows/ci-all-in-one-build.yml +++ b/.github/workflows/ci-all-in-one-build.yml @@ -6,9 +6,14 @@ on: pull_request: branches: [ master ] -jobs: +jobs: all-in-one: runs-on: ubuntu-latest + services: + registry: + image: registry:2 + ports: + - 5000:5000 steps: - uses: actions/checkout@v2 with: @@ -31,6 +36,12 @@ jobs: - name: Install tools run: make install-ci + + - uses: docker/setup-qemu-action@v1 + + - uses: docker/setup-buildx-action@v1 + with: + driver-opts: network=host - name: Build, test, and publish all-in-one image run: bash scripts/build-all-in-one-image.sh diff --git a/.github/workflows/ci-docker-build.yml b/.github/workflows/ci-docker-build.yml index 804f168c431..923f3ad76d2 100644 --- a/.github/workflows/ci-docker-build.yml +++ b/.github/workflows/ci-docker-build.yml @@ -9,6 +9,13 @@ on: jobs: docker-images: runs-on: ubuntu-latest + + services: + registry: + image: registry:2 + ports: + - 5000:5000 + steps: - uses: actions/checkout@v2 with: @@ -32,11 +39,14 @@ jobs: - name: Install tools run: make install-ci - - name: Build docker images - run: make docker + - uses: docker/setup-qemu-action@v1 - - name: Upload docker images - run: bash scripts/upload-all-docker-images.sh + - uses: docker/setup-buildx-action@v1 + with: + driver-opts: network=host + + - name: Build and upload all docker images + run: bash scripts/build-upload-docker-images.sh env: DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} diff --git a/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index dd0b7b3b60d..ff51c86265b 100644 --- a/.github/workflows/ci-release.yml +++ b/.github/workflows/ci-release.yml @@ -8,6 +8,12 @@ on: jobs: publish-release: runs-on: ubuntu-latest + services: + registry: + image: registry:2 + ports: + - 5000:5000 + steps: - uses: actions/checkout@v2 with: @@ -49,13 +55,14 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} if: steps.package-binaries.outcome == 'success' - - name: Build docker images - id: build-images - run: make docker + - uses: docker/setup-qemu-action@v1 - - name: Upload docker images - run: bash scripts/upload-all-docker-images.sh - if: steps.build-images.outcome == 'success' + - uses: docker/setup-buildx-action@v1 + with: + driver-opts: network=host + + - name: Build and upload all docker images + run: bash scripts/build-upload-docker-images.sh env: DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} QUAY_TOKEN: ${{ secrets.QUAY_TOKEN }} diff --git a/Makefile b/Makefile index a5c6b260f02..6ca0c5055d1 100644 --- a/Makefile +++ b/Makefile @@ -72,6 +72,17 @@ MOCKERY=mockery .DEFAULT_GOAL := test-and-lint +BASE_IMAGE_MULTIARCH := localhost:5000/baseimg:$(VERSION)-$(shell echo $(ROOT_IMAGE) | tr : -) +PLATFORMS=linux/amd64,linux/s390x +INGESTER_TAG=$(subst JAGERCOMP,ingester,$(IMAGE_TAGS)) +AGENT_TAG=$(subst JAGERCOMP,agent,$(IMAGE_TAGS)) +COLLECTOR_TAG=$(subst JAGERCOMP,collector,$(IMAGE_TAGS)) +QUERY_TAG=$(subst JAGERCOMP,query,$(IMAGE_TAGS)) +ESINDEX_TAG=$(subst JAGERCOMP,es-index-cleaner,$(IMAGE_TAGS)) +ESROLLOVER_TAG=$(subst JAGERCOMP,es-rollover,$(IMAGE_TAGS)) +TRACEGEN_TAG=$(subst JAGERCOMP,tracegen,$(IMAGE_TAGS)) +ANONYMIZER_TAG=$(subst JAGERCOMP,anonymizer,$(IMAGE_TAGS)) + .PHONY: test-and-lint test-and-lint: test fmt lint @@ -298,7 +309,8 @@ build-platform-binaries: build-agent \ build-all-in-one \ build-examples \ build-tracegen \ - build-anonymizer + build-anonymizer \ + build-esmapping-generator .PHONY: build-all-platforms build-all-platforms: build-binaries-linux build-binaries-windows build-binaries-darwin build-binaries-s390x build-binaries-arm64 build-binaries-ppc64le @@ -309,9 +321,10 @@ docker-images-cassandra: @echo "Finished building jaeger-cassandra-schema ==============" .PHONY: docker-images-elastic -docker-images-elastic: build-esmapping-generator-linux +docker-images-elastic: + GOOS=linux GOARCH=$(GOARCH) $(MAKE) build-esmapping-generator docker build -t $(DOCKER_NAMESPACE)/jaeger-es-index-cleaner:${DOCKER_TAG} plugin/storage/es - docker build -t $(DOCKER_NAMESPACE)/jaeger-es-rollover:${DOCKER_TAG} plugin/storage/es -f plugin/storage/es/Dockerfile.rollover + docker build -t $(DOCKER_NAMESPACE)/jaeger-es-rollover:${DOCKER_TAG} plugin/storage/es -f plugin/storage/es/Dockerfile.rollover --build-arg TARGETARCH=$(GOARCH) @echo "Finished building jaeger-es-indices-clean ==============" docker-images-jaeger-backend: TARGET = release @@ -348,6 +361,73 @@ docker-images-only: docker-images-cassandra \ docker-images-tracegen \ docker-images-anonymizer +.PHONY: multiarch-docker +multiarch-docker: build-binaries-linux \ + build-binaries-s390x \ + multiarch-docker-images-only + +.PHONY: multiarch-docker-images-only +multiarch-docker-images-only: docker-images-jaeger-backend-multiarch \ + docker-images-elastic-multiarch \ + docker-images-tracegen-multiarch \ + docker-images-anonymizer-multiarch + +.PHONY: create-baseimage-multiarch +create-baseimage-multiarch: + docker buildx build -t $(BASE_IMAGE_MULTIARCH) --push \ + --build-arg root_image=$(ROOT_IMAGE) \ + --build-arg cert_image=$(CERT_IMAGE) \ + --platform=$(PLATFORMS) \ + docker/base + echo "Finished building multiarch base image ==============" + +.PHONY: docker-images-jaeger-backend-multiarch +docker-images-jaeger-backend-multiarch: create-baseimage-multiarch + for component in agent collector query ingester ; do \ + docker buildx build --output "$(PUSHTAG)" \ + --progress=plain --target release \ + --build-arg base_image=$(BASE_IMAGE_MULTIARCH) \ + --build-arg debug_image=$(GOLANG_IMAGE) \ + --platform=$(PLATFORMS) \ + --file cmd/$$component/Dockerfile \ + $(subst JAGERCOMP,$$component,$(IMAGE_TAGS)) \ + cmd/$$component; \ + echo "Finished building $$component ==============" ; \ + done + +.PHONY: docker-images-elastic-multiarch +docker-images-elastic-multiarch: + docker buildx build --output "$(PUSHTAG)" \ + --progress=plain \ + --platform=$(PLATFORMS) \ + ${ESINDEX_TAG} \ + plugin/storage/es + docker buildx build --output "$(PUSHTAG)" \ + --progress=plain \ + --platform=$(PLATFORMS) \ + --file plugin/storage/es/Dockerfile.rollover \ + ${ESROLLOVER_TAG} \ + plugin/storage/es + @echo "Finished building multiarch jaeger-es-indices-clean ==============" + +.PHONY: docker-images-tracegen-multiarch +docker-images-tracegen-multiarch: + docker buildx build --output "$(PUSHTAG)" \ + --progress=plain \ + --platform=$(PLATFORMS) \ + ${TRACEGEN_TAG} \ + cmd/tracegen/ + @echo "Finished building multiarch jaeger-tracegen ==============" + +.PHONY: docker-images-anonymizer-multiarch +docker-images-anonymizer-multiarch: + docker buildx build --output "$(PUSHTAG)" \ + --progress=plain \ + --platform=$(PLATFORMS) \ + $(ANONYMIZER_TAG) \ + cmd/anonymizer/ + @echo "Finished building multiarch jaeger-anonymizer ==============" + .PHONY: docker-push docker-push: @while [ -z "$$CONFIRM" ]; do \ diff --git a/cmd/agent/Dockerfile b/cmd/agent/Dockerfile index 2c7ee6f1d51..ae6e3378871 100644 --- a/cmd/agent/Dockerfile +++ b/cmd/agent/Dockerfile @@ -2,7 +2,7 @@ ARG base_image ARG debug_image FROM $base_image AS release -ARG TARGETARCH=amd64 +ARG TARGETARCH ARG USER_UID=10001 COPY agent-linux-$TARGETARCH /go/bin/agent-linux EXPOSE 5775/udp 6831/udp 6832/udp 5778/tcp diff --git a/cmd/all-in-one/Dockerfile b/cmd/all-in-one/Dockerfile index 2c7589f95d7..b6eb9835b8b 100644 --- a/cmd/all-in-one/Dockerfile +++ b/cmd/all-in-one/Dockerfile @@ -2,7 +2,7 @@ ARG base_image ARG debug_image FROM $base_image AS release -ARG TARGETARCH=amd64 +ARG TARGETARCH # Agent zipkin.thrift compact EXPOSE 5775/udp @@ -28,6 +28,8 @@ EXPOSE 16686 COPY all-in-one-linux-$TARGETARCH /go/bin/all-in-one-linux COPY sampling_strategies.json /etc/jaeger/ +RUN chmod +x /go/bin/all-in-one-linux + VOLUME ["/tmp"] ENTRYPOINT ["/go/bin/all-in-one-linux"] CMD ["--sampling.strategies-file=/etc/jaeger/sampling_strategies.json"] diff --git a/cmd/anonymizer/Dockerfile b/cmd/anonymizer/Dockerfile index 096f6929b09..6106f8a2205 100644 --- a/cmd/anonymizer/Dockerfile +++ b/cmd/anonymizer/Dockerfile @@ -1,5 +1,5 @@ FROM scratch -ARG TARGETARCH=amd64 +ARG TARGETARCH COPY anonymizer-linux-$TARGETARCH /go/bin/anonymizer-linux ENTRYPOINT ["/go/bin/anonymizer-linux"] diff --git a/cmd/collector/Dockerfile b/cmd/collector/Dockerfile index c33cedfce9c..44f1b1438aa 100644 --- a/cmd/collector/Dockerfile +++ b/cmd/collector/Dockerfile @@ -2,7 +2,7 @@ ARG base_image ARG debug_image FROM $base_image AS release -ARG TARGETARCH=amd64 +ARG TARGETARCH COPY collector-linux-$TARGETARCH /go/bin/collector-linux EXPOSE 14250/tcp ENTRYPOINT ["/go/bin/collector-linux"] diff --git a/cmd/ingester/Dockerfile b/cmd/ingester/Dockerfile index 8aa6c86e1ca..051652d5950 100644 --- a/cmd/ingester/Dockerfile +++ b/cmd/ingester/Dockerfile @@ -2,7 +2,7 @@ ARG base_image ARG debug_image FROM $base_image AS release -ARG TARGETARCH=amd64 +ARG TARGETARCH COPY ingester-linux-$TARGETARCH /go/bin/ingester-linux EXPOSE 14270/tcp 14271/tcp ENTRYPOINT ["/go/bin/ingester-linux"] diff --git a/cmd/query/Dockerfile b/cmd/query/Dockerfile index 1cd2cb542fd..921a131659b 100644 --- a/cmd/query/Dockerfile +++ b/cmd/query/Dockerfile @@ -2,7 +2,7 @@ ARG base_image ARG debug_image FROM $base_image AS release -ARG TARGETARCH=amd64 +ARG TARGETARCH COPY query-linux-$TARGETARCH /go/bin/query-linux EXPOSE 16686/tcp ENTRYPOINT ["/go/bin/query-linux"] diff --git a/cmd/tracegen/Dockerfile b/cmd/tracegen/Dockerfile index 81cf932de7f..2262d37970e 100644 --- a/cmd/tracegen/Dockerfile +++ b/cmd/tracegen/Dockerfile @@ -1,5 +1,5 @@ FROM scratch -ARG TARGETARCH=amd64 +ARG TARGETARCH COPY tracegen-linux-$TARGETARCH /go/bin/tracegen-linux ENTRYPOINT ["/go/bin/tracegen-linux"] diff --git a/plugin/storage/es/Dockerfile.rollover b/plugin/storage/es/Dockerfile.rollover index f58d054b6e5..4e4f4052eeb 100644 --- a/plugin/storage/es/Dockerfile.rollover +++ b/plugin/storage/es/Dockerfile.rollover @@ -1,4 +1,5 @@ FROM python:3-alpine3.11 +ARG TARGETARCH # Temporary fix for https://github.com/jaegertracing/jaeger/issues/1494 RUN pip install urllib3==1.24.3 @@ -6,6 +7,6 @@ RUN pip install urllib3==1.24.3 RUN pip install elasticsearch elasticsearch-curator COPY ./mappings/* /mappings/ COPY esRollover.py /es-rollover/ -COPY esmapping-generator /usr/bin/ +COPY esmapping-generator-linux-$TARGETARCH /usr/bin/esmapping-generator -ENTRYPOINT ["python3", "/es-rollover/esRollover.py"] +ENTRYPOINT ["python3", "/es-rollover/esRollover.py"] \ No newline at end of file diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 0b89a6f7634..cf682259aaa 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -45,17 +45,108 @@ upload_to_docker() { fi } -make build-all-in-one GOOS=linux GOARCH=$GOARCH +upload_multiarch_to_docker() { + # 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" + REPO=$1 + build_upload_multiarch_to_docker $REPO + else + echo 'skip docker images upload for PR' + fi +} + +build_upload_multiarch_to_docker(){ + DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-"jaegertracingbot"} + DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-} + QUAY_USERNAME=${QUAY_USERNAME:-"jaegertracing+github_workflows"} + QUAY_TOKEN=${QUAY_TOKEN:-} + + ###############Compute the tag + BASE_BUILD_IMAGE=$1 + + ## if we are on a release tag, let's extract the version number + ## the other possible value, currently, is 'master' (or another branch name) + if [[ $BRANCH == v* ]]; then + COMPONENT_VERSION=$(echo ${BRANCH} | grep -Po "([\d\.]+)") + MAJOR_MINOR=$(echo ${COMPONENT_VERSION} | awk -F. '{print $1"."$2}') + MAJOR1=$(echo ${COMPONENT_VERSION} | awk -F. '{print $1}') + + else + COMPONENT_VERSION="latest" + MAJOR_MINOR="" + MAJOR1="" + fi + + # for docker.io + BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${COMPONENT_VERSION}"} + IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE}" + SNAPSHOT_TAG="${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}" + + if [ "${MAJOR_MINOR}x" != "x" ]; then + MAJOR_MINOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR_MINOR}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE}" + fi + + if [ "${MAJOR1}x" != "x" ]; then + MAJOR1_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR1}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR1_IMAGE}" + fi + + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG}" + + ## for quay.io + IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" + + if [ "${MAJOR_MINOR}x" != "x" ]; then + IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR_MINOR_IMAGE}" + fi + + if [ "${MAJOR1}x" != "x" ]; then + IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR1_IMAGE}" + fi + + IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${SNAPSHOT_TAG}" + ################################ + + # Only push images to dockerhub/quay.io for master branch or for release tags vM.N.P + echo "build multiarch images and upload to dockerhub/quay.io, BRANCH=$BRANCH" + + echo "Performing a 'docker login' for DockerHub" + echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" docker.io --password-stdin + + echo "Performing a 'docker login' for Quay" + echo "${QUAY_TOKEN}" | docker login -u "${QUAY_USERNAME}" quay.io --password-stdin + + docker buildx build --output "type=image, push=true" \ + --progress=plain --target release \ + --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ + --build-arg debug_image="golang:1.15-alpine" \ + --platform=$PLATFORMS \ + --file cmd/all-in-one/Dockerfile \ + ${IMAGE_TAGS} \ + cmd/all-in-one +} + +make build-all-in-one GOOS=linux GOARCH=amd64 +make build-all-in-one GOOS=linux GOARCH=s390x + +make create-baseimage-multiarch make create-baseimg-debugimg repo=jaegertracing/all-in-one -docker build -f cmd/all-in-one/Dockerfile \ - --target release \ - --tag $repo:latest cmd/all-in-one \ - --build-arg base_image=localhost/baseimg:1.0.0-alpine-3.12 \ - --build-arg debug_image=localhost/debugimg:1.0.0-golang-1.15-alpine \ - --build-arg TARGETARCH=$GOARCH -run_integration_test $repo -upload_to_docker $repo + +PLATFORMS="linux/amd64,linux/s390x" + +docker buildx build --push \ + --progress=plain --target release \ + --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ + --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 +run_integration_test localhost:5000/$repo +upload_multiarch_to_docker $repo make build-all-in-one-debug GOOS=linux GOARCH=$GOARCH repo=jaegertracing/all-in-one-debug diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh new file mode 100644 index 00000000000..cce1b90188b --- /dev/null +++ b/scripts/build-upload-docker-images.sh @@ -0,0 +1,99 @@ +#!/bin/bash + +set -euxf -o pipefail + +DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-"jaegertracingbot"} +DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-} +QUAY_USERNAME=${QUAY_USERNAME:-"jaegertracing+github_workflows"} +QUAY_TOKEN=${QUAY_TOKEN:-} + +###############Compute the tag +BASE_BUILD_IMAGE=${BASE_BUILD_IMAGE:-"jaegertracing/jaeger-JAGERCOMP"} + +## if we are on a release tag, let's extract the version number +## the other possible value, currently, is 'master' (or another branch name) +if [[ $BRANCH == v* ]]; then + COMPONENT_VERSION=$(echo ${BRANCH} | grep -Po "([\d\.]+)") + MAJOR_MINOR=$(echo ${COMPONENT_VERSION} | awk -F. '{print $1"."$2}') + MAJOR1=$(echo ${COMPONENT_VERSION} | awk -F. '{print $1}') + +else + COMPONENT_VERSION="latest" + MAJOR_MINOR="" + MAJOR1="" +fi + +# for docker.io +BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${COMPONENT_VERSION}"} +IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE}" +SNAPSHOT_TAG="${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}" + +if [ "${MAJOR_MINOR}x" != "x" ]; then + MAJOR_MINOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR_MINOR}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE}" +fi + +if [ "${MAJOR1}x" != "x" ]; then + MAJOR1_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR1}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR1_IMAGE}" +fi + +IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG}" + +## for quay.io +IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" + +if [ "${MAJOR_MINOR}x" != "x" ]; then + IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR_MINOR_IMAGE}" +fi + +if [ "${MAJOR1}x" != "x" ]; then + IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR1_IMAGE}" +fi + +IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${SNAPSHOT_TAG}" +################################# + +# 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 multiarch images and upload to dockerhub/quay.io, BRANCH=$BRANCH" + + echo "Performing a 'docker login' for DockerHub" + echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" docker.io --password-stdin + + echo "Performing a 'docker login' for Quay" + echo "${QUAY_TOKEN}" | docker login -u "${QUAY_USERNAME}" quay.io --password-stdin + + IMAGE_TAGS="${IMAGE_TAGS}" PUSHTAG="type=image, push=true" make multiarch-docker +else + echo 'skip multiarch docker images upload, only allowed for tagged releases or master (latest tag)' + IMAGE_TAGS="${IMAGE_TAGS}" PUSHTAG="type=image, push=false" make multiarch-docker +fi + + +make docker-images-jaeger-backend-debug +make docker-images-cassandra +# Only push amd64 specific 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" +else + echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)' + exit 0 +fi + +export DOCKER_NAMESPACE=jaegertracing + +jaeger_components=( + agent-debug + cassandra-schema + collector-debug + query-debug + ingester-debug +) + +for component in "${jaeger_components[@]}" +do + REPO="jaegertracing/jaeger-${component}" + bash scripts/upload-to-registry.sh $REPO +done + diff --git a/scripts/upload-all-docker-images.sh b/scripts/upload-all-docker-images.sh deleted file mode 100755 index 1a044c2bfcc..00000000000 --- a/scripts/upload-all-docker-images.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash - -# this script expects all docker images to be already built, it only uploads them to Docker Hub - -set -euxf -o pipefail - -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" -else - echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)' - exit 0 -fi - -export DOCKER_NAMESPACE=jaegertracing - -jaeger_components=( - agent - agent-debug - cassandra-schema - es-index-cleaner - es-rollover - collector - collector-debug - query - query-debug - ingester - ingester-debug - tracegen - anonymizer -) - -for component in "${jaeger_components[@]}" -do - REPO="jaegertracing/jaeger-${component}" - bash scripts/upload-to-registry.sh $REPO -done From c0de24a4ce9488b0d4a6799b48e3164471120d57 Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Fri, 23 Apr 2021 15:37:48 -0400 Subject: [PATCH 02/12] Update tag computation and Dockerfile Remove chmod from all-in-one Dockerfile Optimize tag computation code Signed-off-by: Kun-Lu --- cmd/all-in-one/Dockerfile | 2 -- scripts/build-all-in-one-image.sh | 38 +++++++++------------------ scripts/build-upload-docker-images.sh | 38 +++++++++------------------ 3 files changed, 26 insertions(+), 52 deletions(-) diff --git a/cmd/all-in-one/Dockerfile b/cmd/all-in-one/Dockerfile index b6eb9835b8b..d52f9e43151 100644 --- a/cmd/all-in-one/Dockerfile +++ b/cmd/all-in-one/Dockerfile @@ -28,8 +28,6 @@ EXPOSE 16686 COPY all-in-one-linux-$TARGETARCH /go/bin/all-in-one-linux COPY sampling_strategies.json /etc/jaeger/ -RUN chmod +x /go/bin/all-in-one-linux - VOLUME ["/tmp"] ENTRYPOINT ["/go/bin/all-in-one-linux"] CMD ["--sampling.strategies-file=/etc/jaeger/sampling_strategies.json"] diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index cf682259aaa..9e85d1512ac 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -68,45 +68,33 @@ build_upload_multiarch_to_docker(){ ## if we are on a release tag, let's extract the version number ## the other possible value, currently, is 'master' (or another branch name) if [[ $BRANCH == v* ]]; then - COMPONENT_VERSION=$(echo ${BRANCH} | grep -Po "([\d\.]+)") - MAJOR_MINOR=$(echo ${COMPONENT_VERSION} | awk -F. '{print $1"."$2}') - MAJOR1=$(echo ${COMPONENT_VERSION} | awk -F. '{print $1}') + MAJOR_MINOR_PATCH=$(echo ${BRANCH} | grep -Po "([\d\.]+)") + MAJOR_MINOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1"."$2}') + MAJOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1}') else - COMPONENT_VERSION="latest" + MAJOR_MINOR_PATCH="latest" MAJOR_MINOR="" - MAJOR1="" + MAJOR="" fi - # for docker.io - BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${COMPONENT_VERSION}"} - IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE}" + # for docker.io and quay.io + BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"} + IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" SNAPSHOT_TAG="${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}" if [ "${MAJOR_MINOR}x" != "x" ]; then MAJOR_MINOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR_MINOR}" - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE} --tag quay.io/${MAJOR_MINOR_IMAGE}" fi - if [ "${MAJOR1}x" != "x" ]; then - MAJOR1_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR1}" - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR1_IMAGE}" + if [ "${MAJOR}x" != "x" ]; then + MAJOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_IMAGE} --tag quay.io/${MAJOR_IMAGE}" fi - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG} --tag quay.io/${SNAPSHOT_TAG}" - ## for quay.io - IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" - - if [ "${MAJOR_MINOR}x" != "x" ]; then - IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR_MINOR_IMAGE}" - fi - - if [ "${MAJOR1}x" != "x" ]; then - IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR1_IMAGE}" - fi - - IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${SNAPSHOT_TAG}" ################################ # Only push images to dockerhub/quay.io for master branch or for release tags vM.N.P diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index cce1b90188b..6fc20f1ed45 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -13,45 +13,33 @@ BASE_BUILD_IMAGE=${BASE_BUILD_IMAGE:-"jaegertracing/jaeger-JAGERCOMP"} ## if we are on a release tag, let's extract the version number ## the other possible value, currently, is 'master' (or another branch name) if [[ $BRANCH == v* ]]; then - COMPONENT_VERSION=$(echo ${BRANCH} | grep -Po "([\d\.]+)") - MAJOR_MINOR=$(echo ${COMPONENT_VERSION} | awk -F. '{print $1"."$2}') - MAJOR1=$(echo ${COMPONENT_VERSION} | awk -F. '{print $1}') + MAJOR_MINOR_PATCH=$(echo ${BRANCH} | grep -Po "([\d\.]+)") + MAJOR_MINOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1"."$2}') + MAJOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1}') else - COMPONENT_VERSION="latest" + MAJOR_MINOR_PATCH="latest" MAJOR_MINOR="" - MAJOR1="" + MAJOR="" fi -# for docker.io -BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${COMPONENT_VERSION}"} -IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE}" +# for docker.io and quay.io +BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"} +IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" SNAPSHOT_TAG="${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}" if [ "${MAJOR_MINOR}x" != "x" ]; then MAJOR_MINOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR_MINOR}" - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE} --tag quay.io/${MAJOR_MINOR_IMAGE}" fi -if [ "${MAJOR1}x" != "x" ]; then - MAJOR1_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR1}" - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR1_IMAGE}" +if [ "${MAJOR}x" != "x" ]; then + MAJOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_IMAGE} --tag quay.io/${MAJOR_IMAGE}" fi -IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG}" +IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG} --tag quay.io/${SNAPSHOT_TAG}" -## for quay.io -IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" - -if [ "${MAJOR_MINOR}x" != "x" ]; then - IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR_MINOR_IMAGE}" -fi - -if [ "${MAJOR1}x" != "x" ]; then - IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${MAJOR1_IMAGE}" -fi - -IMAGE_TAGS="${IMAGE_TAGS} --tag quay.io/${SNAPSHOT_TAG}" ################################# # Only push multi-arch images to dockerhub/quay.io for master branch or for release tags vM.N.P From d97303158721fed34aa822772e1ab5cafa27ee73 Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Mon, 26 Apr 2021 14:11:30 -0400 Subject: [PATCH 03/12] Optimize the code changes 1. Extracted duplicate codes from build-all-in-one-image.sh and build-upload-docker-images.sh and put them in new scripts. 2. Moved the multi-arch images building and uploading codes from Makefile to scripts. 3. Removed some unused Makefile targets and extra whitespaces. Signed-off-by: Kun-Lu --- .github/workflows/ci-all-in-one-build.yml | 2 +- Makefile | 93 ----------------- plugin/storage/es/Dockerfile.rollover | 2 +- scripts/build-all-in-one-image.sh | 81 +++------------ scripts/build-multiarch-baseimg.sh | 16 +++ scripts/build-upload-docker-images.sh | 104 +++++++++++--------- scripts/compute-tag-for-multiarch-image.sh | 39 ++++++++ scripts/docker-login-for-multiarch-image.sh | 14 +++ 8 files changed, 140 insertions(+), 211 deletions(-) create mode 100644 scripts/build-multiarch-baseimg.sh create mode 100644 scripts/compute-tag-for-multiarch-image.sh create mode 100644 scripts/docker-login-for-multiarch-image.sh diff --git a/.github/workflows/ci-all-in-one-build.yml b/.github/workflows/ci-all-in-one-build.yml index 46fb6198d4f..8cf5e76a6c7 100644 --- a/.github/workflows/ci-all-in-one-build.yml +++ b/.github/workflows/ci-all-in-one-build.yml @@ -6,7 +6,7 @@ on: pull_request: branches: [ master ] -jobs: +jobs: all-in-one: runs-on: ubuntu-latest services: diff --git a/Makefile b/Makefile index 19d5ee1f372..93bb55ec70e 100644 --- a/Makefile +++ b/Makefile @@ -72,17 +72,6 @@ MOCKERY=mockery .DEFAULT_GOAL := test-and-lint -BASE_IMAGE_MULTIARCH := localhost:5000/baseimg:$(VERSION)-$(shell echo $(ROOT_IMAGE) | tr : -) -PLATFORMS=linux/amd64,linux/s390x -INGESTER_TAG=$(subst JAGERCOMP,ingester,$(IMAGE_TAGS)) -AGENT_TAG=$(subst JAGERCOMP,agent,$(IMAGE_TAGS)) -COLLECTOR_TAG=$(subst JAGERCOMP,collector,$(IMAGE_TAGS)) -QUERY_TAG=$(subst JAGERCOMP,query,$(IMAGE_TAGS)) -ESINDEX_TAG=$(subst JAGERCOMP,es-index-cleaner,$(IMAGE_TAGS)) -ESROLLOVER_TAG=$(subst JAGERCOMP,es-rollover,$(IMAGE_TAGS)) -TRACEGEN_TAG=$(subst JAGERCOMP,tracegen,$(IMAGE_TAGS)) -ANONYMIZER_TAG=$(subst JAGERCOMP,anonymizer,$(IMAGE_TAGS)) - .PHONY: test-and-lint test-and-lint: test fmt lint @@ -270,9 +259,6 @@ build-collector build-collector-debug: build-ingester build-ingester-debug: $(GOBUILD) $(DISABLE_OPTIMIZATIONS) -o ./cmd/ingester/ingester$(SUFFIX)-$(GOOS)-$(GOARCH) $(BUILD_INFO) ./cmd/ingester/main.go -.PHONY: docker -docker: build-binaries-linux docker-images-only - .PHONY: build-binaries-linux build-binaries-linux: GOOS=linux GOARCH=amd64 $(MAKE) build-platform-binaries @@ -361,85 +347,6 @@ docker-images-only: docker-images-cassandra \ docker-images-tracegen \ docker-images-anonymizer -.PHONY: multiarch-docker -multiarch-docker: build-binaries-linux \ - build-binaries-s390x \ - multiarch-docker-images-only - -.PHONY: multiarch-docker-images-only -multiarch-docker-images-only: docker-images-jaeger-backend-multiarch \ - docker-images-elastic-multiarch \ - docker-images-tracegen-multiarch \ - docker-images-anonymizer-multiarch - -.PHONY: create-baseimage-multiarch -create-baseimage-multiarch: - docker buildx build -t $(BASE_IMAGE_MULTIARCH) --push \ - --build-arg root_image=$(ROOT_IMAGE) \ - --build-arg cert_image=$(CERT_IMAGE) \ - --platform=$(PLATFORMS) \ - docker/base - echo "Finished building multiarch base image ==============" - -.PHONY: docker-images-jaeger-backend-multiarch -docker-images-jaeger-backend-multiarch: create-baseimage-multiarch - for component in agent collector query ingester ; do \ - docker buildx build --output "$(PUSHTAG)" \ - --progress=plain --target release \ - --build-arg base_image=$(BASE_IMAGE_MULTIARCH) \ - --build-arg debug_image=$(GOLANG_IMAGE) \ - --platform=$(PLATFORMS) \ - --file cmd/$$component/Dockerfile \ - $(subst JAGERCOMP,$$component,$(IMAGE_TAGS)) \ - cmd/$$component; \ - echo "Finished building $$component ==============" ; \ - done - -.PHONY: docker-images-elastic-multiarch -docker-images-elastic-multiarch: - docker buildx build --output "$(PUSHTAG)" \ - --progress=plain \ - --platform=$(PLATFORMS) \ - ${ESINDEX_TAG} \ - plugin/storage/es - docker buildx build --output "$(PUSHTAG)" \ - --progress=plain \ - --platform=$(PLATFORMS) \ - --file plugin/storage/es/Dockerfile.rollover \ - ${ESROLLOVER_TAG} \ - plugin/storage/es - @echo "Finished building multiarch jaeger-es-indices-clean ==============" - -.PHONY: docker-images-tracegen-multiarch -docker-images-tracegen-multiarch: - docker buildx build --output "$(PUSHTAG)" \ - --progress=plain \ - --platform=$(PLATFORMS) \ - ${TRACEGEN_TAG} \ - cmd/tracegen/ - @echo "Finished building multiarch jaeger-tracegen ==============" - -.PHONY: docker-images-anonymizer-multiarch -docker-images-anonymizer-multiarch: - docker buildx build --output "$(PUSHTAG)" \ - --progress=plain \ - --platform=$(PLATFORMS) \ - $(ANONYMIZER_TAG) \ - cmd/anonymizer/ - @echo "Finished building multiarch jaeger-anonymizer ==============" - -.PHONY: docker-push -docker-push: - @while [ -z "$$CONFIRM" ]; do \ - read -r -p "Do you really want to push images to repository \"${DOCKER_NAMESPACE}\"? [y/N] " CONFIRM; \ - done ; \ - if [ $$CONFIRM != "y" ] && [ $$CONFIRM != "Y" ]; then \ - echo "Exiting." ; exit 1 ; \ - fi - for component in agent cassandra-schema es-index-cleaner es-rollover collector query ingester example-hotrod tracegen anonymizer; do \ - docker push $(DOCKER_NAMESPACE)/jaeger-$$component ; \ - done - .PHONY: build-crossdock-linux build-crossdock-linux: GOOS=linux $(GOBUILD) -o ./crossdock/crossdock-linux ./crossdock/main.go diff --git a/plugin/storage/es/Dockerfile.rollover b/plugin/storage/es/Dockerfile.rollover index 4e4f4052eeb..223e39814d5 100644 --- a/plugin/storage/es/Dockerfile.rollover +++ b/plugin/storage/es/Dockerfile.rollover @@ -9,4 +9,4 @@ COPY ./mappings/* /mappings/ COPY esRollover.py /es-rollover/ COPY esmapping-generator-linux-$TARGETARCH /usr/bin/esmapping-generator -ENTRYPOINT ["python3", "/es-rollover/esRollover.py"] \ No newline at end of file +ENTRYPOINT ["python3", "/es-rollover/esRollover.py"] diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 9e85d1512ac..487fb5b17b5 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -45,86 +45,33 @@ upload_to_docker() { fi } -upload_multiarch_to_docker() { +build_upload_multiarch_to_docker(){ # 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" - REPO=$1 - build_upload_multiarch_to_docker $REPO + bash scripts/docker-login-for-multiarch-image.sh + IMAGE_TAGS=$(bash scripts/compute-tag-for-multiarch-image.sh $1) + docker buildx build --output "type=image, push=true" \ + --progress=plain --target release \ + --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ + --build-arg debug_image="golang:1.15-alpine" \ + --platform=$PLATFORMS \ + --file cmd/all-in-one/Dockerfile \ + ${IMAGE_TAGS} \ + cmd/all-in-one else echo 'skip docker images upload for PR' fi } -build_upload_multiarch_to_docker(){ - DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-"jaegertracingbot"} - DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-} - QUAY_USERNAME=${QUAY_USERNAME:-"jaegertracing+github_workflows"} - QUAY_TOKEN=${QUAY_TOKEN:-} - - ###############Compute the tag - BASE_BUILD_IMAGE=$1 - - ## if we are on a release tag, let's extract the version number - ## the other possible value, currently, is 'master' (or another branch name) - if [[ $BRANCH == v* ]]; then - MAJOR_MINOR_PATCH=$(echo ${BRANCH} | grep -Po "([\d\.]+)") - MAJOR_MINOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1"."$2}') - MAJOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1}') - - else - MAJOR_MINOR_PATCH="latest" - MAJOR_MINOR="" - MAJOR="" - fi - - # for docker.io and quay.io - BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"} - IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" - SNAPSHOT_TAG="${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}" - - if [ "${MAJOR_MINOR}x" != "x" ]; then - MAJOR_MINOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR_MINOR}" - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE} --tag quay.io/${MAJOR_MINOR_IMAGE}" - fi - - if [ "${MAJOR}x" != "x" ]; then - MAJOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR}" - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_IMAGE} --tag quay.io/${MAJOR_IMAGE}" - fi - - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG} --tag quay.io/${SNAPSHOT_TAG}" - - ################################ - - # Only push images to dockerhub/quay.io for master branch or for release tags vM.N.P - echo "build multiarch images and upload to dockerhub/quay.io, BRANCH=$BRANCH" - - echo "Performing a 'docker login' for DockerHub" - echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" docker.io --password-stdin - - echo "Performing a 'docker login' for Quay" - echo "${QUAY_TOKEN}" | docker login -u "${QUAY_USERNAME}" quay.io --password-stdin - - docker buildx build --output "type=image, push=true" \ - --progress=plain --target release \ - --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ - --build-arg debug_image="golang:1.15-alpine" \ - --platform=$PLATFORMS \ - --file cmd/all-in-one/Dockerfile \ - ${IMAGE_TAGS} \ - cmd/all-in-one -} - make build-all-in-one GOOS=linux GOARCH=amd64 make build-all-in-one GOOS=linux GOARCH=s390x -make create-baseimage-multiarch +PLATFORMS="linux/amd64,linux/s390x" +bash scripts/build-multiarch-baseimg.sh make create-baseimg-debugimg repo=jaegertracing/all-in-one -PLATFORMS="linux/amd64,linux/s390x" - docker buildx build --push \ --progress=plain --target release \ --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ @@ -134,7 +81,7 @@ docker buildx build --push \ --tag localhost:5000/$repo:latest \ cmd/all-in-one run_integration_test localhost:5000/$repo -upload_multiarch_to_docker $repo +build_upload_multiarch_to_docker $repo make build-all-in-one-debug GOOS=linux GOARCH=$GOARCH repo=jaegertracing/all-in-one-debug diff --git a/scripts/build-multiarch-baseimg.sh b/scripts/build-multiarch-baseimg.sh new file mode 100644 index 00000000000..2721e933c0d --- /dev/null +++ b/scripts/build-multiarch-baseimg.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -exu + +VERSION=1.0.0 +ROOT_IMAGE=alpine:3.12 +CERT_IMAGE=alpine:3.12 +BASE_IMAGE_MULTIARCH=localhost:5000/baseimg:${VERSION}-$(echo ${ROOT_IMAGE} | sed "s/:/-/") +PLATFORMS="linux/amd64,linux/s390x" + +docker buildx build -t ${BASE_IMAGE_MULTIARCH} --push \ + --build-arg root_image=${ROOT_IMAGE} \ + --build-arg cert_image=${CERT_IMAGE} \ + --platform=${PLATFORMS} \ + docker/base +echo "Finished building multiarch base image ==============" diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index 6fc20f1ed45..7d6f4ca398f 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -2,63 +2,69 @@ set -euxf -o pipefail -DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-"jaegertracingbot"} -DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-} -QUAY_USERNAME=${QUAY_USERNAME:-"jaegertracing+github_workflows"} -QUAY_TOKEN=${QUAY_TOKEN:-} - -###############Compute the tag -BASE_BUILD_IMAGE=${BASE_BUILD_IMAGE:-"jaegertracing/jaeger-JAGERCOMP"} - -## if we are on a release tag, let's extract the version number -## the other possible value, currently, is 'master' (or another branch name) -if [[ $BRANCH == v* ]]; then - MAJOR_MINOR_PATCH=$(echo ${BRANCH} | grep -Po "([\d\.]+)") - MAJOR_MINOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1"."$2}') - MAJOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1}') - -else - MAJOR_MINOR_PATCH="latest" - MAJOR_MINOR="" - MAJOR="" -fi - -# for docker.io and quay.io -BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"} -IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" -SNAPSHOT_TAG="${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}" - -if [ "${MAJOR_MINOR}x" != "x" ]; then - MAJOR_MINOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR_MINOR}" - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE} --tag quay.io/${MAJOR_MINOR_IMAGE}" -fi - -if [ "${MAJOR}x" != "x" ]; then - MAJOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR}" - IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_IMAGE} --tag quay.io/${MAJOR_IMAGE}" -fi - -IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG} --tag quay.io/${SNAPSHOT_TAG}" - -################################# +build_upload_multiarch_images(){ + for component in agent collector query ingester + do + docker buildx build --output "${PUSHTAG}" \ + --progress=plain --target release \ + --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ + --build-arg debug_image="golang:1.15-alpine" \ + --platform=${PLATFORMS} \ + --file cmd/${component}/Dockerfile \ + $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/${component}/g") \ + cmd/${component} + echo "Finished building ${component} ==============" + done + + docker buildx build --output "${PUSHTAG}" \ + --progress=plain \ + --platform=${PLATFORMS} \ + $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/es-index-cleaner/g") \ + plugin/storage/es + docker buildx build --output "${PUSHTAG}" \ + --progress=plain \ + --platform=${PLATFORMS} \ + --file plugin/storage/es/Dockerfile.rollover \ + $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/es-rollover/g") \ + plugin/storage/es + echo "Finished building multiarch jaeger-es-indices-clean ==============" + + docker buildx build --output "${PUSHTAG}" \ + --progress=plain \ + --platform=${PLATFORMS} \ + $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/tracegen/g") \ + cmd/tracegen/ + echo "Finished building multiarch jaeger-tracegen ==============" + + docker buildx build --output "${PUSHTAG}" \ + --progress=plain \ + --platform=${PLATFORMS} \ + $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/anonymizer/g") \ + cmd/anonymizer/ + echo "Finished building multiarch jaeger-anonymizer ==============" +} + +#Step 1: build and upload multiarch docker images +make build-binaries-linux +make build-binaries-s390x + +PLATFORMS="linux/amd64,linux/s390x" +bash scripts/build-multiarch-baseimg.sh + +IMAGE_TAGS=$(bash scripts/compute-tag-for-multiarch-image.sh "jaegertracing/jaeger-JAEGERCOMP") # 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 multiarch images and upload to dockerhub/quay.io, BRANCH=$BRANCH" - - echo "Performing a 'docker login' for DockerHub" - echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" docker.io --password-stdin - - echo "Performing a 'docker login' for Quay" - echo "${QUAY_TOKEN}" | docker login -u "${QUAY_USERNAME}" quay.io --password-stdin - - IMAGE_TAGS="${IMAGE_TAGS}" PUSHTAG="type=image, push=true" make multiarch-docker + bash scripts/docker-login-for-multiarch-image.sh + PUSHTAG="type=image, push=true" else echo 'skip multiarch docker images upload, only allowed for tagged releases or master (latest tag)' - IMAGE_TAGS="${IMAGE_TAGS}" PUSHTAG="type=image, push=false" make multiarch-docker + PUSHTAG="type=image, push=false" fi +build_upload_multiarch_images - +#Step 2: build and upload amd64 docker images make docker-images-jaeger-backend-debug make docker-images-cassandra # Only push amd64 specific images to dockerhub/quay.io for master branch or for release tags vM.N.P diff --git a/scripts/compute-tag-for-multiarch-image.sh b/scripts/compute-tag-for-multiarch-image.sh new file mode 100644 index 00000000000..84094d804ef --- /dev/null +++ b/scripts/compute-tag-for-multiarch-image.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -exu + +###############Compute the tag +BASE_BUILD_IMAGE=$1 + +## if we are on a release tag, let's extract the version number +## the other possible value, currently, is 'master' (or another branch name) +if [[ $BRANCH == v* ]]; then + MAJOR_MINOR_PATCH=$(echo ${BRANCH} | grep -Po "([\d\.]+)") + MAJOR_MINOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1"."$2}') + MAJOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1}') +else + MAJOR_MINOR_PATCH="latest" + MAJOR_MINOR="" + MAJOR="" +fi + +# for docker.io and quay.io +BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${MAJOR_MINOR_PATCH}"} +IMAGE_TAGS="--tag docker.io/${BASE_BUILD_IMAGE} --tag docker.io/${BUILD_IMAGE} --tag quay.io/${BASE_BUILD_IMAGE} --tag quay.io/${BUILD_IMAGE}" +SNAPSHOT_TAG="${BASE_BUILD_IMAGE}-snapshot:${GITHUB_SHA}" + +if [ "${MAJOR_MINOR}x" != "x" ]; then + MAJOR_MINOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR_MINOR}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_MINOR_IMAGE} --tag quay.io/${MAJOR_MINOR_IMAGE}" +fi + +if [ "${MAJOR}x" != "x" ]; then + MAJOR_IMAGE="${BASE_BUILD_IMAGE}:${MAJOR}" + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${MAJOR_IMAGE} --tag quay.io/${MAJOR_IMAGE}" +fi + +IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG} --tag quay.io/${SNAPSHOT_TAG}" + +################################ + +echo ${IMAGE_TAGS} diff --git a/scripts/docker-login-for-multiarch-image.sh b/scripts/docker-login-for-multiarch-image.sh new file mode 100644 index 00000000000..22561d1d84b --- /dev/null +++ b/scripts/docker-login-for-multiarch-image.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -exu + +DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-"jaegertracingbot"} +DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-} +QUAY_USERNAME=${QUAY_USERNAME:-"jaegertracing+github_workflows"} +QUAY_TOKEN=${QUAY_TOKEN:-} + +echo "Performing a 'docker login' for DockerHub" +echo "${DOCKERHUB_TOKEN}" | docker login -u "${DOCKERHUB_USERNAME}" docker.io --password-stdin + +echo "Performing a 'docker login' for Quay" +echo "${QUAY_TOKEN}" | docker login -u "${QUAY_USERNAME}" quay.io --password-stdin From 5273aa313281986fc25ea75d9e955180c2451c4e Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Wed, 28 Apr 2021 09:59:43 -0400 Subject: [PATCH 04/12] Optimize the code changes - update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. fix the indentation issues in build-upload-docker-images.sh 2. make other multi-arch images built in one for loop 3. use strict regex to match branch names 4. remove “for-multiarch-image” from script names Signed-off-by: Kun-Lu --- scripts/build-all-in-one-image.sh | 4 +- scripts/build-upload-docker-images.sh | 66 +++++++++---------- ...for-multiarch-image.sh => compute-tags.sh} | 2 +- ...for-multiarch-image.sh => docker-login.sh} | 0 4 files changed, 33 insertions(+), 39 deletions(-) rename scripts/{compute-tag-for-multiarch-image.sh => compute-tags.sh} (96%) rename scripts/{docker-login-for-multiarch-image.sh => docker-login.sh} (100%) diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 487fb5b17b5..89a1a07623a 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -49,8 +49,8 @@ build_upload_multiarch_to_docker(){ # 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-for-multiarch-image.sh - IMAGE_TAGS=$(bash scripts/compute-tag-for-multiarch-image.sh $1) + bash scripts/docker-login.sh + IMAGE_TAGS=$(bash scripts/compute-tags.sh $1) docker buildx build --output "type=image, push=true" \ --progress=plain --target release \ --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index 7d6f4ca398f..2d2653748b0 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -3,45 +3,39 @@ set -euxf -o pipefail build_upload_multiarch_images(){ - for component in agent collector query ingester - do + for component in agent collector query ingester + do docker buildx build --output "${PUSHTAG}" \ - --progress=plain --target release \ - --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ + --progress=plain --target release \ + --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ --build-arg debug_image="golang:1.15-alpine" \ - --platform=${PLATFORMS} \ - --file cmd/${component}/Dockerfile \ - $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/${component}/g") \ + --platform=${PLATFORMS} \ + --file cmd/${component}/Dockerfile \ + $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/${component}/g") \ cmd/${component} - echo "Finished building ${component} ==============" + echo "Finished building multiarch jager-${component} ==============" done - docker buildx build --output "${PUSHTAG}" \ - --progress=plain \ - --platform=${PLATFORMS} \ - $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/es-index-cleaner/g") \ - plugin/storage/es - docker buildx build --output "${PUSHTAG}" \ - --progress=plain \ - --platform=${PLATFORMS} \ - --file plugin/storage/es/Dockerfile.rollover \ - $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/es-rollover/g") \ - plugin/storage/es - echo "Finished building multiarch jaeger-es-indices-clean ==============" - - docker buildx build --output "${PUSHTAG}" \ - --progress=plain \ - --platform=${PLATFORMS} \ - $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/tracegen/g") \ - cmd/tracegen/ - echo "Finished building multiarch jaeger-tracegen ==============" - - docker buildx build --output "${PUSHTAG}" \ - --progress=plain \ - --platform=${PLATFORMS} \ - $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/anonymizer/g") \ - cmd/anonymizer/ - echo "Finished building multiarch jaeger-anonymizer ==============" + for component in es-index-cleaner es-rollover tracegen anonymizer + do + if [[ "${component}" == "es-rollover" ]]; then + docker_file_arg="--file plugin/storage/es/Dockerfile.rollover" + else + docker_file_arg="" + fi + if [[ "${component}" =~ ^es-.* ]]; then + dir_arg="plugin/storage/es" + else + dir_arg="cmd/${component}" + fi + docker buildx build --output "${PUSHTAG}" \ + --progress=plain \ + --platform=${PLATFORMS} \ + $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/${component}/g") \ + ${dir_arg} \ + ${docker_file_arg} + echo "Finished building multiarch jaeger-${component} ==============" + done } #Step 1: build and upload multiarch docker images @@ -51,12 +45,12 @@ make build-binaries-s390x PLATFORMS="linux/amd64,linux/s390x" bash scripts/build-multiarch-baseimg.sh -IMAGE_TAGS=$(bash scripts/compute-tag-for-multiarch-image.sh "jaegertracing/jaeger-JAEGERCOMP") +IMAGE_TAGS=$(bash scripts/compute-tags.sh "jaegertracing/jaeger-JAEGERCOMP") # 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 multiarch images and upload to dockerhub/quay.io, BRANCH=$BRANCH" - bash scripts/docker-login-for-multiarch-image.sh + bash scripts/docker-login.sh PUSHTAG="type=image, push=true" else echo 'skip multiarch docker images upload, only allowed for tagged releases or master (latest tag)' diff --git a/scripts/compute-tag-for-multiarch-image.sh b/scripts/compute-tags.sh similarity index 96% rename from scripts/compute-tag-for-multiarch-image.sh rename to scripts/compute-tags.sh index 84094d804ef..5aae0f74e68 100644 --- a/scripts/compute-tag-for-multiarch-image.sh +++ b/scripts/compute-tags.sh @@ -7,7 +7,7 @@ BASE_BUILD_IMAGE=$1 ## if we are on a release tag, let's extract the version number ## the other possible value, currently, is 'master' (or another branch name) -if [[ $BRANCH == v* ]]; then +if [[ $BRANCH =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then MAJOR_MINOR_PATCH=$(echo ${BRANCH} | grep -Po "([\d\.]+)") MAJOR_MINOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1"."$2}') MAJOR=$(echo ${MAJOR_MINOR_PATCH} | awk -F. '{print $1}') diff --git a/scripts/docker-login-for-multiarch-image.sh b/scripts/docker-login.sh similarity index 100% rename from scripts/docker-login-for-multiarch-image.sh rename to scripts/docker-login.sh From 79748926f574b7caa1de58cdad4ca1e09ed949ac Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Tue, 4 May 2021 16:48:23 -0400 Subject: [PATCH 05/12] Optimize the code changes - update 1. Add a function docker_buildx_build() in scripts/ build-upload-docker-images.sh 2. Use tab for indentation in build-upload-docker-images.sh 3. Remove extra '#' from compute-tags.sh Signed-off-by: Kun-Lu --- scripts/build-all-in-one-image.sh | 10 ++-- scripts/build-upload-docker-images.sh | 83 +++++++++++++++------------ scripts/compute-tags.sh | 4 +- 3 files changed, 52 insertions(+), 45 deletions(-) diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 89a1a07623a..593d9819aec 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -86,10 +86,10 @@ build_upload_multiarch_to_docker $repo 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=localhost/baseimg:1.0.0-alpine-3.12 \ - --build-arg debug_image=localhost/debugimg:1.0.0-golang-1.15-alpine \ - --build-arg TARGETARCH=$GOARCH + --target debug \ + --tag $repo:latest cmd/all-in-one \ + --build-arg base_image=localhost/baseimg:1.0.0-alpine-3.12 \ + --build-arg debug_image=localhost/debugimg:1.0.0-golang-1.15-alpine \ + --build-arg TARGETARCH=$GOARCH run_integration_test $repo upload_to_docker $repo diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index 2d2653748b0..b78c0bca3e5 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -2,39 +2,48 @@ set -euxf -o pipefail +docker_buildx_build(){ + local component_name=$1 + local dir_arg=$2 + local docker_file_arg=$3 + + 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.12 --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(){ + # build/upload images for Jaeger backend components for component in agent collector query ingester do - docker buildx build --output "${PUSHTAG}" \ - --progress=plain --target release \ - --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ - --build-arg debug_image="golang:1.15-alpine" \ - --platform=${PLATFORMS} \ - --file cmd/${component}/Dockerfile \ - $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/${component}/g") \ - cmd/${component} - echo "Finished building multiarch jager-${component} ==============" + docker_buildx_build "${component}" "cmd/${component}" "--file cmd/${component}/Dockerfile" "release" "Y" done - for component in es-index-cleaner es-rollover tracegen anonymizer + # 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 jaeger-tracegen and jaeger-anonymizer + for component in tracegen anonymizer do - if [[ "${component}" == "es-rollover" ]]; then - docker_file_arg="--file plugin/storage/es/Dockerfile.rollover" - else - docker_file_arg="" - fi - if [[ "${component}" =~ ^es-.* ]]; then - dir_arg="plugin/storage/es" - else - dir_arg="cmd/${component}" - fi - docker buildx build --output "${PUSHTAG}" \ - --progress=plain \ - --platform=${PLATFORMS} \ - $(echo ${IMAGE_TAGS} | sed "s/JAEGERCOMP/${component}/g") \ - ${dir_arg} \ - ${docker_file_arg} - echo "Finished building multiarch jaeger-${component} ==============" + docker_buildx_build "${component}" "cmd/${component}" "--file cmd/${component}/Dockerfile" "N" "N" done } @@ -49,12 +58,12 @@ IMAGE_TAGS=$(bash scripts/compute-tags.sh "jaegertracing/jaeger-JAEGERCOMP") # 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 multiarch images and upload to dockerhub/quay.io, BRANCH=$BRANCH" - bash scripts/docker-login.sh - PUSHTAG="type=image, push=true" + echo "build multiarch images and upload to dockerhub/quay.io, BRANCH=$BRANCH" + bash scripts/docker-login.sh + PUSHTAG="type=image, push=true" else - echo 'skip multiarch docker images upload, only allowed for tagged releases or master (latest tag)' - PUSHTAG="type=image, push=false" + echo 'skip multiarch docker images upload, only allowed for tagged releases or master (latest tag)' + PUSHTAG="type=image, push=false" fi build_upload_multiarch_images @@ -63,10 +72,10 @@ make docker-images-jaeger-backend-debug make docker-images-cassandra # Only push amd64 specific 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" + echo "upload to dockerhub/quay.io, BRANCH=$BRANCH" else - echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)' - exit 0 + echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)' + exit 0 fi export DOCKER_NAMESPACE=jaegertracing @@ -81,7 +90,7 @@ jaeger_components=( for component in "${jaeger_components[@]}" do - REPO="jaegertracing/jaeger-${component}" - bash scripts/upload-to-registry.sh $REPO + REPO="jaegertracing/jaeger-${component}" + bash scripts/upload-to-registry.sh $REPO done diff --git a/scripts/compute-tags.sh b/scripts/compute-tags.sh index 5aae0f74e68..6692b52f1d3 100644 --- a/scripts/compute-tags.sh +++ b/scripts/compute-tags.sh @@ -2,7 +2,7 @@ set -exu -###############Compute the tag +# Compute the tag BASE_BUILD_IMAGE=$1 ## if we are on a release tag, let's extract the version number @@ -34,6 +34,4 @@ fi IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${SNAPSHOT_TAG} --tag quay.io/${SNAPSHOT_TAG}" -################################ - echo ${IMAGE_TAGS} From 2613b6c5803927df34a07007c07435ed31bd3d70 Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Mon, 10 May 2021 10:28:42 -0400 Subject: [PATCH 06/12] Optimize the code changes - update 1. Remove duplicate code from upload-to-registry.sh 2. Search for duplicate code in other scripts and adjust them 3. Add multi-arch image support for two more components 4. Move multi-arch base-img creation code to docker/Makefile, keep only one target for creating the base image Signed-off-by: Kun-Lu update --- .github/workflows/ci-crossdock.yml | 11 +++ .github/workflows/ci-hotrod.yml | 11 +++ Makefile | 8 +- crossdock/Dockerfile | 3 +- docker/Makefile | 6 +- examples/hotrod/Dockerfile | 2 +- scripts/build-all-in-one-image.sh | 46 +++++------ scripts/build-crossdock.sh | 18 +++-- scripts/build-multiarch-baseimg.sh | 16 ---- scripts/build-upload-docker-images.sh | 60 +++++++------- scripts/hotrod-integration-test.sh | 24 ++++-- scripts/upload-to-registry.sh | 112 +++----------------------- 12 files changed, 124 insertions(+), 193 deletions(-) delete mode 100644 scripts/build-multiarch-baseimg.sh diff --git a/.github/workflows/ci-crossdock.yml b/.github/workflows/ci-crossdock.yml index d263b3714a8..29c2ed3de72 100644 --- a/.github/workflows/ci-crossdock.yml +++ b/.github/workflows/ci-crossdock.yml @@ -9,6 +9,11 @@ on: jobs: crossdock: runs-on: ubuntu-latest + services: + registry: + image: registry:2 + ports: + - 5000:5000 strategy: matrix: steps: @@ -33,6 +38,12 @@ jobs: - name: Install tools run: make install-ci + + - uses: docker/setup-qemu-action@v1 + + - uses: docker/setup-buildx-action@v1 + with: + driver-opts: network=host - name: Build, test, and publish ${{ matrix.steps.name }} image run: ${{ matrix.steps.cmd }} diff --git a/.github/workflows/ci-hotrod.yml b/.github/workflows/ci-hotrod.yml index 3314cb0d76d..437ad03c854 100644 --- a/.github/workflows/ci-hotrod.yml +++ b/.github/workflows/ci-hotrod.yml @@ -9,6 +9,11 @@ on: jobs: hotrod: runs-on: ubuntu-latest + services: + registry: + image: registry:2 + ports: + - 5000:5000 steps: - uses: actions/checkout@v2 with: @@ -27,6 +32,12 @@ jobs: - name: Install tools run: make install-ci + + - uses: docker/setup-qemu-action@v1 + + - uses: docker/setup-buildx-action@v1 + with: + driver-opts: network=host - name: Build, test, and publish hotrod image run: bash scripts/hotrod-integration-test.sh diff --git a/Makefile b/Makefile index 8b3b1c8bf72..8ff568bb9f6 100644 --- a/Makefile +++ b/Makefile @@ -354,9 +354,13 @@ docker-images-only: docker-images-cassandra \ docker-images-tracegen \ docker-images-anonymizer +.PHONY: build-crossdock-binary +build-crossdock-binary: + $(GOBUILD) -o ./crossdock/crossdock-$(GOOS)-$(GOARCH) ./crossdock/main.go + .PHONY: build-crossdock-linux build-crossdock-linux: - GOOS=linux $(GOBUILD) -o ./crossdock/crossdock-linux ./crossdock/main.go + GOOS=linux $(MAKE) build-crossdock-binary include crossdock/rules.mk @@ -369,7 +373,7 @@ build-crossdock-ui-placeholder: .PHONY: build-crossdock build-crossdock: build-crossdock-ui-placeholder build-binaries-linux build-crossdock-linux docker-images-cassandra docker-images-jaeger-backend - docker build -t $(DOCKER_NAMESPACE)/test-driver:${DOCKER_TAG} crossdock/ + docker build -t $(DOCKER_NAMESPACE)/test-driver:${DOCKER_TAG} --build-arg TARGETARCH=$(GOARCH) crossdock/ @echo "Finished building test-driver ==============" ; \ .PHONY: build-and-run-crossdock diff --git a/crossdock/Dockerfile b/crossdock/Dockerfile index 9a90d2ea73d..2d17d240981 100644 --- a/crossdock/Dockerfile +++ b/crossdock/Dockerfile @@ -1,6 +1,7 @@ FROM scratch +ARG TARGETARCH -COPY crossdock-linux /go/bin/ +COPY crossdock-linux-$TARGETARCH /go/bin/crossdock-linux EXPOSE 8080 ENTRYPOINT ["/go/bin/crossdock-linux"] diff --git a/docker/Makefile b/docker/Makefile index 7ae41af9273..04bb59fe71b 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -3,15 +3,17 @@ ROOT_IMAGE ?= alpine:3.12 CERT_IMAGE := alpine:3.12 GOLANG_IMAGE := golang:1.15-alpine -BASE_IMAGE := localhost/baseimg:$(VERSION)-$(shell echo $(ROOT_IMAGE) | tr : -) +BASE_IMAGE := localhost:5000/baseimg:$(VERSION)-$(shell echo $(ROOT_IMAGE) | tr : -) DEBUG_IMAGE := localhost/debugimg:$(VERSION)-$(shell echo $(GOLANG_IMAGE) | tr : -) +PLATFORMS := linux/amd64,linux/s390x create-baseimg-debugimg: create-baseimg create-debugimg create-baseimg: - docker build -t $(BASE_IMAGE) \ + docker buildx build -t $(BASE_IMAGE) --push \ --build-arg root_image=$(ROOT_IMAGE) \ --build-arg cert_image=$(CERT_IMAGE) \ + --platform=$(PLATFORMS) \ docker/base create-debugimg: diff --git a/examples/hotrod/Dockerfile b/examples/hotrod/Dockerfile index e26a2ec2578..b93de0e6151 100644 --- a/examples/hotrod/Dockerfile +++ b/examples/hotrod/Dockerfile @@ -1,5 +1,5 @@ FROM scratch -ARG TARGETARCH=amd64 +ARG TARGETARCH EXPOSE 8080 8081 8082 8083 COPY hotrod-linux-$TARGETARCH /go/bin/hotrod-linux ENTRYPOINT ["/go/bin/hotrod-linux"] diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 593d9819aec..4e07b4e0554 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -34,31 +34,25 @@ run_integration_test() { docker kill $CID } -upload_to_docker() { - # 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" - REPO=$1 - bash scripts/upload-to-registry.sh $REPO - else - echo 'skip docker images upload for PR' - fi -} - -build_upload_multiarch_to_docker(){ +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 - IMAGE_TAGS=$(bash scripts/compute-tags.sh $1) - docker buildx build --output "type=image, push=true" \ - --progress=plain --target release \ - --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ - --build-arg debug_image="golang:1.15-alpine" \ - --platform=$PLATFORMS \ - --file cmd/all-in-one/Dockerfile \ - ${IMAGE_TAGS} \ - cmd/all-in-one + 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 @@ -68,28 +62,28 @@ make build-all-in-one GOOS=linux GOARCH=amd64 make build-all-in-one GOOS=linux GOARCH=s390x PLATFORMS="linux/amd64,linux/s390x" -bash scripts/build-multiarch-baseimg.sh make create-baseimg-debugimg repo=jaegertracing/all-in-one +BASE_IMAGE="localhost:5000/baseimg:1.0.0-alpine-3.12" docker buildx build --push \ --progress=plain --target release \ - --build-arg base_image="localhost:5000/baseimg:1.0.0-alpine-3.12" \ + --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 run_integration_test localhost:5000/$repo -build_upload_multiarch_to_docker $repo +build_upload_to_docker $repo "Y" 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=localhost/baseimg:1.0.0-alpine-3.12 \ + --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 -upload_to_docker $repo +build_upload_to_docker $repo "N" diff --git a/scripts/build-crossdock.sh b/scripts/build-crossdock.sh index f17f90dddc9..7a6a9707613 100755 --- a/scripts/build-crossdock.sh +++ b/scripts/build-crossdock.sh @@ -10,12 +10,18 @@ make build-and-run-crossdock # Only push images to dockerhub/quay.io for master branch if [[ "$BRANCH" == "master" ]]; then echo 'upload images to dockerhub/quay.io' + make build-crossdock-binary GOOS=linux GOARCH=amd64 + make build-crossdock-binary GOOS=linux GOARCH=s390x + PLATFORMS="linux/amd64,linux/s390x" + REPO=jaegertracing/test-driver + IMAGE_TAGS=$(bash scripts/compute-tags.sh $REPO) + IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${REPO}:${COMMIT} --tag quay.io/${REPO}:${COMMIT}" + bash scripts/docker-login.sh + docker buildx build --push \ + --progress=plain \ + --platform=$PLATFORMS \ + ${IMAGE_TAGS} \ + crossdock/ else echo 'skip docker images upload for PR' - exit 0 fi - -# docker image has been build when running the crossdock -REPO=jaegertracing/test-driver -docker tag $REPO:latest $REPO:$COMMIT -bash scripts/upload-to-registry.sh $REPO diff --git a/scripts/build-multiarch-baseimg.sh b/scripts/build-multiarch-baseimg.sh deleted file mode 100644 index 2721e933c0d..00000000000 --- a/scripts/build-multiarch-baseimg.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -set -exu - -VERSION=1.0.0 -ROOT_IMAGE=alpine:3.12 -CERT_IMAGE=alpine:3.12 -BASE_IMAGE_MULTIARCH=localhost:5000/baseimg:${VERSION}-$(echo ${ROOT_IMAGE} | sed "s/:/-/") -PLATFORMS="linux/amd64,linux/s390x" - -docker buildx build -t ${BASE_IMAGE_MULTIARCH} --push \ - --build-arg root_image=${ROOT_IMAGE} \ - --build-arg cert_image=${CERT_IMAGE} \ - --platform=${PLATFORMS} \ - docker/base -echo "Finished building multiarch base image ==============" diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index b78c0bca3e5..4ddbf1ad850 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -30,6 +30,9 @@ docker_buildx_build(){ } build_upload_multiarch_images(){ + PLATFORMS="linux/amd64,linux/s390x" + IMAGE_TAGS=$(bash scripts/compute-tags.sh "jaegertracing/jaeger-JAEGERCOMP") + # build/upload images for Jaeger backend components for component in agent collector query ingester do @@ -47,50 +50,41 @@ build_upload_multiarch_images(){ done } -#Step 1: build and upload multiarch docker images +upload_docker_images(){ + # upload amd64 docker images + jaeger_components=( + agent-debug + cassandra-schema + collector-debug + query-debug + ingester-debug + ) + + 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 - -PLATFORMS="linux/amd64,linux/s390x" -bash scripts/build-multiarch-baseimg.sh - -IMAGE_TAGS=$(bash scripts/compute-tags.sh "jaegertracing/jaeger-JAEGERCOMP") +# 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 multiarch images and upload to dockerhub/quay.io, BRANCH=$BRANCH" + 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 multiarch docker images upload, only allowed for tagged releases or master (latest tag)' + echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)' PUSHTAG="type=image, push=false" fi build_upload_multiarch_images -#Step 2: build and upload amd64 docker images -make docker-images-jaeger-backend-debug -make docker-images-cassandra -# Only push amd64 specific 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" -else - echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)' - exit 0 -fi -export DOCKER_NAMESPACE=jaegertracing - -jaeger_components=( - agent-debug - cassandra-schema - collector-debug - query-debug - ingester-debug -) - -for component in "${jaeger_components[@]}" -do - REPO="jaegertracing/jaeger-${component}" - bash scripts/upload-to-registry.sh $REPO -done diff --git a/scripts/hotrod-integration-test.sh b/scripts/hotrod-integration-test.sh index 91790ba3010..21b97b0c744 100755 --- a/scripts/hotrod-integration-test.sh +++ b/scripts/hotrod-integration-test.sh @@ -2,9 +2,19 @@ set -euxf -o pipefail -make docker-hotrod +make build-examples GOOS=linux GOARCH=amd64 +make build-examples GOOS=linux GOARCH=s390x + REPO=jaegertracing/example-hotrod -export CID=$(docker run -d -p 8080:8080 $REPO:latest) +PLATFORMS="linux/amd64,linux/s390x" + +docker buildx build --push \ + --progress=plain \ + --platform=$PLATFORMS \ + --tag localhost:5000/$REPO:latest \ + examples/hotrod + +export CID=$(docker run -d -p 8080:8080 localhost:5000/$REPO:latest) i=0 while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8080)" != "200" && ${i} < 30 ]]; do sleep 1 @@ -22,9 +32,13 @@ 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)" - exit 0 fi - -bash scripts/upload-to-registry.sh $REPO diff --git a/scripts/upload-to-registry.sh b/scripts/upload-to-registry.sh index 8156bd9819a..0e7b0ca8d1b 100755 --- a/scripts/upload-to-registry.sh +++ b/scripts/upload-to-registry.sh @@ -2,104 +2,14 @@ set -euxf -o pipefail -DOCKERHUB_USERNAME=${DOCKERHUB_USERNAME:-"jaegertracingbot"} -DOCKERHUB_TOKEN=${DOCKERHUB_TOKEN:-} -QUAY_USERNAME=${QUAY_USERNAME:-"jaegertracing+github_workflows"} -QUAY_TOKEN=${QUAY_TOKEN:-} - -usage() { - echo $"Usage: $0 " - exit 1 -} - -check_args() { - if [ ! $# -eq 1 ]; then - echo "ERROR: need exactly one argument" - usage - fi -} - -compute_image_tag() { - local branch=$1 - - if [[ "${branch}" == "master" ]]; then - local tag="latest" - echo ${tag} - elif [[ "${branch}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then - local major="${BASH_REMATCH[1]}" - local minor="${BASH_REMATCH[2]}" - local patch="${BASH_REMATCH[3]}" - local tag=${major}.${minor}.${patch} - echo "${tag} ${major} ${minor} ${patch}" - else - local tag="${branch}" - echo ${tag} - fi -} - -label_release_tag() { - local registry=$1 - local image=$2 - local major=${3:-} - local minor=${4:-} - local patch=${5:-} - - docker tag ${image} ${registry}/${image} - if [[ -n ${major} ]]; then - docker tag ${image} ${registry}/${image}:${major} - if [[ -n ${minor} ]]; then - docker tag ${image} ${registry}/${image}:${major}.${minor} - if [[ -n ${patch} ]]; then - docker tag ${image} ${registry}/${image}:${major}.${minor}.${patch} - fi - fi - fi -} - -try_login() { - local registry=$1 - local user=$2 - local token=$3 - local marker=$4 - - if [ ! -f ${marker} ] && [ -v ${token} ]; then - printenv ${token} | docker login ${registry} --username ${user} --password-stdin - touch ${marker} - fi -} - -upload_images() { - local registry=$1 - local image=$2 - local user=$3 - local token=$4 - local marker=.${registry}.login - - try_login ${registry} ${user} ${token} ${marker} - - if [ ! -f ${marker} ]; then - echo "skipping upload to ${registry}, not logged in!" - else - docker push --all-tags ${registry}/${image} - local snapshot_image="${image}-snapshot:${GITHUB_SHA}" - echo "pushing snapshot image ${snapshot_image}" - docker tag ${image} ${registry}/${snapshot_image} - docker push ${registry}/${snapshot_image} - fi -} - -main() { - local registry=$1 - local image=$2 - local user=$3 - local token=$4 - - read -r tag major minor patch <<< "$(compute_image_tag ${BRANCH})" - label_release_tag ${registry} ${image} ${major} ${minor} ${patch} - upload_images ${registry} ${image} ${user} ${token} -} - -check_args "$@" - -main "docker.io" $1 ${DOCKERHUB_USERNAME} DOCKERHUB_TOKEN -main "quay.io" $1 ${QUAY_USERNAME} QUAY_TOKEN +IMAGE_TAGS=$(bash scripts/compute-tags.sh $1) +IMAGE_TAGS=$(echo ${IMAGE_TAGS} | sed "s/--tag //g") +for image_tag in $IMAGE_TAGS +do + docker tag $1 $image_tag +done + +docker push --all-tags docker.io/$1 +docker push --all-tags docker.io/$1-snapshot +docker push --all-tags quay.io/$1 +docker push --all-tags quay.io/$1-snapshot From 23ede7286ed163cb22311e0a0d94152f5312f050 Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Fri, 28 May 2021 14:36:31 -0400 Subject: [PATCH 07/12] upgrade the base image version Signed-off-by: Kun-Lu --- scripts/build-all-in-one-image.sh | 2 +- scripts/build-upload-docker-images.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 4e07b4e0554..b10a073d05f 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -64,7 +64,7 @@ make build-all-in-one GOOS=linux GOARCH=s390x PLATFORMS="linux/amd64,linux/s390x" make create-baseimg-debugimg repo=jaegertracing/all-in-one -BASE_IMAGE="localhost:5000/baseimg:1.0.0-alpine-3.12" +BASE_IMAGE="localhost:5000/baseimg:1.0.0-alpine-3.13" docker buildx build --push \ --progress=plain --target release \ diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index 4ddbf1ad850..4d656d997c1 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -16,7 +16,7 @@ docker_buildx_build(){ 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.12 --build-arg debug_image=golang:1.15-alpine " + 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}" \ From 027376a291d3b8d296f921229c8cef8fbe8ca820 Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Fri, 11 Jun 2021 15:47:56 -0400 Subject: [PATCH 08/12] Create a common shared script for docker images 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 --- docker/Makefile | 5 +- scripts/build-all-in-one-image.sh | 61 ++++----------- scripts/build-upload-a-docker-image.sh | 70 +++++++++++++++++ scripts/build-upload-docker-images.sh | 104 +++++++------------------ scripts/hotrod-integration-test.sh | 23 +----- scripts/upload-to-registry.sh | 15 ---- 6 files changed, 120 insertions(+), 158 deletions(-) create mode 100644 scripts/build-upload-a-docker-image.sh delete mode 100755 scripts/upload-to-registry.sh diff --git a/docker/Makefile b/docker/Makefile index 04609d2832d..5a94ecff8bf 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -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 @@ -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 diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index b10a073d05f..5f2b37bc482 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -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 diff --git a/scripts/build-upload-a-docker-image.sh b/scripts/build-upload-a-docker-image.sh new file mode 100644 index 00000000000..042c08b5e7d --- /dev/null +++ b/scripts/build-upload-a-docker-image.sh @@ -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} ==============" diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index 4d656d997c1..acb7e3b6558 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -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}" diff --git a/scripts/hotrod-integration-test.sh b/scripts/hotrod-integration-test.sh index 21b97b0c744..851919d6f89 100755 --- a/scripts/hotrod-integration-test.sh +++ b/scripts/hotrod-integration-test.sh @@ -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 @@ -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}" diff --git a/scripts/upload-to-registry.sh b/scripts/upload-to-registry.sh deleted file mode 100755 index 0e7b0ca8d1b..00000000000 --- a/scripts/upload-to-registry.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -euxf -o pipefail - -IMAGE_TAGS=$(bash scripts/compute-tags.sh $1) -IMAGE_TAGS=$(echo ${IMAGE_TAGS} | sed "s/--tag //g") -for image_tag in $IMAGE_TAGS -do - docker tag $1 $image_tag -done - -docker push --all-tags docker.io/$1 -docker push --all-tags docker.io/$1-snapshot -docker push --all-tags quay.io/$1 -docker push --all-tags quay.io/$1-snapshot From 5a6b26812054f52488209a9df4a85e057f50999a Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Mon, 14 Jun 2021 14:18:05 -0400 Subject: [PATCH 09/12] Refactor update Change the names of base image and debug image to stable local names and update build-crossdock.sh Signed-off-by: Kun-Lu --- docker/Makefile | 6 +++--- scripts/build-all-in-one-image.sh | 4 ++-- scripts/build-crossdock.sh | 5 +---- scripts/build-upload-docker-images.sh | 4 ++-- scripts/compute-tags.sh | 4 +++- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/docker/Makefile b/docker/Makefile index 5a94ecff8bf..0f810f881f4 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,10 +1,10 @@ VERSION := 1.0.0 ROOT_IMAGE ?= alpine:3.13 -CERT_IMAGE := alpine:3.13 +CERT_IMAGE := $(ROOT_IMAGE) GOLANG_IMAGE := golang:1.15-alpine -BASE_IMAGE := localhost:5000/baseimg:$(VERSION)-$(shell echo $(ROOT_IMAGE) | tr : -) -DEBUG_IMAGE := localhost:5000/debugimg:$(VERSION)-$(shell echo $(GOLANG_IMAGE) | tr : -) +BASE_IMAGE := localhost:5000/baseimg_alpine:latest +DEBUG_IMAGE := localhost:5000/debugimg_alpine:latest PLATFORMS := linux/amd64,linux/s390x create-baseimg-debugimg: create-baseimg create-debugimg diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 5f2b37bc482..b03cd0f65fd 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -40,7 +40,7 @@ make build-all-in-one GOOS=linux GOARCH=amd64 make build-all-in-one GOOS=linux GOARCH=s390x platforms="linux/amd64,linux/s390x" repo=jaegertracing/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 " +base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --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 @@ -50,7 +50,7 @@ bash scripts/build-upload-a-docker-image.sh -c all-in-one -b "${base_debug_img_a make build-all-in-one-debug GOOS=linux GOARCH=$GOARCH 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 " +base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --build-arg debug_image=localhost:5000/debugimg_alpine:latest " #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 diff --git a/scripts/build-crossdock.sh b/scripts/build-crossdock.sh index 7a6a9707613..ae627172586 100755 --- a/scripts/build-crossdock.sh +++ b/scripts/build-crossdock.sh @@ -10,16 +10,13 @@ make build-and-run-crossdock # Only push images to dockerhub/quay.io for master branch if [[ "$BRANCH" == "master" ]]; then echo 'upload images to dockerhub/quay.io' - make build-crossdock-binary GOOS=linux GOARCH=amd64 - make build-crossdock-binary GOOS=linux GOARCH=s390x - PLATFORMS="linux/amd64,linux/s390x" REPO=jaegertracing/test-driver IMAGE_TAGS=$(bash scripts/compute-tags.sh $REPO) IMAGE_TAGS="${IMAGE_TAGS} --tag docker.io/${REPO}:${COMMIT} --tag quay.io/${REPO}:${COMMIT}" bash scripts/docker-login.sh docker buildx build --push \ --progress=plain \ - --platform=$PLATFORMS \ + --platform=linux/amd64 \ ${IMAGE_TAGS} \ crossdock/ else diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index acb7e3b6558..ff712548571 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -9,7 +9,7 @@ make build-binaries-linux make build-binaries-s390x 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 " +base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --build-arg debug_image=golang:1.15-alpine " # build/upload images for release version of Jaeger backend components for component in agent collector query ingester @@ -30,7 +30,7 @@ done # build amd64 docker 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 " +base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --build-arg debug_image=localhost:5000/debugimg_alpine:latest " # build/upload images for debug version of Jaeger backend components for component in agent collector query ingester diff --git a/scripts/compute-tags.sh b/scripts/compute-tags.sh index 6692b52f1d3..342e3c70b3f 100644 --- a/scripts/compute-tags.sh +++ b/scripts/compute-tags.sh @@ -1,9 +1,11 @@ #!/bin/bash +# Compute major/minor/etc image tags based on the current branch + set -exu -# Compute the tag BASE_BUILD_IMAGE=$1 +BRANCH=${BRANCH:?'expecting BRANCH env var'} ## if we are on a release tag, let's extract the version number ## the other possible value, currently, is 'master' (or another branch name) From ba3e9bc120178112cff88e96cc08ff4eef3e99e3 Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Tue, 15 Jun 2021 15:59:37 -0400 Subject: [PATCH 10/12] Remove cross-script dependencies of debugimg name 1. Update docker/debug/Dockerfile to use `if statement` to support s390x 2. Use the stable local name for debugimg across all archs 3. Populate arg `base_debug_img_arg` with the stable local names directly in the shared script `build-upload-a-docker-image.sh` Signed-off-by: Kun-Lu --- docker/Makefile | 2 +- docker/debug/Dockerfile | 13 +++++++++---- scripts/build-all-in-one-image.sh | 10 ++++------ scripts/build-upload-a-docker-image.sh | 6 +++--- scripts/build-upload-docker-images.sh | 10 ++++------ 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/docker/Makefile b/docker/Makefile index 0f810f881f4..fab9116aedd 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -19,5 +19,5 @@ create-baseimg: create-debugimg: docker buildx build -t $(DEBUG_IMAGE) --push \ --build-arg golang_image=$(GOLANG_IMAGE) \ - --platform=linux/amd64 \ + --platform=$(PLATFORMS) \ docker/debug diff --git a/docker/debug/Dockerfile b/docker/debug/Dockerfile index 487d7205590..952a11a00d6 100644 --- a/docker/debug/Dockerfile +++ b/docker/debug/Dockerfile @@ -1,11 +1,16 @@ ARG golang_image FROM $golang_image AS build +ARG TARGETARCH ENV GOPATH /go -RUN apk add --update --no-cache ca-certificates make git && \ - go get github.com/go-delve/delve/cmd/dlv && \ - cd /go/src/github.com/go-delve/delve && \ - make install +RUN apk add --update --no-cache ca-certificates make git +RUN if [[ "$TARGETARCH" != "s390x" ]] ; then \ + go get github.com/go-delve/delve/cmd/dlv && \ + cd /go/src/github.com/go-delve/delve && \ + make install; \ + else \ + touch /go/bin/dlv; \ + fi FROM $golang_image COPY --from=build /go/bin/dlv /go/bin/dlv diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index b03cd0f65fd..ba9a20b526e 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -40,19 +40,17 @@ make build-all-in-one GOOS=linux GOARCH=amd64 make build-all-in-one GOOS=linux GOARCH=s390x platforms="linux/amd64,linux/s390x" repo=jaegertracing/all-in-one -base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --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 +bash scripts/build-upload-a-docker-image.sh -l -b -c all-in-one -d cmd/all-in-one -p "${platforms}" -t release run_integration_test localhost:5000/$repo #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 +bash scripts/build-upload-a-docker-image.sh -b -c all-in-one -d cmd/all-in-one -p "${platforms}" -t release make build-all-in-one-debug GOOS=linux GOARCH=$GOARCH repo=${repo}-debug -base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --build-arg debug_image=localhost:5000/debugimg_alpine:latest " #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 +bash scripts/build-upload-a-docker-image.sh -l -b -c all-in-one-debug -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 +bash scripts/build-upload-a-docker-image.sh -b -c all-in-one-debug -d cmd/all-in-one -t debug diff --git a/scripts/build-upload-a-docker-image.sh b/scripts/build-upload-a-docker-image.sh index 042c08b5e7d..5ca4612442f 100644 --- a/scripts/build-upload-a-docker-image.sh +++ b/scripts/build-upload-a-docker-image.sh @@ -9,13 +9,13 @@ local_test_only='N' platforms="linux/amd64" name_space="jaegertracing" -while getopts "lc:b:d:f:p:t:" opt; do +while getopts "lbc:d:f:p:t:" opt; do case "${opt}" in c) component_name=${OPTARG} ;; b) - base_debug_img_arg=${OPTARG} + base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --build-arg debug_image=localhost:5000/debugimg_alpine:latest " ;; d) dir_arg=${OPTARG} @@ -67,4 +67,4 @@ docker buildx build --output "${PUSHTAG}" \ ${IMAGE_TAGS} \ ${dir_arg} -echo "Finished building${upload_flag} jager-${component_name} ==============" +echo "Finished building${upload_flag} ${component_name} ==============" diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh index ff712548571..c40757184f5 100644 --- a/scripts/build-upload-docker-images.sh +++ b/scripts/build-upload-docker-images.sh @@ -8,13 +8,13 @@ make create-baseimg-debugimg make build-binaries-linux make build-binaries-s390x +# build multi-arch docker images platforms="linux/amd64,linux/s390x" -base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --build-arg debug_image=golang:1.15-alpine " # 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 + bash scripts/build-upload-a-docker-image.sh -b -c "jaeger-${component}" -d "cmd/${component}" -p "${platforms}" -t release done # build/upload images for jaeger-es-index-cleaner and jaeger-es-rollover @@ -29,14 +29,12 @@ done # build amd64 docker images -platforms="linux/amd64" -base_debug_img_arg="--build-arg base_image=localhost:5000/baseimg_alpine:latest --build-arg debug_image=localhost:5000/debugimg_alpine:latest " # 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 + bash scripts/build-upload-a-docker-image.sh -b -c "jaeger-${component}-debug" -d "cmd/${component}" -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}" +bash scripts/build-upload-a-docker-image.sh -c jaeger-cassandra-schema -d plugin/storage/cassandra/ From 18aad23c299c1ea30b8c5f8cfebd2de908739593 Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Thu, 24 Jun 2021 15:50:13 -0400 Subject: [PATCH 11/12] Fix the indentation issue Signed-off-by: Kun-Lu --- scripts/build-upload-a-docker-image.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/build-upload-a-docker-image.sh b/scripts/build-upload-a-docker-image.sh index 5ca4612442f..56df0ab644b 100644 --- a/scripts/build-upload-a-docker-image.sh +++ b/scripts/build-upload-a-docker-image.sh @@ -20,16 +20,16 @@ while getopts "lbc:d:f:p:t:" opt; do d) dir_arg=${OPTARG} ;; - f) + f) docker_file_arg=${OPTARG} ;; - p) + p) platforms=${OPTARG} ;; t) target_arg=${OPTARG} ;; - l) + l) local_test_only='Y' ;; esac @@ -53,7 +53,7 @@ else 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" + upload_flag=" and uploading" else echo 'skip docker images upload, only allowed for tagged releases or master (latest tag)' PUSHTAG="type=image, push=false" From c492340fd7ede167571e9af1856c5f3486615ab8 Mon Sep 17 00:00:00 2001 From: Kun-Lu Date: Fri, 25 Jun 2021 15:11:30 -0400 Subject: [PATCH 12/12] Add comment in debug Dockerfile Signed-off-by: Kun-Lu --- docker/debug/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/debug/Dockerfile b/docker/debug/Dockerfile index 952a11a00d6..ab25713e891 100644 --- a/docker/debug/Dockerfile +++ b/docker/debug/Dockerfile @@ -4,6 +4,7 @@ FROM $golang_image AS build ARG TARGETARCH ENV GOPATH /go RUN apk add --update --no-cache ca-certificates make git +#Once go-delve adds support for s390x (see PR #2948), remove this entire conditional. RUN if [[ "$TARGETARCH" != "s390x" ]] ; then \ go get github.com/go-delve/delve/cmd/dlv && \ cd /go/src/github.com/go-delve/delve && \