From 12180808768337d7ec8e82001c1a1e90fc4e84d4 Mon Sep 17 00:00:00 2001 From: Matt Cruz Date: Fri, 29 Nov 2024 22:31:16 -0500 Subject: [PATCH] Move prebuild of Postgres replica to separate workflow --- .../workflows/prebuild_postgres_replica.yml | 46 +++++++++++++++++++ .github/workflows/test.yml | 23 +--------- postgres_replica.dockerfile | 1 + 3 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/prebuild_postgres_replica.yml diff --git a/.github/workflows/prebuild_postgres_replica.yml b/.github/workflows/prebuild_postgres_replica.yml new file mode 100644 index 0000000..f907cf1 --- /dev/null +++ b/.github/workflows/prebuild_postgres_replica.yml @@ -0,0 +1,46 @@ +name: Build Postgres Replica Image + +on: + pull_request: + paths: + - 'postgres_replica.dockerfile' + +jobs: + export_variables: + runs-on: ubuntu-latest + + outputs: + replica_image: ${{ steps.compute_container_registry_name.outputs.CR_NAME }}/postgres_replica:${{ steps.calculate_replica_sha.outputs.REPLICA_SHA }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Compute container registry name + id: compute_container_registry_name + run: echo "CR_NAME=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT + + - name: Calculate SHA256 for postgres_replica.dockerfile + id: calculate_replica_sha + run: echo "REPLICA_SHA=$(sha256sum postgres_replica.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_OUTPUT + + prebuild_replica: + needs: export_variables + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and tag replica Docker image + run: docker build -f postgres_replica.dockerfile -t ${{ needs.export_variables.outputs.replica_image }} . + + - name: Push replica Docker image + run: docker push ${{ needs.export_variables.outputs.replica_image }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6ccc80..9569020 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,27 +29,6 @@ jobs: id: calculate_replica_sha run: echo "REPLICA_SHA=$(sha256sum postgres_replica.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_OUTPUT - prebuild_replica: - needs: export_variables - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Log in to GitHub Container Registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and tag replica Docker image - run: docker build -f postgres_replica.dockerfile -t ${{ needs.export_variables.outputs.replica_image }} . - - - name: Push replica Docker image - run: docker push ${{ needs.export_variables.outputs.replica_image }} - rubocop: runs-on: ubuntu-latest @@ -70,7 +49,7 @@ jobs: run: bundle exec rubocop rspec: - needs: [export_variables, prebuild_replica] + needs: [export_variables] runs-on: ubuntu-latest strategy: diff --git a/postgres_replica.dockerfile b/postgres_replica.dockerfile index 7b6975e..dd8550b 100644 --- a/postgres_replica.dockerfile +++ b/postgres_replica.dockerfile @@ -7,6 +7,7 @@ ENV PRIMARY_REPLICATION_SLOT=replication_slot USER root RUN printf '' > cmd.sh + RUN echo 'until pg_basebackup --pgdata=/var/lib/postgresql/data -R --slot=$PRIMARY_REPLICATION_SLOT --host=$PRIMARY_DATABASE_HOST --port=$PRIMARY_DATABASE_PORT' >> cmd.sh RUN echo 'do' >> cmd.sh RUN echo "echo 'Waiting for primary to connect...'" >> cmd.sh