Skip to content

Commit

Permalink
fix: docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaspearson committed Mar 2, 2022
1 parent 5bca62f commit 025f068
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ TYPEORM_DATABASE=express
TYPEORM_CONNECTION_NAME=default
TYPEORM_SCHEMA=public
TYPEORM_PASSWORD=masterkey
TYPEORM_USERNAME=master
TYPEORM_USERNAME=admin
2 changes: 1 addition & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
env:
POSTGRES_DB: express
POSTGRES_PASSWORD: masterkey
POSTGRES_USER: master
POSTGRES_USER: admin
ports:
- 5432:5432
options: " --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10 "
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.github/workflows
*.spec.ts.snap
.pnp.js
.pnp.cjs
.yarn
build
package.json
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ FROM node:16-alpine

WORKDIR /usr/src/app

COPY --chown=node:node --from=builder /usr/src/app/.pnp.js ./.pnp.js
COPY --chown=node:node --from=builder /usr/src/app/.yarn ./.yarn
COPY --chown=node:node --from=builder /usr/src/app/.pnp.cjs ./.pnp.cjs
COPY --chown=node:node --from=builder /usr/src/app/.pnp.loader.mjs ./.pnp.loader.mjs
COPY --chown=node:node --from=builder /usr/src/app/.yarn/cache ./.yarn/cache
COPY --chown=node:node --from=builder /usr/src/app/.yarn/plugins ./.yarn/plugins
COPY --chown=node:node --from=builder /usr/src/app/.yarn/releases ./.yarn/releases
COPY --chown=node:node --from=builder /usr/src/app/.yarnrc.yml ./.yarnrc.yml
COPY --chown=node:node --from=builder /usr/src/app/logs ./logs
COPY --chown=node:node --from=builder /usr/src/app/ormconfig.json ./ormconfig.json
COPY --chown=node:node --from=builder /usr/src/app/package.json ./package.json
COPY --chown=node:node --from=builder /usr/src/app/yarn.lock ./yarn.lock

COPY --chown=node:node --from=builder /usr/src/app/logs ./logs
COPY --chown=node:node --from=builder /usr/src/app/ormconfig.json ./ormconfig.json
COPY --chown=node:node --from=builder /usr/src/app/dist/src ./src

USER node
Expand Down
54 changes: 33 additions & 21 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,49 @@ networks:

services:
api:
image: api:latest
build:
args:
PACKAGE: api
context: .
dockerfile: Dockerfile
container_name: api
depends_on:
- postgres
environment:
- TYPEORM_HOST=postgres
- REDIS_HOST=redis
- REDIS_PORT=6379
env_file:
- .env
expose:
- 3000
image: nicpearson/node.express.starter:1.0.0
networks:
- development
environment:
- TYPEORM_DATABASE=express
- TYPEORM_HOST=db
- TYPEORM_PASSWORD=masterkey
- TYPEORM_PORT=5432
- TYPEORM_SCHEMA=public
- TYPEORM_USERNAME=master
ports:
- 3000:3000
depends_on:
db:
condition: service_healthy
networks:
- development
container_name: api

postgres:
container_name: postgres
#########################
## Persistence ##
#########################

db:
image: postgres:14-alpine
environment:
- POSTGRES_DB=express
- POSTGRES_USER=master
- POSTGRES_PASSWORD=masterkey
expose:
- 5432
hostname: postgres
image: postgres:14
networks:
- development
- POSTGRES_USER=admin
ports:
- 5432:5432
networks:
- development
healthcheck:
test: ['CMD-SHELL', 'pg_isready']
interval: 10s
timeout: 5s
retries: 5
volumes:
- ./scripts/db:/docker-entrypoint-initdb.d
container_name: express-db
2 changes: 1 addition & 1 deletion ormconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "master",
"username": "admin",
"password": "masterkey",
"database": "express",
"entities": ["src/db/entities/*.entity.{js,ts}"],
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
"db:migration:run": "typeorm migration:run",
"db:start": "run exec:docker-compose up -d --renew-anon-volumes --force-recreate postgres",
"debug": "run build && run watch:debug",
"docker:build": "yarn exec:docker-compose build --no-cache api",
"docker:logs": "yarn exec:docker-compose logs -f api",
"docker:start": "yarn exec:docker-compose up -d --build api",
"docker:up": "yarn exec:docker-compose up -d --renew-anon-volumes --wait",
"doctor": "yarn dlx @yarnpkg/doctor .",
"exec:docker-compose": "docker compose -f $(pwd)/docker-compose.yaml",
"exec:jest": "jest --version && jest --coverage --detectOpenHandles --color --forceExit",
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-migration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export TYPEORM_HOST="${TYPEORM_HOST:-localhost}"
export TYPEORM_PASSWORD="${TYPEORM_PASSWORD:-masterkey}"
export TYPEORM_PORT="${TYPEORM_PORT:-5432}"
export TYPEORM_SYNCHRONIZE="${TYPEORM_SYNCHRONIZE:-false}"
export TYPEORM_USERNAME="${TYPEORM_USERNAME:-master}"
export TYPEORM_USERNAME="${TYPEORM_USERNAME:-admin}"
export TYPEORM_SCHEMA="${TYPEORM_SCHEMA:-public}"
export TYPEORM_ENTITIES="${TYPEORM_ENTITIES:-dist/src/db/entities/*.js}"
export TYPEORM_MIGRATIONS="${TYPEORM_MIGRATIONS:-dist/src/db/migrations/*.js}"
Expand Down
2 changes: 1 addition & 1 deletion src/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function getValidationSchema(): Joi.ObjectSchema {
.default(false),
TYPEORM_USERNAME: Joi.string()
.description('The database username to be used by TypeORM')
.example('master')
.example('admin')
.required(),
});
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/.env.integration
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ TYPEORM_DATABASE=express
TYPEORM_CONNECTION_NAME=default
TYPEORM_SCHEMA=public
TYPEORM_PASSWORD=masterkey
TYPEORM_USERNAME=master
TYPEORM_USERNAME=admin
2 changes: 1 addition & 1 deletion test/unit/.env.unit
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ TYPEORM_DATABASE=express
TYPEORM_CONNECTION_NAME=default
TYPEORM_SCHEMA=public
TYPEORM_PASSWORD=masterkey
TYPEORM_USERNAME=master
TYPEORM_USERNAME=admin

0 comments on commit 025f068

Please sign in to comment.