Skip to content

Commit

Permalink
Merge pull request #1202 from PokeAPI/db-cicd
Browse files Browse the repository at this point in the history
test db dump and restore
  • Loading branch information
Naramsim authored Feb 14, 2025
2 parents e00f125 + 63d4c09 commit 3f27daa
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Database

on:
pull_request:

jobs:
sqlite:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Start pokeapi
run: |
make install
make migrate
make build-db
nohup make serve &
sleep 3
- name: Dump DB
run: stat db.sqlite3
- name: Test data
run: curl -Ss http://localhost:8000/api/v2/pokemon/1/ | grep -q 'bulbasaur'
postgres:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build
run: |
docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
make docker-migrate
make docker-build-db
- name: Dump DB
run: docker compose exec -T -u postgres db sh -c "cd /tmp && pg_dump -h localhost -Fc -U ash -N 'hdb_*' pokeapi > pokeapi.dump"
- name: Copy dump
run: docker compose cp db:/tmp/pokeapi.dump ./
- name: Down services
run: docker compose -f docker-compose.yml -f docker-compose-dev.yml down -v
- name: Start services
run: docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
- name: Import database
run: |
docker compose cp ./pokeapi.dump db:/tmp/
docker compose exec -T -u postgres db sh -c "cd /tmp && pg_restore -h localhost -U ash -d pokeapi pokeapi.dump"
- name: Test data
run: curl -Ss http://localhost/api/v2/pokemon/1/ | grep -q 'bulbasaur'
2 changes: 1 addition & 1 deletion .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Push Docker image
name: Publish

on:
push:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-k8s.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Docker, Compose and k8s
name: Container

on:
pull_request:
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,31 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build
- name: Start pokeapi (docker)
run: |
docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
make docker-migrate
make docker-build-db
- name: Dump DB
run: docker compose exec -T -u postgres db sh -c "cd /tmp && pg_dump -h localhost -Fc -U ash pokeapi | gzip > pokeapi.dump.zip"
- name: Copy dump
- name: Dump PG db
run: docker compose exec -T -u postgres db sh -c "cd /tmp && pg_dump -h localhost -Fc -U ash -N 'hdb_*' pokeapi > pokeapi.pgdump"
- name: Copy PG dump
run: |
docker compose cp db:/tmp/pokeapi.dump.zip ./
docker compose cp db:/tmp/pokeapi.pgdump ./
ls -larth
- name: Start pokeapi
run: |
make install
make migrate
make build-db
nohup make serve &
sleep 3
- name: Release
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
fail_on_unmatched_files: true
files: pokeapi.dump.zip
files: |
pokeapi.pgdump
db.sqlite3
generate_release_notes: true
12 changes: 5 additions & 7 deletions Resources/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ http {

resolver 127.0.0.11 valid=30s;

upstream graphql_upstream {
server graphql-engine:8080 fail_timeout=0;
}

geo $limit {
default 1;
10.0.0.0/8 0;
Expand Down Expand Up @@ -95,7 +91,8 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://graphql_upstream/;
set $upstream_graphql graphql;
proxy_pass http://$upstream_graphql:8080/;
}

location /graphql/console {
Expand All @@ -105,7 +102,7 @@ http {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
set $upstream_graphiql graphiql;
set $upstream_graphiql graphql-engine;
proxy_pass http://$upstream_graphiql:80/;
}

Expand All @@ -126,7 +123,8 @@ http {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://graphql_upstream/v1/graphql;
set $upstream_graphql graphql;
proxy_pass http://$upstream_graphql:8080/v1/graphql;
}

location /api/ {
Expand Down

0 comments on commit 3f27daa

Please sign in to comment.