Skip to content

Commit

Permalink
move dump script to compose jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
zach-betz-hln committed Nov 6, 2024
1 parent 0b331bb commit 917666e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.5.0 (2024-11-06)

- Move `task_dump_kc_data.sh` to `compose.jobs.yml`
- Upgrade `postgres` image from `16.2-bookworm` to `16.4-bookworm`
- Specific current dir for `env_file` value, like `./.env`
- Regen dump files in dir `db/init`

## 1.4.0 (2024-11-06)

- Upgrade Keycloak to 26.0.5
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ I've copied the request _query params_ and _form data_ directly from DevTools fo

The `db/init` folder contains SQL which is copied into the Postgres image and runs on container startup.

I didn't write this SQL by hand. Instead, I customized the `master` realm a tad, then dumped the data. See script `task_dump_kc_data.sh`
I didn't write this SQL by hand. Instead, I customized the `master` realm a tad, then dumped the data. See `compose.jobs.yml`

### Clients

Expand Down Expand Up @@ -356,6 +356,10 @@ This repo originally lived at [zach-betz-hln/mre-keycloak-react](https://github.
1. Create a branch from `main`, or a fork of this repo
1. Make your changes
1. Run through the _Setup_ steps in this doc from scratch and confirm everything works
1. Run the dump job

docker compose -f compose.yml -f compose.jobs.yml run dump

1. Increment the [semantic version](https://docs.npmjs.com/about-semantic-versioning). `<semver>` should be one of: `major` | `minor` | `patch`

npm --no-git-tag-version version <semver>
Expand Down
21 changes: 21 additions & 0 deletions compose.jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
services:
dump:
image: postgres:16.4-bookworm
shm_size: 128mb
env_file:
- ./.env
environment:
- PGHOST=${KC_DB_URL_HOST}
- PGPORT=${KC_DB_URL_PORT}
- PGDATABASE=${KC_DB_URL_DATABASE}
- PGUSER=${KC_DB_USERNAME}
- PGPASSWORD=${KC_DB_PASSWORD}
volumes:
- ./db/init:/db/init
command: >
sh -c '
echo "Dumping schema..." &&
pg_dump --schema-only --file /db/init/01-dump-schema-only.sql &&
echo "Dumping data..." &&
pg_dump --data-only --file /db/init/02-dump-data-only.sql
'
10 changes: 5 additions & 5 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
ports:
- 5432:5432
env_file:
- .env
- ./.env

kc:
depends_on:
Expand All @@ -16,7 +16,7 @@ services:
ports:
- ${KC_HTTP_PORT}:${KC_HTTP_PORT}
env_file:
- .env
- ./.env

mailhog:
depends_on:
Expand All @@ -26,7 +26,7 @@ services:
ports:
- ${MH_UI_BIND_ADDR_PORT}:${MH_UI_BIND_ADDR_PORT}
env_file:
- .env
- ./.env

api:
depends_on:
Expand All @@ -36,7 +36,7 @@ services:
ports:
- ${API_PORT}:${API_PORT}
env_file:
- .env
- ./.env

react:
depends_on:
Expand All @@ -47,6 +47,6 @@ services:
ports:
- ${VITE_PORT}:${VITE_PORT}
env_file:
- .env
- ./.env
volumes:
- ./react/src:/app/src:rw
2 changes: 1 addition & 1 deletion db/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FROM postgres:16.2-bookworm
FROM postgres:16.4-bookworm
COPY init/*.sql /docker-entrypoint-initdb.d/
4 changes: 2 additions & 2 deletions db/init/01-dump-schema-only.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 16.2 (Debian 16.2-1.pgdg120+2)
-- Dumped by pg_dump version 16.1
-- Dumped from database version 16.4 (Debian 16.4-1.pgdg120+2)
-- Dumped by pg_dump version 16.4 (Debian 16.4-1.pgdg120+2)

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down
4 changes: 2 additions & 2 deletions db/init/02-dump-data-only.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 16.2 (Debian 16.2-1.pgdg120+2)
-- Dumped by pg_dump version 16.1
-- Dumped from database version 16.4 (Debian 16.4-1.pgdg120+2)
-- Dumped by pg_dump version 16.4 (Debian 16.4-1.pgdg120+2)

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.4.0",
"version": "1.5.0",
"scripts": {
"toc": "markdown-toc -i README.md"
},
Expand Down
17 changes: 0 additions & 17 deletions task_dump_kc_data.sh

This file was deleted.

0 comments on commit 917666e

Please sign in to comment.