Skip to content

Commit

Permalink
Add migration before init app in Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
n0str committed Oct 19, 2023
1 parent 4285165 commit 30d1b21
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
!package.json
!package-lock.json
!tsconfig.json
!migrations
!init.sh

# Ignore unnecessary files inside allowed directories
**/*~
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ COPY --from=builder /app/dist ./dist
COPY package.json package-lock.json ./
RUN npm install
COPY ./app-config.yaml .
COPY ./migrations ./migrations
COPY ./init.sh .

USER node
ENV NODE_ENV="production"
CMD ["node", "dist/index.js"]

CMD ["/bin/sh", "init.sh"]
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ services:
postgres:
image: postgres
environment:
POSTGRES_DB: codex-notes
POSTGRES_PASSWORD: example
ports:
- 127.0.0.1:5432:5432
Expand Down
4 changes: 4 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
set -e
npm run migrate
node dist/index.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"dev": "nodemon --watch './src/**/*.ts' --ext ts --exec 'npm run start:dev'",
"start": "node dist/index.js -c app-config.yaml -c app-config.local.yaml",
"start:dev": "npm run build && node dist/index.js -c app-config.yaml -c app-config.local.yaml",
"migrate": "node --loader ts-node/esm ./src/repository/storage/postgres/migrations/index.ts -c app-config.local.yaml",
"migrate": "node --loader ts-node/esm dist/repository/storage/postgres/migrations/index.js -c app-config.yaml -c app-config.yaml",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"test": "vitest",
Expand Down

0 comments on commit 30d1b21

Please sign in to comment.