Skip to content

Commit 4fcf3a1

Browse files
committed
Migrate postgres job to not use Docker
Context: - With the Docker config we hit a memory limit in Github actions - This alternative approach uses "bare metal" and still works
1 parent 93568a6 commit 4fcf3a1

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

.github/workflows/database.yml

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
name: Database
2+
# These workflows are intended to check that various actions related to the database
3+
# (such as building, exporting, and importing) work as expected.
24

35
on:
46
pull_request:
@@ -52,29 +54,50 @@ jobs:
5254
run: curl -Ss http://localhost:8000/api/v2/pokemon/1/ | grep -q 'bulbasaur'
5355
postgres:
5456
runs-on: ubuntu-latest
57+
services:
58+
postgres:
59+
image: postgres:16
60+
env:
61+
POSTGRES_USER: pokeapi
62+
POSTGRES_PASSWORD: pokeapi
63+
POSTGRES_DB: pokeapi
64+
options: >-
65+
--health-cmd pg_isready
66+
--health-interval 10s
67+
--health-timeout 5s
68+
--health-retries 5
69+
ports:
70+
- 5432:5432
5571
steps:
5672
- name: Checkout
5773
uses: actions/checkout@v5
5874
with:
5975
submodules: recursive
6076
- name: Install uv
6177
uses: astral-sh/setup-uv@v7
62-
- name: Build
63-
run: |
64-
docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
65-
make docker-migrate
66-
make docker-build-db
78+
- name: Install dependencies
79+
run: make install
80+
- name: Run migrations
81+
run: uv run manage.py migrate --settings=config.local
82+
- name: Build database
83+
run: uv run manage.py shell --settings=config.local -c "from data.v2.build import build_all; build_all(); exit()"
6784
- name: Dump DB
68-
run: docker compose exec -T -u postgres db sh -c "cd /tmp && pg_dump -h localhost -Fc -U ash -N 'hdb_*' pokeapi > pokeapi.dump"
69-
- name: Copy dump
70-
run: docker compose cp db:/tmp/pokeapi.dump ./
71-
- name: Down services
72-
run: docker compose -f docker-compose.yml -f docker-compose-dev.yml down -v
73-
- name: Start services
74-
run: docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
85+
run: pg_dump -h localhost -U pokeapi -Fc -N 'hdb_*' pokeapi > pokeapi.dump
86+
env:
87+
PGPASSWORD: pokeapi
88+
- name: Drop and recreate database
89+
run: |
90+
psql -h localhost -U pokeapi -d postgres -c "DROP DATABASE pokeapi;"
91+
psql -h localhost -U pokeapi -d postgres -c "CREATE DATABASE pokeapi;"
92+
env:
93+
PGPASSWORD: pokeapi
7594
- name: Import database
95+
run: pg_restore -h localhost -U pokeapi -d pokeapi pokeapi.dump
96+
env:
97+
PGPASSWORD: pokeapi
98+
- name: Start server
7699
run: |
77-
docker compose cp ./pokeapi.dump db:/tmp/
78-
docker compose exec -T -u postgres db sh -c "cd /tmp && pg_restore -h localhost -U ash -d pokeapi pokeapi.dump"
100+
nohup uv run manage.py runserver 0.0.0.0:8000 --settings=config.local &
101+
sleep 5
79102
- name: Test data
80-
run: curl -Ss http://localhost/api/v2/pokemon/1/ | grep -q 'bulbasaur'
103+
run: curl -Ss http://localhost:8000/api/v2/pokemon/1/ | grep -q 'bulbasaur'

0 commit comments

Comments
 (0)