|
| 1 | +name: Build Services |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + push: |
| 7 | + description: Push images |
| 8 | + required: true |
| 9 | + type: boolean |
| 10 | + default: true |
| 11 | + workflow_call: |
| 12 | + |
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + REPO: datadog/images-rb |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - service: datadog/agent |
| 24 | + arch: ["x86_64", "aarch64"] |
| 25 | + - service: datadog/dd-apm-test-agent |
| 26 | + arch: ["x86_64", "aarch64"] |
| 27 | + - service: elasticsearch |
| 28 | + arch: ["x86_64", "aarch64"] |
| 29 | + - service: memcached |
| 30 | + arch: ["x86_64", "aarch64"] |
| 31 | + - service: mongo |
| 32 | + arch: ["x86_64", "aarch64"] |
| 33 | + - service: mysql |
| 34 | + arch: ["x86_64", "aarch64"] |
| 35 | + - service: opensearchproject/opensearch |
| 36 | + arch: ["x86_64", "aarch64"] |
| 37 | + - service: postgres |
| 38 | + arch: ["x86_64", "aarch64"] |
| 39 | + - service: redis |
| 40 | + arch: ["x86_64", "aarch64"] |
| 41 | + - service: starburstdata/presto |
| 42 | + arch: ["x86_64", "aarch64"] |
| 43 | + runs-on: ubuntu-24.04 |
| 44 | + permissions: |
| 45 | + packages: write |
| 46 | + name: Build (${{ matrix.service }}) |
| 47 | + steps: |
| 48 | + - name: Set up Docker |
| 49 | + uses: crazy-max/ghaction-setup-docker@635d07c09dc2b52072362e9bb37e7e789767106d |
| 50 | + with: |
| 51 | + daemon-config: | |
| 52 | + { |
| 53 | + "features": { |
| 54 | + "containerd-snapshotter": true |
| 55 | + } |
| 56 | + } |
| 57 | + - name: Set up Ruby |
| 58 | + uses: ruby/setup-ruby@2654679fe7f7c29875c669398a8ec0791b8a64a1 |
| 59 | + with: |
| 60 | + ruby-version: '3.4' |
| 61 | + - name: Checkout |
| 62 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 |
| 63 | + with: |
| 64 | + persist-credentials: false |
| 65 | + fetch-depth: 2 |
| 66 | + - name: Bundle install |
| 67 | + run: | |
| 68 | + bundle install |
| 69 | + - name: Set variables |
| 70 | + id: vars |
| 71 | + run: | |
| 72 | + echo "DOCKER_PLATFORMS=$(echo ${{ join(matrix.arch) }} | tr ',' '\n' | sed 's/^/linux\//' | paste -s -d, -)" >> $GITHUB_OUTPUT |
| 73 | +
|
| 74 | + # First, build image for x86_64 as it will fail fast |
| 75 | + # |
| 76 | + - name: Build single-arch image (x86_64) |
| 77 | + if: ${{ contains(matrix.arch, 'x86_64') }} |
| 78 | + run: | |
| 79 | + bundle exec rake docker:build['services/${{ matrix.service }}:*'] PLATFORM='linux/x86_64' |
| 80 | +
|
| 81 | + # Then, build image for aarch64 which, being emulated under qemu, is slower |
| 82 | + # |
| 83 | + # Start by enabling qemu for aarch64 |
| 84 | + - name: Enable aarch64 emulation (x86_64) |
| 85 | + if: ${{ contains(matrix.arch, 'aarch64') }} |
| 86 | + run: | |
| 87 | + docker run --privileged --rm tonistiigi/binfmt --install arm64 |
| 88 | + - name: Build single-arch image (aarch64) |
| 89 | + if: ${{ contains(matrix.arch, 'aarch64') }} |
| 90 | + run: | |
| 91 | + bundle exec rake docker:build['services/${{ matrix.service }}:*'] PLATFORM='linux/aarch64' |
| 92 | +
|
| 93 | + # Finally, assemble multi-arch image for a combined push to the registry |
| 94 | + # |
| 95 | + # This reruns docker build but layers are in the cache, so it's fast |
| 96 | + - name: Log in to the Container Registry |
| 97 | + run: | |
| 98 | + echo ${{ secrets.GITHUB_TOKEN }} | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin |
| 99 | + - name: Push release image (${{ join(matrix.arch, ', ') }}) |
| 100 | + if: ${{ inputs.push }} |
| 101 | + run: | |
| 102 | + bundle exec rake docker:build['services/${{ matrix.service }}:*'] PLATFORM='${{ steps.vars.outputs.DOCKER_PLATFORMS }}' PUSH=true |
0 commit comments