Skip to content

Commit e6659d2

Browse files
committed
refactor(database): docker and add init script
1 parent 4d375d2 commit e6659d2

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

apps/database/Dockerfile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
ARG BASE_IMAGE=node:12.18.2-alpine3.11
1+
ARG BASE_IMAGE
22

33
FROM $BASE_IMAGE as base
44

5-
WORKDIR /app
5+
WORKDIR /apps/database
66

7-
CMD yarn start
7+
FROM base as dev
8+
9+
CMD yarn dev
10+
11+
FROM base as production_build
12+
13+
CMD yarn migrate
14+
15+
COPY apps/database/package.json apps/database/yarn.lock /apps/database/
16+
17+
RUN yarn --frozen-lockfile
18+
19+
COPY apps/database/ /apps/database/

apps/database/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
{
22
"private": true,
3+
"engines": {
4+
"node": ">=15.8.0"
5+
},
36
"scripts": {
4-
"start": "graphile-migrate watch",
7+
"dev": "graphile-migrate watch",
58
"commit": "graphile-migrate commit",
6-
"mig-init": "graphile-migrate init"
9+
"mig-init": "graphile-migrate init",
10+
"migrate": "graphile-migrate migrate",
11+
"load": "sh ./mig_data.sh",
12+
"reset": "graphile-migrate reset"
713
},
814
"dependencies": {
915
"graphile-migrate": "^1.0.2"

docker-compose.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ version: "3.7"
33
services:
44
db:
55
image: postgres:13.1-alpine
6+
environment:
7+
POSTGRES_USER: $DATABASE_OWNER
8+
POSTGRES_PASSWORD: $DATABASE_OWNER_PASSWORD
9+
POSTGRES_DB: $DATABASE_NAME
610
env_file:
711
- .env
812
volumes:
@@ -11,17 +15,26 @@ services:
1115
- 5432:5432
1216

1317
migrations:
18+
environment:
19+
ROOT_DATABASE_URL: postgres://$DATABASE_OWNER:$DATABASE_OWNER_PASSWORD@$DATABASE_HOST/template1
20+
DATABASE_URL: postgres://$DATABASE_OWNER:$DATABASE_OWNER_PASSWORD@$DATABASE_HOST/$DATABASE_NAME
21+
SHADOW_DATABASE_URL: postgres://$DATABASE_OWNER:$DATABASE_OWNER_PASSWORD@$DATABASE_HOST/${DATABASE_NAME}_shadow
1422
build:
1523
context: .
1624
dockerfile: apps/database/Dockerfile
25+
target: dev
26+
args:
27+
BASE_IMAGE: ${BASE_IMAGE_NODE_ALPINE}
1728
volumes:
18-
- ./apps/database:/app
29+
- ./apps/database:/apps/database
1930
env_file:
2031
- .env
2132
depends_on:
2233
- db
2334

2435
gql:
36+
environment:
37+
DATABASE_AUTHENTICATOR_URL: postgres://$DATABASE_AUTHENTICATOR:$DATABASE_AUTHENTICATOR_PASSWORD@$$DATABASE_HOST/$DATABASE_NAME
2538
build:
2639
context: .
2740
target: dev

init.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# exit when any command fails
2+
set -e
3+
4+
echo "Bringing down all containers"
5+
docker-compose down --volumes
6+
7+
echo "Building graphql and web containers"
8+
docker-compose build --parallel migrations # gql
9+
10+
echo "Bringing up database, running migrations and loading data"
11+
docker-compose up -d db
12+
docker-compose run --rm --no-deps migrations yarn --frozen-lockfile
13+
docker-compose run --rm --no-deps migrations yarn graphile-migrate reset --erase
14+
docker-compose up -d migrations
15+
#docker-compose run --rm --no-deps migrations yarn load

0 commit comments

Comments
 (0)