From ff083f7a83f69a5947cfb59390dae9737e98c4de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraci=20Paix=C3=A3o=20Kr=C3=B6hling?= Date: Fri, 11 Dec 2020 16:04:31 +0100 Subject: [PATCH] Refactor how images are pushed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Juraci Paixão Kröhling --- .ci/publish-bundle-images.sh | 31 ------- .ci/publish-images.sh | 29 ------- .github/workflows/publish-images.yaml | 81 +++++++++++++++++++ .github/workflows/release.yaml | 16 ---- .../workflows/remove-me-before-merging.yaml | 63 +++++++++++++++ CONTRIBUTING.md | 2 +- Makefile | 8 +- 7 files changed, 149 insertions(+), 81 deletions(-) delete mode 100755 .ci/publish-bundle-images.sh delete mode 100755 .ci/publish-images.sh create mode 100644 .github/workflows/publish-images.yaml create mode 100644 .github/workflows/remove-me-before-merging.yaml diff --git a/.ci/publish-bundle-images.sh b/.ci/publish-bundle-images.sh deleted file mode 100755 index c9e6cabb14..0000000000 --- a/.ci/publish-bundle-images.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -OPERATOR_VERSION=${OPERATOR_VERSION:-$(git describe --tags | grep -Po "([\d\.]+)")} - -echo "Building bundle image" -make bundle-build - -## push to Docker Hub -if [ "${DOCKER_PASSWORD}x" != "x" -a "${DOCKER_USERNAME}x" != "x" ]; then - echo "Performing a 'docker login'" - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - TARGET_IMAGE="otel/opentelemetry-operator-bundle:${OPERATOR_VERSION}" - docker tag "controller-bundle:${OPERATOR_VERSION}" "${TARGET_IMAGE}" - - echo "Pushing ${TARGET_IMAGE}" - docker push "${TARGET_IMAGE}" -fi - -## push to quay.io -if [ "${QUAY_PASSWORD}x" != "x" -a "${QUAY_USERNAME}x" != "x" ]; then - echo "Performing a 'docker login' for Quay" - echo "${QUAY_PASSWORD}" | docker login -u "${QUAY_USERNAME}" quay.io --password-stdin - - TARGET_IMAGE="quay.io/opentelemetry/opentelemetry-operator-bundle:${OPERATOR_VERSION}" - docker tag "controller-bundle:${OPERATOR_VERSION}" "${TARGET_IMAGE}" - - echo "Pushing ${TARGET_IMAGE}" - docker push "${TARGET_IMAGE}" -fi - diff --git a/.ci/publish-images.sh b/.ci/publish-images.sh deleted file mode 100755 index 18979b589d..0000000000 --- a/.ci/publish-images.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -source ./.ci/tagAndPushFunc.sh - -BASE_BUILD_IMAGE=${BASE_BUILD_IMAGE:-"otel/opentelemetry-operator"} -OPERATOR_VERSION=${OPERATOR_VERSION:-$(git describe --tags | grep -Po "([\d\.]+)")} -BUILD_IMAGE=${BUILD_IMAGE:-"${BASE_BUILD_IMAGE}:${OPERATOR_VERSION}"} - -echo "Building image ${BUILD_IMAGE}" -make container IMG="${BUILD_IMAGE}" VERSION=${OPERATOR_VERSION} - -## push to Docker Hub -if [ "${DOCKER_PASSWORD}x" != "x" -a "${DOCKER_USERNAME}x" != "x" ]; then - echo "Performing a 'docker login'" - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - - BASE_BUILD_IMAGE=${DOCKER_BASE_BUILD_IMAGE:-"otel/opentelemetry-operator"} - tagAndPush ${BUILD_IMAGE} ${BASE_BUILD_IMAGE} ${OPERATOR_VERSION} -fi - -## push to quay.io -if [ "${QUAY_PASSWORD}x" != "x" -a "${QUAY_USERNAME}x" != "x" ]; then - echo "Performing a 'docker login' for Quay" - echo "${QUAY_PASSWORD}" | docker login -u "${QUAY_USERNAME}" quay.io --password-stdin - - BASE_BUILD_IMAGE=${QUAY_BASE_BUILD_IMAGE:-"quay.io/opentelemetry/opentelemetry-operator"} - tagAndPush ${BUILD_IMAGE} ${BASE_BUILD_IMAGE} ${OPERATOR_VERSION} -fi - diff --git a/.github/workflows/publish-images.yaml b/.github/workflows/publish-images.yaml new file mode 100644 index 0000000000..6a0c675356 --- /dev/null +++ b/.github/workflows/publish-images.yaml @@ -0,0 +1,81 @@ +name: "Publish images" + +on: + push: + branches: [master] + release: + types: [published] + +jobs: + publish-dockerhub: + name: Publish image to Docker Hub + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Set env vars for the job + run: | + grep -v '\#' versions.txt | grep opentelemetry-collector | awk -F= '{print "OTELCOL_VERSION="$2}' >> $GITHUB_ENV + echo "VERSION_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + echo "VERSION=$(git describe --tags | sed 's/^v//')" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Login to Quay.io + uses: docker/login-action@v1 + with: + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_PASSWORD }} + + - name: Build and push Operator image + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + push: true + build-args: | + VERSION_PKG=github.com/open-telemetry/opentelemetry-operator/internal/version + VERSION=${VERSION} + VERSION_DATE=${VERSION_DATE} + OTELCOL_VERSION=${OTELCOL_VERSION} + tags: | + otel/opentelemetry-operator:latest + otel/opentelemetry-operator:${GITHUB_REF} + quay.io/opentelemetry/opentelemetry-operator:latest + quay.io/opentelemetry/opentelemetry-operator:${GITHUB_REF} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Build and push bundle image + uses: docker/build-push-action@v2 + with: + context: . + file: ./bundle.Dockerfile + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + push: true + tags: | + otel/opentelemetry-operator-bundle:latest + otel/opentelemetry-operator-bundle:${GITHUB_REF} + quay.io/opentelemetry/opentelemetry-operator-bundle:latest + quay.io/opentelemetry/opentelemetry-operator-bundle:${GITHUB_REF} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 1fab8f6b48..1b4ccda71e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -23,22 +23,6 @@ jobs: - name: "generate release resources" run: make release-artifacts IMG_PREFIX="quay.io/opentelemetry" - - name: "publish the images" - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }} - QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }} - run: ./.ci/publish-images.sh - - - name: "publish the bundle image" - env: - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }} - QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }} - run: ./.ci/publish-bundle-images.sh - - name: "create the release in GitHub" env: GH_WRITE_TOKEN: ${{ secrets.GH_WRITE_TOKEN }} diff --git a/.github/workflows/remove-me-before-merging.yaml b/.github/workflows/remove-me-before-merging.yaml new file mode 100644 index 0000000000..0d55a952ea --- /dev/null +++ b/.github/workflows/remove-me-before-merging.yaml @@ -0,0 +1,63 @@ +name: "Remove me before merging" + +on: + pull_request: + branches: [master] + +jobs: + publish-dockerhub: + name: Publish image to Docker Hub + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + + - name: Set env vars for the job + run: | + grep -v '\#' versions.txt | grep opentelemetry-collector | awk -F= '{print "OTELCOL_VERSION="$2}' >> $GITHUB_ENV + echo "VERSION_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_ENV + echo "VERSION=latest" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build and push Operator image + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + push: false + build-args: | + VERSION_PKG=github.com/open-telemetry/opentelemetry-operator/internal/version + VERSION=${VERSION} + VERSION_DATE=${VERSION_DATE} + OTELCOL_VERSION=${OTELCOL_VERSION} + tags: | + otel/opentelemetry-operator:latest + quay.io/opentelemetry/opentelemetry-operator:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Build and push bundle image + uses: docker/build-push-action@v2 + with: + context: . + file: ./bundle.Dockerfile + platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/ppc64le,linux/s390x + push: false + tags: | + otel/opentelemetry-operator-bundle:latest + quay.io/opentelemetry/opentelemetry-operator-bundle:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90b7e44089..fb35b54c97 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -47,7 +47,7 @@ make cert-manager Once it's ready, the following can be used to build and deploy a manager, along with the required webhook configuration: ``` -make manifests container docker-push deploy +make manifests container container-push deploy ``` By default, it will generate an image following the format `quay.io/${USER}/opentelemetry-operator:${VERSION}`. You can set the following env vars in front of the `make` command to override parts or the entirety of the image: diff --git a/Makefile b/Makefile index 515dceaeb6..13a3cc17c8 100644 --- a/Makefile +++ b/Makefile @@ -94,12 +94,12 @@ vet: generate: controller-gen $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." -# Build the docker image +# Build the container image, used only for local dev purposes container: test docker build -t ${IMG} --build-arg VERSION_PKG=${VERSION_PKG} --build-arg VERSION=${VERSION} --build-arg VERSION_DATE=${VERSION_DATE} --build-arg OTELCOL_VERSION=${OTELCOL_VERSION} . -# Push the docker image -docker-push: +# Push the container image, used only for local dev purposes +container-push: docker push ${IMG} cert-manager: @@ -160,7 +160,7 @@ bundle: operator-sdk manifests $(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) $(OPERATOR_SDK) bundle validate ./bundle -# Build the bundle image. +# Build the bundle image, used only for local dev purposes bundle-build: docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .