From a808fe0c294b78c245d76ea8e1ad0433c9c454e8 Mon Sep 17 00:00:00 2001 From: Matt Cruz Date: Thu, 28 Nov 2024 17:34:12 -0500 Subject: [PATCH] troubleshoot --- .github/workflows/test.yml | 117 +++++++++++++++++++++++++++---------- 1 file changed, 87 insertions(+), 30 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7b7dfed..702854f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,13 +4,38 @@ on: pull_request: branches: - main - push: - branches: - - main - - add-ci-tests + # push: + # branches: + # - main + # - add-ci-tests jobs: - prebuild: + export_variables: + runs-on: ubuntu-latest + + outputs: + primary_image: ${{ steps.compute_container_registry_name.outputs.CR_NAME }}/postgres_primary:${{ steps.calculate_primary_sha.outputs.PRIMARY_SHA }} + 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@v2 + + - 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_primary.dockerfile + id: calculate_primary_sha + run: echo "PRIMARY_SHA=$(sha256sum postgres_primary.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $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_primary: + needs: export_variables runs-on: ubuntu-latest steps: @@ -24,39 +49,48 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Calculate SHA256 for postgres_primary.dockerfile - run: echo "PRIMARY_SHA=$(sha256sum postgres_primary.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_ENV + - name: Build and tag primary Docker image + run: docker build -f postgres_primary.dockerfile -t ${{ needs.export_variables.outputs.primary_image }} . - - name: Calculate SHA256 for postgres_replica.dockerfile - run: echo "REPLICA_SHA=$(sha256sum postgres_replica.dockerfile | awk '{ print substr($1, 1, 12) }')" >> $GITHUB_ENV + - name: Push primary Docker image + run: docker push ${{ needs.export_variables.outputs.primary_image }} - - name: Compute container registry name - run: echo "CR_NAME=$(echo ghcr.io/${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + prebuild_replica: + needs: export_variables + runs-on: ubuntu-latest - - name: Build and tag primary Docker image - run: docker build -f postgres_primary.dockerfile -t $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }} . + steps: + - name: Checkout repository + uses: actions/checkout@v2 - - name: Build and tag replica Docker image - run: docker build -f postgres_replica.dockerfile -t $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }} . + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Push primary Docker image - run: docker push $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }} + - 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 $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }} + run: docker push ${{ needs.export_variables.outputs.replica_image }} rspec: - needs: prebuild + needs: [export_variables, prebuild_primary, prebuild_replica] runs-on: ubuntu-latest + strategy: matrix: - ruby: [3.1.6, 3.2.5, 3.3.5] - rails: ['~> 7.0.0', '7.1.0', '8.0.0'] + # ruby: [3.2.5, 3.3.5] + # rails: ['~> 7.0.0', '~> 7.1.0', '~> 8.0.0'] + ruby: [3.2.5] + rails: ['~> 7.0.0'] name: Ruby ${{ matrix.ruby }} / ActiveRecord ${{ matrix.rails }} services: postgres_primary: - image: $CR_NAME/postgres_primary:${{ env.PRIMARY_SHA }} + image: ${{ needs.export_variables.outputs.primary_image }} ports: - 5432:5432 env: @@ -65,16 +99,33 @@ jobs: POSTGRES_PASSWORD: postgres_primary_test POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5" POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256" + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 postgres_replica: - image: $CR_NAME/postgres_replica:${{ env.REPLICA_SHA }} + image: ${{ needs.export_variables.outputs.primary_image }} + # image: ${{ needs.export_variables.outputs.replica_image }} ports: - 5433:5432 env: - PGUSER: replicator - PGPASSWORD: replicator - PGPORT: 5433 - PRIMARY_DATABASE_HOST: postgres_primary + # PGUSER: replicator + # PGPASSWORD: replicator + # PGPORT: 5433 + # PRIMARY_DATABASE_HOST: postgres_primary + # PRIMARY_DATABASE_PORT: 5432 + POSTGRES_DB: postgres_primary_test + POSTGRES_USER: postgres_primary_test + POSTGRES_PASSWORD: postgres_primary_test + POSTGRES_HOST_AUTH_METHOD: "scram-sha-256\nhost replication all 0.0.0.0/0 md5" + POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256" + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 steps: - name: Checkout repository @@ -83,7 +134,14 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby: ${{ matrix.ruby }} + ruby-version: ${{ matrix.ruby }} + + - name: Check if primary is available + run: pg_isready -h localhost -U postgres_primary_test --dbname=postgres -p 5432 + + - name: Check if replica is available + # run: pg_isready -h localhost -U replicator --dbname=postgres -p 5433 + run: pg_isready -h localhost -U postgres_primary_test --dbname=postgres -p 5433 - name: Install dependencies env: @@ -94,14 +152,13 @@ jobs: - name: Run RSpec tests env: - PGHOST: postgres_primary PG_PRIMARY_USER: postgres_primary_test PG_PRIMARY_PASSWORD: postgres_primary_test PG_PRIMARY_HOST: postgres_primary PG_PRIMARY_PORT: 5432 PG_REPLICA_USER: postgres_primary_test PG_REPLICA_PASSWORD: postgres_primary_test - PG_REPLICA_HOST: postgres-replica + PG_REPLICA_HOST: postgres_replica PG_REPLICA_PORT: 5433 run: bundle exec rspec --format progress