diff --git a/.github/workflows/ci-all-in-one-build.yml b/.github/workflows/ci-all-in-one-build.yml index 714582ad2cb..f27a65c7632 100644 --- a/.github/workflows/ci-all-in-one-build.yml +++ b/.github/workflows/ci-all-in-one-build.yml @@ -9,6 +9,11 @@ on: jobs: all-in-one: runs-on: ubuntu-latest + services: + registry: + image: registry:2 + ports: + - 5000:5000 steps: - uses: actions/checkout@v2.3.4 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-crossdock.yml b/.github/workflows/ci-crossdock.yml index 5151c8b29ac..2a2fb402905 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-docker-build.yml b/.github/workflows/ci-docker-build.yml index d3a1b39596d..b5d84b7efbf 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.3.4 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-hotrod.yml b/.github/workflows/ci-hotrod.yml index b3f298dfa91..d2303ebd93a 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.3.4 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/.github/workflows/ci-release.yml b/.github/workflows/ci-release.yml index df9fc88dbb4..07c0418a564 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.3.4 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 956fe51b0a6..0cd40aace4b 100644 --- a/Makefile +++ b/Makefile @@ -269,9 +269,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 @@ -308,7 +305,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 @@ -319,9 +317,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 @@ -358,21 +357,13 @@ docker-images-only: docker-images-cassandra \ docker-images-tracegen \ docker-images-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-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 @@ -385,7 +376,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/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 70699f5cf24..e92c89c7fc5 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 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/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 890f6b37328..fab9116aedd 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,20 +1,23 @@ 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/baseimg:$(VERSION)-$(shell echo $(ROOT_IMAGE) | tr : -) -DEBUG_IMAGE := localhost/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 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: - docker build -t $(DEBUG_IMAGE) \ + docker buildx build -t $(DEBUG_IMAGE) --push \ --build-arg golang_image=$(GOLANG_IMAGE) \ + --platform=$(PLATFORMS) \ docker/debug diff --git a/docker/debug/Dockerfile b/docker/debug/Dockerfile index 487d7205590..ab25713e891 100644 --- a/docker/debug/Dockerfile +++ b/docker/debug/Dockerfile @@ -1,11 +1,17 @@ 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 +#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 && \ + make install; \ + else \ + touch /go/bin/dlv; \ + fi FROM $golang_image COPY --from=build /go/bin/dlv /go/bin/dlv 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/plugin/storage/es/Dockerfile.rollover b/plugin/storage/es/Dockerfile.rollover index f58d054b6e5..223e39814d5 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"] diff --git a/scripts/build-all-in-one-image.sh b/scripts/build-all-in-one-image.sh index 0b89a6f7634..ba9a20b526e 100755 --- a/scripts/build-all-in-one-image.sh +++ b/scripts/build-all-in-one-image.sh @@ -34,36 +34,23 @@ 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 -} - -make build-all-in-one GOOS=linux GOARCH=$GOARCH 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" 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 +#build all-in-one image locally for integration test +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 -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=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 -run_integration_test $repo -upload_to_docker $repo +repo=${repo}-debug +#build all-in-one-debug image locally for integration test +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 -b -c all-in-one-debug -d cmd/all-in-one -t debug diff --git a/scripts/build-crossdock.sh b/scripts/build-crossdock.sh index f17f90dddc9..ae627172586 100755 --- a/scripts/build-crossdock.sh +++ b/scripts/build-crossdock.sh @@ -10,12 +10,15 @@ 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' + 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=linux/amd64 \ + ${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-upload-a-docker-image.sh b/scripts/build-upload-a-docker-image.sh new file mode 100644 index 00000000000..56df0ab644b --- /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 "lbc:d:f:p:t:" opt; do + case "${opt}" in + c) + component_name=${OPTARG} + ;; + b) + 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} + ;; + 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} ${component_name} ==============" diff --git a/scripts/build-upload-docker-images.sh b/scripts/build-upload-docker-images.sh new file mode 100644 index 00000000000..c40757184f5 --- /dev/null +++ b/scripts/build-upload-docker-images.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +set -euxf -o pipefail + +make create-baseimg-debugimg + +# build multi-arch binaries +make build-binaries-linux +make build-binaries-s390x + +# build multi-arch docker images +platforms="linux/amd64,linux/s390x" + +# 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 -b -c "jaeger-${component}" -d "cmd/${component}" -p "${platforms}" -t release +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}" + +# 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 + + +# build amd64 docker images + +# 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 -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/ diff --git a/scripts/compute-tags.sh b/scripts/compute-tags.sh new file mode 100644 index 00000000000..342e3c70b3f --- /dev/null +++ b/scripts/compute-tags.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Compute major/minor/etc image tags based on the current branch + +set -exu + +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) +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}') +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.sh b/scripts/docker-login.sh new file mode 100644 index 00000000000..22561d1d84b --- /dev/null +++ b/scripts/docker-login.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 diff --git a/scripts/hotrod-integration-test.sh b/scripts/hotrod-integration-test.sh index 91790ba3010..851919d6f89 100755 --- a/scripts/hotrod-integration-test.sh +++ b/scripts/hotrod-integration-test.sh @@ -2,9 +2,15 @@ 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" +#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 while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' localhost:8080)" != "200" && ${i} < 30 ]]; do sleep 1 @@ -20,11 +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" -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 +bash scripts/build-upload-a-docker-image.sh -c example-hotrod -d examples/hotrod -p "${platforms}" 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 diff --git a/scripts/upload-to-registry.sh b/scripts/upload-to-registry.sh deleted file mode 100755 index 8156bd9819a..00000000000 --- a/scripts/upload-to-registry.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/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:-} - -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