Skip to content

Commit

Permalink
Add docker configurations for dev and prod environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavle Portic committed May 28, 2019
1 parent 5008ad4 commit b8c91e6
Show file tree
Hide file tree
Showing 10 changed files with 2,095 additions and 2,049 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM node:lts-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install
COPY . .

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

12 changes: 12 additions & 0 deletions Dockerfile-nginx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM nginx:alpine

COPY ./docker/entrypoint-nginx.sh /

RUN set -ex && \
apk add --no-cache bash && \
chmod +x /entrypoint-nginx.sh

COPY ./docker/vhost.template /etc/nginx/conf.d/vhost.template

CMD ["/entrypoint-nginx.sh"]

14 changes: 14 additions & 0 deletions Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM node:lts-alpine as builder

WORKDIR /app

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

EXPOSE 3000

CMD [ "npm", "run", "start:prod" ]

46 changes: 46 additions & 0 deletions docker-compose-swarm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: "3"
services:
nest:
image: nest
deploy:
replicas: 1
restart_policy:
condition: on-failure
volumes:
- .env:/app/.env
depends_on:
- db

nginx:
image: nginx
deploy:
replicas: 1
restart_policy:
condition: on-failure
depends_on:
- nest
environment:
- NGINX_SERVER_NAME=_
- NEST_HOST=nest
- NEST_PORT=3000
- NGINX_MAX_BODY=100M
ports:
- 127.0.0.1:80:80

db:
image: mariadb:10
deploy:
replicas: 1
restart_policy:
condition: on-failure
environment:
MYSQL_DATABASE: nest
MYSQL_USER: nest
MYSQL_PASSWORD: nest
MYSQL_ROOT_PASSWORD: root
volumes:
- mariadbdata:/var/lib/mysql

volumes:
mariadbdata:

43 changes: 43 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: "2"
services:
nest:
build: .
container_name: nest
depends_on:
- db
volumes:
- ./src:/app/src
- .env:/app/.env
- ./ormconfig.json:/app/ormconfig.json

nginx:
build:
context: .
dockerfile: Dockerfile-nginx
container_name: nest-nginx
depends_on:
- nest
environment:
- NGINX_SERVER_NAME=localhost
- NEST_HOST=nest
- NEST_PORT=3000
- NGINX_MAX_BODY=100M
ports:
- 80:80

db:
image: mariadb:10
container_name: nest-db
environment:
MYSQL_DATABASE: nest
MYSQL_USER: nest
MYSQL_PASSWORD: nest
MYSQL_ROOT_PASSWORD: root
ports:
- 3306:3306
volumes:
- mariadbdata:/var/lib/mysql

volumes:
mariadbdata:

7 changes: 7 additions & 0 deletions docker/entrypoint-nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

vars=$(compgen -A variable)
subst=$(printf '${%s} ' $vars)
envsubst "$subst" < /etc/nginx/conf.d/vhost.template > /etc/nginx/conf.d/default.conf
nginx -g 'daemon off;'

19 changes: 19 additions & 0 deletions docker/vhost.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# vim: ft=nginx

server {
listen 80;
server_name ${NGINX_SERVER_NAME};
root /app/public;
client_max_body_size ${NGINX_MAX_BODY};

location / {
# try_files $uri =404;
proxy_pass http://${NEST_HOST}:${NEST_PORT};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto https;
}
}

15 changes: 9 additions & 6 deletions ormconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"type": "sqlite",
"database": "./sqlite-example.sql",
"entities": [
"src/**/**.entity{.ts,.js}"
],
"type": "mariadb",
"host": "db",
"port": 3306,
"username": "nest",
"password": "nest",
"database": "nest",
"entities": ["src/modules/**/*.entity{.ts,.js}"],
"synchronize": true
}
}

Loading

0 comments on commit b8c91e6

Please sign in to comment.