Skip to content

Commit

Permalink
Make ormconfig dynamic to cover prod and dev environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavle Portic committed May 29, 2019
1 parent b8c91e6 commit 1be53fe
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9,614 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ FROM node:lts-alpine

WORKDIR /app

ENV NODE_ENV development
COPY package*.json ./
RUN yarn

RUN npm install
COPY . .

EXPOSE 3000
CMD [ "npm", "run", "start:dev" ]
CMD [ "yarn", "run", "start:dev" ]

9 changes: 5 additions & 4 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ FROM node:lts-alpine as builder

WORKDIR /app

ENV NODE_ENV production
COPY package*.json /app/
RUN set -x && npm install
RUN set -x && yarn

COPY . /app
COPY ormconfig.json /app/dist
RUN set -x && npm run prestart:prod
RUN set -x && yarn run prestart:prod

EXPOSE 3000

CMD [ "npm", "run", "start:prod" ]
CMD [ "node", "dist/main.js" ]

2 changes: 1 addition & 1 deletion docker-compose-swarm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
- NEST_PORT=3000
- NGINX_MAX_BODY=100M
ports:
- 127.0.0.1:80:80
- 80:80

db:
image: mariadb:10
Expand Down
19 changes: 19 additions & 0 deletions ormconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* ormconfig.js
* Copyright (C) 2019 pavle <[email protected]>
*
* Distributed under terms of the BSD-3-Clause license.
*/

const SOURCE_PATH = process.env.NODE_ENV === 'production' ? 'dist' : 'src'

module.exports = {
type: 'mariadb',
host: "db",
port: 3306,
username: "nest",
password: "nest",
database: "nest",
entities: [`${SOURCE_PATH}/**/**.entity{.ts,.js}`],
}

Loading

0 comments on commit 1be53fe

Please sign in to comment.