Cleanup rust #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: 💫 Build and push Spilo | |
| on: | |
| push: | |
| branches: [master] | |
| concurrency: | |
| group: environment-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| setup_env: | |
| name: ⚙️ Setup environment | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - name: Add SHORT_SHA env property | |
| run: echo "SHORT_SHA=`echo ${GITHUB_SHA::7}`" >> $GITHUB_ENV | |
| - name: Put commit msg in environment | |
| run: echo "COMMIT_MSG=${{ github.event.head_commit.message }}" >> $GITHUB_ENV | |
| - name: Escape commit message | |
| run: | | |
| echo "COMMIT_MSG=$(echo $COMMIT_MSG | tr -d \'\\\")" >> $GITHUB_ENV | |
| - name: Get branch name (merge) | |
| if: github.event_name != 'pull_request' | |
| shell: bash | |
| run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV | |
| - name: Get branch name (pull request) | |
| if: github.event_name == 'pull_request' | |
| shell: bash | |
| run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF} | tr / -)" >> $GITHUB_ENV | |
| - name: Set build start in env variable | |
| run: echo "BUILD_START=$(date +%s)" >> $GITHUB_ENV | |
| outputs: | |
| short_sha: ${{ env.SHORT_SHA }} | |
| commit_msg: ${{ env.COMMIT_MSG }} | |
| branch_name: ${{ env.BRANCH_NAME }} | |
| build_start: ${{ env.BUILD_START }} | |
| build_spilo: | |
| name: 🔨 Build Spilo ${{ matrix.pgversion }} for ${{ matrix.arch }} | |
| needs: setup_env | |
| strategy: | |
| matrix: | |
| pgversion: [14, 15, 16, 17] | |
| arch: [amd64, arm64] | |
| include: | |
| - arch: amd64 | |
| platform: linux/amd64 | |
| runs-on: ubuntu-24.04 | |
| - arch: arm64 | |
| platform: linux/arm64 | |
| runs-on: ubuntu-24.04-arm | |
| runs-on: ${{ matrix.runs-on }} | |
| env: | |
| GITHUB_RUN_ID: ${{ github.run_id }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| # Set up cache for Docker layers | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| with: | |
| # Use a custom builder instance with persistent caching | |
| driver-opts: | | |
| image=moby/buildkit:latest | |
| network=host | |
| # Cache Docker layers | |
| - name: Cache Docker layers | |
| uses: actions/cache@v4 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-${{ matrix.arch }}-buildx-${{ matrix.pgversion }}-${{ hashFiles('./postgres-appliance/Dockerfile') }} | |
| restore-keys: | | |
| ${{ runner.os }}-${{ matrix.arch }}-buildx-${{ matrix.pgversion }}- | |
| ${{ runner.os }}-${{ matrix.arch }}-buildx- | |
| - name: Login to registry | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build and push Spilo image | |
| if: success() | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./postgres-appliance | |
| platforms: ${{ matrix.platform }} | |
| provenance: false | |
| push: true | |
| file: ./postgres-appliance/Dockerfile | |
| tags: unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-${{ matrix.arch }} | |
| build-args: | | |
| PGVERSION=${{ matrix.pgversion }} | |
| # Use the cache | |
| cache-from: type=local,src=/tmp/.buildx-cache | |
| cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max | |
| # Move cache to prevent cache growth (see https://github.com/docker/build-push-action/issues/252) | |
| - name: Move cache | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| create_manifests: | |
| name: 📦 Create and Push Multi-Arch Manifests for PostgreSQL ${{ matrix.pgversion }} | |
| runs-on: ubuntu-24.04 | |
| needs: [setup_env, build_spilo] | |
| strategy: | |
| matrix: | |
| pgversion: [14, 15, 16, 17] | |
| env: | |
| GITHUB_RUN_ID: ${{ github.run_id }} | |
| steps: | |
| - name: Login to registry | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Create and push manifest for PG ${{ matrix.pgversion }} | |
| run: | | |
| # Create run-specific tag with both architectures | |
| docker manifest create unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} \ | |
| --amend unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 \ | |
| --amend unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
| docker manifest annotate --arch amd64 --os linux unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 | |
| docker manifest annotate --arch arm64 --os linux unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
| docker manifest push unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }} | |
| # Tag as version-latest | |
| docker manifest create unbindapp/spilo:${{ matrix.pgversion }}-latest \ | |
| --amend unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 \ | |
| --amend unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
| docker manifest annotate --arch amd64 --os linux unbindapp/spilo:${{ matrix.pgversion }}-latest unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 | |
| docker manifest annotate --arch arm64 --os linux unbindapp/spilo:${{ matrix.pgversion }}-latest unbindapp/spilo:${{ matrix.pgversion }}-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
| docker manifest push unbindapp/spilo:${{ matrix.pgversion }}-latest | |
| # Optional: Add a separate step to tag the latest PostgreSQL version as the default "latest" tag | |
| tag_latest: | |
| name: 🏷️ Tag PostgreSQL 17 as Latest | |
| runs-on: ubuntu-24.04 | |
| needs: [setup_env, create_manifests] | |
| env: | |
| GITHUB_RUN_ID: ${{ github.run_id }} | |
| steps: | |
| - name: Login to registry | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKER_USER }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Tag PostgreSQL 17 as latest | |
| run: | | |
| docker manifest create unbindapp/spilo:latest \ | |
| --amend unbindapp/spilo:17-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 \ | |
| --amend unbindapp/spilo:17-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
| docker manifest annotate --arch amd64 --os linux unbindapp/spilo:latest unbindapp/spilo:17-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-amd64 | |
| docker manifest annotate --arch arm64 --os linux unbindapp/spilo:latest unbindapp/spilo:17-${{ needs.setup_env.outputs.branch_name }}-${{ env.GITHUB_RUN_ID }}-arm64 | |
| docker manifest push unbindapp/spilo:latest |