|
| 1 | +# Copyright The OpenTelemetry Authors |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_call: |
| 6 | + inputs: |
| 7 | + push: |
| 8 | + description: Should the images be pushed |
| 9 | + default: false |
| 10 | + required: false |
| 11 | + type: boolean |
| 12 | + version: |
| 13 | + description: The version used when tagging the image |
| 14 | + default: 'dev' |
| 15 | + required: false |
| 16 | + type: string |
| 17 | + dockerhub_repo: |
| 18 | + description: Docker Hub repository |
| 19 | + default: 'otel/demo' |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + ghcr_repo: |
| 23 | + description: GHCR repository |
| 24 | + default: 'ghcr.io/open-telemetry/demo' |
| 25 | + required: false |
| 26 | + type: string |
| 27 | + |
| 28 | +jobs: |
| 29 | + build_and_push_images: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + permissions: |
| 32 | + contents: read |
| 33 | + packages: write |
| 34 | + |
| 35 | + env: |
| 36 | + RELEASE_VERSION: "${{ github.event.release.tag_name }}" |
| 37 | + |
| 38 | + strategy: |
| 39 | + fail-fast: false |
| 40 | + matrix: |
| 41 | + file_tag: |
| 42 | + - file: ./src/accountingservice/Dockerfile |
| 43 | + tag_suffix: accountingservice |
| 44 | + context: ./ |
| 45 | + setup-qemu: true |
| 46 | + - file: ./src/adservice/Dockerfile |
| 47 | + tag_suffix: adservice |
| 48 | + context: ./ |
| 49 | + setup-qemu: true |
| 50 | + - file: ./src/cartservice/src/Dockerfile |
| 51 | + tag_suffix: cartservice |
| 52 | + context: ./ |
| 53 | + setup-qemu: false |
| 54 | + - file: ./src/checkoutservice/Dockerfile |
| 55 | + tag_suffix: checkoutservice |
| 56 | + context: ./ |
| 57 | + setup-qemu: true |
| 58 | + - file: ./src/currencyservice/Dockerfile |
| 59 | + tag_suffix: currencyservice |
| 60 | + context: ./ |
| 61 | + setup-qemu: true |
| 62 | + - file: ./src/emailservice/Dockerfile |
| 63 | + tag_suffix: emailservice |
| 64 | + context: ./src/emailservice |
| 65 | + setup-qemu: true |
| 66 | + - file: ./src/frauddetectionservice/Dockerfile |
| 67 | + tag_suffix: frauddetectionservice |
| 68 | + context: ./ |
| 69 | + setup-qemu: true |
| 70 | + - file: ./src/frontend/Dockerfile |
| 71 | + tag_suffix: frontend |
| 72 | + context: ./ |
| 73 | + setup-qemu: true |
| 74 | + - file: ./src/frontendproxy/Dockerfile |
| 75 | + tag_suffix: frontendproxy |
| 76 | + context: ./ |
| 77 | + setup-qemu: true |
| 78 | + - file: ./src/frontend/Dockerfile.cypress |
| 79 | + tag_suffix: frontend-tests |
| 80 | + context: ./ |
| 81 | + setup-qemu: true |
| 82 | + - file: ./src/imageprovider/Dockerfile |
| 83 | + tag_suffix: imageprovider |
| 84 | + context: ./ |
| 85 | + setup-qemu: true |
| 86 | + - file: ./src/kafka/Dockerfile |
| 87 | + tag_suffix: kafka |
| 88 | + context: ./ |
| 89 | + setup-qemu: true |
| 90 | + - file: ./src/loadgenerator/Dockerfile |
| 91 | + tag_suffix: loadgenerator |
| 92 | + context: ./ |
| 93 | + setup-qemu: true |
| 94 | + - file: ./src/paymentservice/Dockerfile |
| 95 | + tag_suffix: paymentservice |
| 96 | + context: ./ |
| 97 | + setup-qemu: true |
| 98 | + - file: ./src/productcatalogservice/Dockerfile |
| 99 | + tag_suffix: productcatalogservice |
| 100 | + context: ./ |
| 101 | + setup-qemu: true |
| 102 | + - file: ./src/quoteservice/Dockerfile |
| 103 | + tag_suffix: quoteservice |
| 104 | + context: ./ |
| 105 | + setup-qemu: true |
| 106 | + - file: ./src/recommendationservice/Dockerfile |
| 107 | + tag_suffix: recommendationservice |
| 108 | + context: ./ |
| 109 | + setup-qemu: true |
| 110 | + - file: ./src/shippingservice/Dockerfile |
| 111 | + tag_suffix: shippingservice |
| 112 | + context: ./ |
| 113 | + setup-qemu: true |
| 114 | + - file: ./test/tracetesting/Dockerfile |
| 115 | + tag_suffix: traceBasedTests |
| 116 | + context: ./ |
| 117 | + setup-qemu: true |
| 118 | + |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + with: |
| 122 | + fetch-depth: 0 |
| 123 | + - name: Check for changes and set push options |
| 124 | + id: check_changes |
| 125 | + run: | |
| 126 | + DOCKERFILE_DIR=$(dirname ${{ matrix.file_tag.file }}) |
| 127 | + FILES_CHANGED=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- $DOCKERFILE_DIR) |
| 128 | + FORCE_PUSH=${{ inputs.push }} |
| 129 | + if [ "$FORCE_PUSH" = true ]; then |
| 130 | + echo "Force push is enabled, proceeding with build." |
| 131 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 132 | + elif [ -z "$FILES_CHANGED" ]; then |
| 133 | + echo "No changes in ${{ matrix.file_tag.context }}, skipping build." |
| 134 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 135 | + else |
| 136 | + echo "Changes detected in ${{ matrix.file_tag.context }}, proceeding with build." |
| 137 | + echo "skip=false" >> "$GITHUB_OUTPUT" |
| 138 | + fi |
| 139 | + - name: Log in to the Container registry |
| 140 | + uses: docker/login-action@v3 |
| 141 | + with: |
| 142 | + registry: ghcr.io |
| 143 | + username: ${{ github.repository_owner }} |
| 144 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 145 | + if: ${{ inputs.push }} |
| 146 | + - name: Log in to Docker Hub |
| 147 | + uses: docker/login-action@v3 |
| 148 | + with: |
| 149 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 150 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 151 | + if: ${{ inputs.push }} |
| 152 | + - name: Set up QEMU |
| 153 | + if: ${{ matrix.file_tag.setup-qemu }} |
| 154 | + uses: docker/setup-qemu-action@v3 |
| 155 | + with: |
| 156 | + image: tonistiigi/binfmt:master |
| 157 | + - name: Set up Docker Buildx |
| 158 | + uses: docker/setup-buildx-action@v3 |
| 159 | + with: |
| 160 | + buildkitd-config-inline: | |
| 161 | + [worker.oci] |
| 162 | + max-parallelism = 2 |
| 163 | + - name: Matrix Build and push demo images |
| 164 | + if: steps.check_changes.outputs.skip == 'false' |
| 165 | + uses: docker/build-push-action@v5.4.0 |
| 166 | + with: |
| 167 | + context: ${{ matrix.file_tag.context }} |
| 168 | + file: ${{ matrix.file_tag.file }} |
| 169 | + platforms: linux/amd64,linux/arm64 |
| 170 | + push: ${{ inputs.push }} |
| 171 | + tags: | |
| 172 | + ${{ inputs.dockerhub_repo }}:${{ inputs.version }}-${{matrix.file_tag.tag_suffix }} |
| 173 | + ${{ inputs.dockerhub_repo }}:latest-${{matrix.file_tag.tag_suffix }} |
| 174 | + ${{ inputs.ghcr_repo }}:${{ inputs.version }}-${{ matrix.file_tag.tag_suffix }} |
| 175 | + ${{ inputs.ghcr_repo }}:latest-${{ matrix.file_tag.tag_suffix }} |
| 176 | + cache-from: type=gha |
| 177 | + cache-to: type=gha |
0 commit comments