diff --git a/.github/workflows/build-images-elastic.yml b/.github/workflows/build-images-elastic.yml new file mode 100644 index 0000000000..fd64e8beb5 --- /dev/null +++ b/.github/workflows/build-images-elastic.yml @@ -0,0 +1,12 @@ +name: Test image generation + +on: + push: + paths: + - 'src/**' + - 'test/**' + +jobs: + build_images: + if: github.repository == 'elastic/opentelemetry-demo' + uses: ./.github/workflows/component_build_images-elastic.yml diff --git a/.github/workflows/component_build-images-elastic.yml b/.github/workflows/component_build-images-elastic.yml new file mode 100644 index 0000000000..8571e9e3fb --- /dev/null +++ b/.github/workflows/component_build-images-elastic.yml @@ -0,0 +1,158 @@ +on: + workflow_call: + inputs: + push: + description: Should the images be pushed + default: false + required: false + type: boolean + version: + description: The version used when tagging the image + default: 'dev' + required: false + type: string + +jobs: + build_and_push_images: + if: github.repository == 'elastic/opentelemetry-demo' + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + env: + RELEASE_VERSION: "${{ github.event.release.tag_name }}" + GHCR_REPO: "ghcr.io/elastic/opentelemetry-demo" + + strategy: + fail-fast: false + matrix: + file_tag: + - file: ./src/accountingservice/Dockerfile + tag_suffix: accountingservice + context: ./ + setup-qemu: true + - file: ./src/adservice/Dockerfile.elastic + tag_suffix: adservice + context: ./ + setup-qemu: true + - file: ./src/cartservice/src/Dockerfile + tag_suffix: cartservice + context: ./ + setup-qemu: false + - file: ./src/checkoutservice/Dockerfile + tag_suffix: checkoutservice + context: ./ + setup-qemu: true + - file: ./src/currencyservice/Dockerfile + tag_suffix: currencyservice + context: ./ + setup-qemu: true + - file: ./src/emailservice/Dockerfile + tag_suffix: emailservice + context: ./src/emailservice + setup-qemu: true + - file: ./src/frauddetectionservice/Dockerfile + tag_suffix: frauddetectionservice + context: ./ + setup-qemu: true + - file: ./src/frontend/Dockerfile + tag_suffix: frontend + context: ./ + setup-qemu: true + - file: ./src/frontendproxy/Dockerfile + tag_suffix: frontendproxy + context: ./ + setup-qemu: true + - file: ./src/frontend/Dockerfile.cypress + tag_suffix: frontend-tests + context: ./ + setup-qemu: true + - file: ./src/imageprovider/Dockerfile + tag_suffix: imageprovider + context: ./ + setup-qemu: true + - file: ./src/kafka/Dockerfile + tag_suffix: kafka + context: ./ + setup-qemu: true + - file: ./src/loadgenerator/Dockerfile + tag_suffix: loadgenerator + context: ./ + setup-qemu: true + - file: ./src/paymentservice/Dockerfile + tag_suffix: paymentservice + context: ./ + setup-qemu: true + - file: ./src/productcatalogservice/Dockerfile + tag_suffix: productcatalogservice + context: ./ + setup-qemu: true + - file: ./src/quoteservice/Dockerfile + tag_suffix: quoteservice + context: ./ + setup-qemu: true + - file: ./src/recommendationservice/Dockerfile + tag_suffix: recommendationservice + context: ./ + setup-qemu: true + - file: ./src/shippingservice/Dockerfile + tag_suffix: shippingservice + context: ./ + setup-qemu: true + - file: ./test/tracetesting/Dockerfile + tag_suffix: traceBasedTests + context: ./ + setup-qemu: true + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check for changes and set push options + id: check_changes + run: | + DOCKERFILE_DIR=$(dirname ${{ matrix.file_tag.file }}) + FILES_CHANGED=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} -- $DOCKERFILE_DIR) + FORCE_PUSH=${{ inputs.push }} + if [ "$FORCE_PUSH" = true ]; then + echo "Force push is enabled, proceeding with build." + echo "skip=false" >> "$GITHUB_OUTPUT" + elif [ -z "$FILES_CHANGED" ]; then + echo "No changes in ${{ matrix.file_tag.context }}, skipping build." + echo "skip=true" >> "$GITHUB_OUTPUT" + else + echo "Changes detected in ${{ matrix.file_tag.context }}, proceeding with build." + echo "skip=false" >> "$GITHUB_OUTPUT" + fi + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + if: ${{ inputs.push }} + - name: Set up QEMU + if: ${{ matrix.file_tag.setup-qemu }} + uses: docker/setup-qemu-action@v3 + with: + image: tonistiigi/binfmt:master + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + config-inline: | + [worker.oci] + max-parallelism = 2 + - name: Matrix Build and push demo images + if: steps.check_changes.outputs.skip == 'false' + uses: docker/build-push-action@v5.0.0 + with: + context: ${{ matrix.file_tag.context }} + file: ${{ matrix.file_tag.file }} + platforms: linux/amd64,linux/arm64 + push: ${{ inputs.push }} + tags: | + ${{ env.GHCR_REPO }}:${{ inputs.version }}-${{ matrix.file_tag.tag_suffix }} + ${{ env.GHCR_REPO }}:latest-${{ matrix.file_tag.tag_suffix }} + cache-from: type=gha + cache-to: type=gha diff --git a/.github/workflows/release-elastic.yml b/.github/workflows/release-elastic.yml new file mode 100644 index 0000000000..6bf30c9db6 --- /dev/null +++ b/.github/workflows/release-elastic.yml @@ -0,0 +1,14 @@ +name: "Build and Publish" + +on: + release: + types: [published] + +jobs: + build_and_push_images: + uses: ./.github/workflows/component_build-images-elastic.yml + if: github.repository == 'elastic/opentelemetry-demo' + with: + push: true + version: ${{ github.event.release.tag_name }} + secrets: inherit