From 42721205c9a3cbe6466d430f0448cdedb0fe70bf Mon Sep 17 00:00:00 2001 From: Matthew Baggett Date: Thu, 15 Feb 2024 01:36:29 +0100 Subject: [PATCH] Add postgres with healthcheck --- .github/workflows/build.yml | 9 ++++ .github/workflows/postgres.yml | 91 ++++++++++++++++++++++++++++++++ postgres/Dockerfile | 13 +++++ postgres/postgres_healthcheck.sh | 2 + 4 files changed, 115 insertions(+) create mode 100644 .github/workflows/postgres.yml create mode 100644 postgres/Dockerfile create mode 100755 postgres/postgres_healthcheck.sh diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3046dc2..ba076db 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -81,6 +81,15 @@ jobs: contents: read packages: write + postgres: + needs: qc-before + name: Postgres w/Healthcheck + uses: ./.github/workflows/postgres.yml + secrets: inherit + permissions: + contents: read + packages: write + mysql-proxy: needs: qc-before name: MySQL Proxy diff --git a/.github/workflows/postgres.yml b/.github/workflows/postgres.yml new file mode 100644 index 0000000..eb9529f --- /dev/null +++ b/.github/workflows/postgres.yml @@ -0,0 +1,91 @@ +name: Postgres w/Healthcheck + +permissions: + contents: read + packages: write + +on: + workflow_call: + workflow_dispatch: + push: + branches: + - main + paths: + - postgres/** + - .github/workflows/postgres.yml + +env: + should_push: ${{ github.ref == 'refs/heads/main' }} + +jobs: + postgres-build: + name: "Build" + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + version: + - latest + - 16 + - 16.2 + - 16.1 + - "16.0" + - 15 + - 15.6 + - 15.5 + - 15.4 + - 15.3 + - 15.2 + - 15.1 + - "15.0" + - 14 + - 14.11 + - 14.10 + - 14.9 + - 14.8 + - 14.7 + - 14.6 + - 14.5 + - 14.4 + - 14.3 + - 14.2 + - 14.1 + - "14.0" + - 13 + - 13.14 + - 12 + - 12.18 + steps: + - uses: actions/checkout@v3 + + - uses: docker/setup-qemu-action@v2 + + - uses: docker/setup-buildx-action@v2 + + - name: "Setup: Login to Docker Hub" + if: ${{ env.should_push }} + uses: docker/login-action@v3 + with: + username: matthewbaggett + password: ${{ secrets.DOCKER_HUB_PASSWORD }} + + - name: "Setup: Login to GHCR" + if: ${{ env.should_push }} + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: matthewbaggett + password: ${{ secrets.GHCR_PASSWORD }} + + - uses: docker/build-push-action@v4 + name: Build & Push + with: + context: postgres + platforms: ${{ env.ACT && 'linux/amd64' || 'linux/amd64,linux/arm64' }} + pull: true + push: ${{ env.should_push }} + tags: | + benzine/postgres:${{ matrix.version }} + ghcr.io/benzine-framework/postgres:${{ matrix.version }} + build-contexts: | + postgres:injected-version=docker-image://postgres:${{ matrix.version }} diff --git a/postgres/Dockerfile b/postgres/Dockerfile new file mode 100644 index 0000000..076dd31 --- /dev/null +++ b/postgres/Dockerfile @@ -0,0 +1,13 @@ +FROM postgres:injected-version + +LABEL maintainer="Matthew Baggett " \ + org.label-schema.vcs-url="https://github.com/benzine-framework/docker" \ + org.opencontainers.image.source="https://github.com/benzine-framework/docker" + +# Add healthcheck script +COPY postgres_healthcheck.sh /usr/local/bin/postgres_healthcheck +RUN chmod +x /usr/local/bin/postgres_healthcheck + +# Add healthcheck +HEALTHCHECK --start-period=30s --interval=10s --timeout=30s --retries=3 \ + CMD ["/usr/local/bin/postgres_healthcheck"] diff --git a/postgres/postgres_healthcheck.sh b/postgres/postgres_healthcheck.sh new file mode 100755 index 0000000..de4a464 --- /dev/null +++ b/postgres/postgres_healthcheck.sh @@ -0,0 +1,2 @@ +#!/bin/bash +PG_PASSWORD=$POSTGRES_PASSWORD pg_isready -U "$POSTGRES_USER"