|
| 1 | +name: Publish Electric canary image to Docker Hub |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # TMP for testing |
| 6 | + # branches: ['main'] |
| 7 | + branches: ['alco/ci-build-public-docker-images'] |
| 8 | + |
| 9 | +jobs: |
| 10 | + derive_build_vars: |
| 11 | + name: Derive build variables from the source code |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + short_commit_sha: ${{ steps.vars.outputs.short_commit_sha }} |
| 15 | + electric_version: ${{ steps.vars.outputs.electric_version }} |
| 16 | + |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + # It is crucial that we checkout the actual HEAD commit of the branch instead of |
| 21 | + # GitHub's ephemeral merge commit that it creates for CI runs by default. |
| 22 | + # We rely on the correct HEAD commit to be checked out in order to determine the |
| 23 | + # correct ELECTRIC_VERSION to bake into the Docker image. |
| 24 | + ref: ${{ github.event.pull_request.head.sha }} |
| 25 | + # Also important to fetch the whole history since otherwise we won't get that tags |
| 26 | + # that are required to determine the correct ELECTRIC_VERSION. |
| 27 | + fetch-depth: 0 |
| 28 | + fetch-tags: true |
| 29 | + |
| 30 | + - name: Determine SHORT_COMMIT_SHA and ELECTRIC_VERSION to use in the build step |
| 31 | + id: vars |
| 32 | + run: | |
| 33 | + echo "short_commit_sha=$( |
| 34 | + git rev-parse --short HEAD |
| 35 | + )" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + echo "electric_version=$( |
| 38 | + git describe --abbrev=7 --tags --always --first-parent --match '@core/sync-service@*' | sed -En 's|^@core/sync-service@||p' |
| 39 | + )" >> $GITHUB_OUTPUT |
| 40 | +
|
| 41 | + build_and_push_image: |
| 42 | + strategy: |
| 43 | + matrix: |
| 44 | + include: |
| 45 | + - platform: linux/amd64 |
| 46 | + runner: ubuntu-latest |
| 47 | + - platform: linux/arm64/v8 |
| 48 | + runner: ubuntu-24.04-arm |
| 49 | + runs-on: ${{ matrix.runner }} |
| 50 | + needs: [derive_build_vars] |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + |
| 54 | + - uses: docker/setup-buildx-action@v3 |
| 55 | + |
| 56 | + # Login to Docker Hub (create a token in Docker Hub, store as secret). |
| 57 | + #- name: Log in to Docker Hub |
| 58 | + # uses: docker/login-action@v3 |
| 59 | + # with: |
| 60 | + # registry: docker.io |
| 61 | + # username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 62 | + # password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 63 | + |
| 64 | + - name: Build and push by digest |
| 65 | + id: build |
| 66 | + uses: docker/build-push-action@v6 |
| 67 | + with: |
| 68 | + context: packages/sync-service |
| 69 | + build-contexts: | |
| 70 | + electric-telemetry=packages/electric-telemetry |
| 71 | + build-args: | |
| 72 | + ELECTRIC_VERSION=${{ needs.derive_build_vars.outputs.electric_version }} |
| 73 | + platforms: ${{ matrix.platform }} |
| 74 | + push: true |
| 75 | + # push an untagged image and export its digest |
| 76 | + # the subsequent merge job will assemble the manifest list and apply tags |
| 77 | + outputs: type=image,name=electricsql/electric,push-by-digest=true |
| 78 | + # tags: | |
| 79 | + # electricsql/electric:canary |
| 80 | + # electricsql/electric-canary:${{ env.SHORT_COMMIT_SHA }} |
| 81 | + # electricsql/electric-canary:latest |
| 82 | + cache-from: type=gha |
| 83 | + cache-to: type=gha,mode=max |
| 84 | + |
| 85 | + # Save the digest so the merge job can find both platform images |
| 86 | + - name: Export digest |
| 87 | + run: | |
| 88 | + mkdir -p /tmp/digests |
| 89 | + echo "${{ steps.build.outputs.digest }}" > "/tmp/digests/${{ matrix.platform }}.digest" |
| 90 | +
|
| 91 | + - uses: actions/upload-artifact@v4 |
| 92 | + with: |
| 93 | + name: digests-${{ matrix.platform }} |
| 94 | + path: /tmp/digests/*.digest |
| 95 | + |
| 96 | + publish_tagged_image: |
| 97 | + needs: [derive_build_vars, build_and_push_image] |
| 98 | + runs-on: ubuntu-latest |
| 99 | + steps: |
| 100 | + # - uses: docker/login-action@v3 |
| 101 | + # with: |
| 102 | + # username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 103 | + # password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 104 | + |
| 105 | + - uses: docker/setup-buildx-action@v3 |
| 106 | + |
| 107 | + - uses: actions/download-artifact@v4 |
| 108 | + with: |
| 109 | + pattern: digests-* |
| 110 | + merge-multiple: true |
| 111 | + path: /tmp/digests |
| 112 | + |
| 113 | + - name: Create multi-arch manifest list |
| 114 | + run: | |
| 115 | + set -euo pipefail |
| 116 | +
|
| 117 | + cat /tmp/digests/*.digest |
| 118 | +
|
| 119 | + SINGLE_PLATFORM_IMAGES=$( |
| 120 | + for f in /tmp/digests/*.digest; do |
| 121 | + echo electricsql/electric@$(cat $f) |
| 122 | + done |
| 123 | + ) |
| 124 | +
|
| 125 | + echo $SINGLE_PLATFORM_IMAGES |
| 126 | +
|
| 127 | + docker buildx imagetools create --dry-run \ |
| 128 | + -t electricsql/electric:canary \ |
| 129 | + -t electricsql/electric-canary:latest \ |
| 130 | + -t electricsql/electric-canary:${{ needs.derive_build_vars.outputs.short_commit_sha }} |
| 131 | + $SINGLE_PLATFORM_IMAGES |
0 commit comments