Skip to content

The Makefile is only useful for local development these days #208

The Makefile is only useful for local development these days

The Makefile is only useful for local development these days #208

Workflow file for this run

name: Build and push
on:
push:
pull_request:
schedule:
- cron: "0 0 * * 0"
env:
LATEST_POSTGRES_VERSION: "17"
jobs:
base-images:
# for security reason, we only build these images in our repository and on the main branch
if: github.repository == 'pgautoupgrade/docker-pgautoupgrade' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
strategy:
matrix:
flavor:
- alpine
- bookworm
pg_version:
- "9.5"
- "9.6"
- "10"
- "11"
- "12"
- "13"
- "14"
- "15"
- "16"
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push image
uses: docker/build-push-action@v6
with:
file: "Dockerfile.${{ matrix.flavor }}"
push: true
platforms: linux/amd64,linux/arm64
build-args: |
"PGTARGET=16"
target: "build-${{ matrix.pg_version }}"
tags: "pgautoupgrade/pgautoupgrade:build-${{ matrix.pg_version }}-${{ matrix.flavor }}"
cache-to: type=inline
cache-from: type=registry,ref=pgautoupgrade/pgautoupgrade:build-${{ matrix.pg_version }}-${{ matrix.flavor }}
target-images:
runs-on: ubuntu-latest
needs: base-images
# otherwise, it would skip the build entirely (because the base step does not run)
if: always()
env:
# but still use our public caches in any case
# they might be outdated, in which case a full rebuild will be triggered
CACHE_FROM: |
type=registry,ref=pgautoupgrade/pgautoupgrade:build-9.5-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:build-9.6-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:build-10-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:build-11-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:build-12-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:build-13-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:build-14-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:build-15-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:build-16-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:${{ matrix.pg_target }}-${{ matrix.operating_system.flavor }}
type=registry,ref=pgautoupgrade/pgautoupgrade:${{ matrix.pg_target }}-${{ matrix.operating_system.flavor }}${{ matrix.operating_system.version }}
strategy:
matrix:
operating_system:
- flavor: "alpine"
version: "3.20"
- flavor: "bookworm"
pg_target:
- "12"
- "13"
- "14"
- "15"
- "16"
- "17"
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
if: github.repository == 'pgautoupgrade/docker-pgautoupgrade'
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build image
uses: docker/build-push-action@v6
with:
file: "Dockerfile.${{ matrix.operating_system.flavor }}"
load: true
tags: |
"pgautoupgrade/pgautoupgrade:${{ matrix.pg_target }}-${{ matrix.operating_system.flavor }}"
"pgautoupgrade/pgautoupgrade:${{ matrix.pg_target }}-${{ matrix.operating_system.flavor }}${{ matrix.operating_system.version }}"
build-args: |
"PGTARGET=${{ matrix.pg_target }}"
cache-to: type=inline
cache-from: "${{ env.CACHE_FROM }}"
- name: Checkout code
uses: actions/checkout@v4
- name: Test image
run: |
make test
env:
PGTARGET: ${{ matrix.pg_target }}
OS_FLAVOR: ${{ matrix.operating_system.flavor }}
# otherwise, we run into space problems
# from observation, the buildx builder container already occupies 7 GB out of the 14 GB we have available on a GitHub Actions runner
# note that this command will also destroy the pgautoupgrade image we just build
# which is intentional, the buildx builder should contain all information still to re-create the same image
- name: Cleanup Docker image before pushing
if: github.repository == 'pgautoupgrade/docker-pgautoupgrade' && github.ref == 'refs/heads/main'
run: |
docker image prune -a -f
- name: Push image
if: github.repository == 'pgautoupgrade/docker-pgautoupgrade' && github.ref == 'refs/heads/main'
uses: docker/build-push-action@v6
with:
file: "Dockerfile.${{ matrix.operating_system.flavor }}"
platforms: linux/amd64,linux/arm64
tags: |
"pgautoupgrade/pgautoupgrade:${{ matrix.pg_target }}-${{ matrix.operating_system.flavor }}"
"pgautoupgrade/pgautoupgrade:${{ matrix.pg_target }}-${{ matrix.operating_system.flavor }}${{ matrix.operating_system.version }}"
build-args: |
"PGTARGET=${{ matrix.pg_target }}"
push: true
cache-to: type=inline
cache-from: "${{ env.CACHE_FROM }}"
- name: Push latest image
if: github.repository == 'pgautoupgrade/docker-pgautoupgrade' && github.ref == 'refs/heads/main' && matrix.pg_target == env.LATEST_POSTGRES_VERSION && matrix.operating_system.flavor == 'alpine'
uses: docker/build-push-action@v6
with:
file: "Dockerfile.${{ matrix.operating_system.flavor }}"
platforms: linux/amd64,linux/arm64
tags: |
"pgautoupgrade/pgautoupgrade:latest"
build-args: |
"PGTARGET=${{ matrix.pg_target }}"
push: true
cache-to: type=inline
cache-from: "${{ env.CACHE_FROM }}"