Skip to content

Commit

Permalink
Use github actions service for postgres in CI
Browse files Browse the repository at this point in the history
Previously the CI runs would start the postgres service inside of the
container doing tests. This would result in intermittent failures when
postgres wasn't able to start up. Now a service container is used for
postgres as described in
https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers
  • Loading branch information
nick-mobilecoin committed Dec 11, 2023
1 parent fae6dca commit 8db9a67
Showing 1 changed file with 65 additions and 15 deletions.
80 changes: 65 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,18 @@ jobs:
NUM_RUNNERS: ${{ matrix.num_runners }}
RUNNER_INDEX: ${{ matrix.runner_index }}

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -258,8 +270,6 @@ jobs:
then
echo '-p mc-util-keyfile -p mc-util-generate-sample-ledger' >> /tmp/fog-test-packages
fi
- name: Start postgres
run: service postgresql start
- name: Run tests
uses: ./.github/actions/run-mc-tests
with:
Expand All @@ -270,20 +280,30 @@ jobs:
env:
# TEST_DATABASE_URL points at the server, as Fog recovery DB tests
# create and drop PG databases.
TEST_DATABASE_URL: postgres://localhost
TEST_DATABASE_URL: postgres://postgres:postgres@postgres


fog-ingest-tests:
runs-on: [self-hosted, Linux, large]
container: mobilecoin/builder-install:v0.0.32

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Setup Rust
uses: ./.github/actions/setup-rust
- name: Start postgres
run: service postgresql start
- name: Run tests
uses: ./.github/actions/run-mc-tests
with:
Expand All @@ -293,13 +313,25 @@ jobs:
env:
# TEST_DATABASE_URL points at the server, as Fog recovery DB tests
# create and drop PG databases.
TEST_DATABASE_URL: postgres://localhost
TEST_DATABASE_URL: postgres://postgres:postgres@postgres


fog-conformance-tests:
runs-on: [self-hosted, Linux, large]
container: mobilecoin/builder-install:v0.0.32

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out code
uses: actions/checkout@v4
Expand All @@ -320,13 +352,12 @@ jobs:
pip install -r requirements.txt
./build.sh
service postgresql start
- name: fog_conformance_tests.py
working-directory: tools/fog-local-network
env:
# TEST_DATABASE_URL points at the server, as Fog recovery DB tests
# create and drop PG databases.
TEST_DATABASE_URL: postgres://localhost
TEST_DATABASE_URL: postgres://postgres:postgres@postgres
run: |
. ./env/bin/activate
python3 fog_conformance_tests.py --release
Expand All @@ -340,6 +371,18 @@ jobs:
runs-on: [self-hosted, Linux, large]
container: mobilecoin/builder-install:v0.0.32

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down Expand Up @@ -397,12 +440,11 @@ jobs:
# Generate sample Fog keys.
"$BIN_DIR/sample-keys" --num 4 --output-dir fog_keys --fog-report-url 'insecure-fog://localhost:6200' --fog-authority-root "$FOG_AUTHORITY_ROOT"
service postgresql start
- name: Run local network
env:
# TEST_DATABASE_URL points at the server, as Fog recovery DB tests
# create and drop PG databases.
TEST_DATABASE_URL: postgres://localhost
TEST_DATABASE_URL: postgres://postgres:postgres@postgres
run: |
BIN_DIR="$PWD/target/release"
SCRIPT_DIR="$PWD/tools/fog-local-network"
Expand Down Expand Up @@ -527,6 +569,18 @@ jobs:
runs-on: [self-hosted, Linux, large]
container: mobilecoin/builder-install:v0.0.32

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down Expand Up @@ -584,12 +638,11 @@ jobs:
# Generate sample Fog keys.
"$BIN_DIR/sample-keys" --num 4 --output-dir fog_keys --fog-report-url 'insecure-fog://localhost:6200' --fog-authority-root "$FOG_AUTHORITY_ROOT"
service postgresql start
- name: Run local network
env:
# TEST_DATABASE_URL points at the server, as Fog recovery DB tests
# create and drop PG databases.
TEST_DATABASE_URL: postgres://localhost
TEST_DATABASE_URL: postgres://postgres:postgres@postgres
run: |
BIN_DIR="$PWD/target/release"
SCRIPT_DIR="$PWD/tools/fog-local-network"
Expand Down Expand Up @@ -664,10 +717,7 @@ jobs:
runs-on: [self-hosted, Linux, small]
if: success() || failure()
needs:
- mc-tests
- consensus-tests
- fog-tests
- fog-ingest-tests
steps:
- name: Download XML reports
if: success() || failure()
Expand Down

0 comments on commit 8db9a67

Please sign in to comment.