diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..e209d9e --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,87 @@ +name: Build and Push Docker Images + +on: + workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + release: + types: [released] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + packages: write + +jobs: + build_and_push: + runs-on: ubuntu-latest + strategy: + # Prevent a failure in one image from stopping the other builds + fail-fast: false + matrix: + # TODO: Get Renovate to update these + cnpgTag: + - 14.10 + - 15.5 + - 16.1 + pgvectorsVersion: + - v0.1.10 + + steps: + # Setup + + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3.0.0 + if: ${{ !github.event.pull_request.head.repo.fork }} + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set major postgres version + id: version + run: | + pg_major=$(echo ${{ matrix.cnpgTag }} | cut -d'.' -f1) + echo "pg_major=$pg_major" >> "$GITHUB_OUTPUT" + + - name: Generate docker image tags + id: metadata + uses: docker/metadata-action@v5 + with: + flavor: | + # Disable latest tag + latest=false + images: | + name=ghcr.io/${{ github.repository_owner }}/cnpgvecto.rs + tags: | + type=ref,event=branch + type=ref,event=pr + # TODO: When exactly to push these tags? + type=raw,value=${{ matrix.cnpgTag }}-${{ matrix.pgvectorsVersion }} + type=raw,value=${{ steps.version.outputs.pg_major }}-${{ matrix.pgvectorsVersion }} + + - name: Build and push image + uses: docker/build-push-action@v4.1.1 + with: + context: . + # TODO: Enable multiarch build + platforms: linux/amd64 + push: ${{ !github.event.pull_request }} + cache-from: type=gha + cache-to: type=gha,mode=max + tags: ${{ steps.metadata.outputs.tags }} + labels: ${{ steps.metadata.outputs.labels }} + build-args: PG_MAJOR=${{ steps.version.outputs.pg_major }},PGVECTORS_TAG=${{ matrix.pgvectorsVersion }} diff --git a/Dockerfile b/Dockerfile index a827e7e..e171c80 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ ARG PG_MAJOR=14 FROM ghcr.io/cloudnative-pg/postgresql:$PG_MAJOR ARG PG_MAJOR -ARG PGVECTORS_TAG=v0.1.10 +ARG PGVECTORS_TAG ARG ARCH=x86_64 # drop to root to install packages