Skip to content

Commit

Permalink
introduce Dockerfile and production image build
Browse files Browse the repository at this point in the history
  • Loading branch information
j33f committed Mar 5, 2021
1 parent 71cc633 commit a90cfbf
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 17 deletions.
15 changes: 13 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea/
/.circleci/
/.nyc_output.func/
/coverage.functional/
Expand All @@ -8,6 +9,7 @@
/.prettierrc
/Dockerfile
/start-dev
/start-uat
/sonar-project.properties
/.eslintrc.json
/start-ci
Expand All @@ -16,6 +18,15 @@
/mongoDump
/.editorconfig
/start-build
/README.md
/fileStorage/
/.git/
/.git/
/features/
/unitTests/
/**/*.test.js
/**/.DS_Store
/.dockerignore
/.mocharc.yml
/node_modules
/**/*.md
/**/.gitkeep
/.yggdrasilrc
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM j33f/node-docker-container
LABEL maintainer="J33f <[email protected]>"

EXPOSE 8842

COPY ./ /var/app
COPY ./docker-compose/config/pm2-prod.json /var/pm2Config/config.json
COPY ./docker-compose/scripts/run-prod.sh /var/startScripts/runCustom.sh
RUN rm -r /var/app/docker-compose

VOLUME /var/app
VOLUME /var/pm2Config
VOLUME /var/startScripts

RUN chmod +x /var/startScripts/runCustom.sh

WORKDIR /var/app
RUN npm install --production

CMD /var/startScripts/runCustom.sh
56 changes: 56 additions & 0 deletions docker-compose/prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: '3'

services:
backend:
build: ..
container_name: backend
volumes:
- ../fileStorage:/var/fileStorage:defered
- ../.yggdrasilrc:/var/app/.yggdrasilrc:defered
cap_add:
- SYS_PTRACE
depends_on:
- redis
- mongo
- mailout
dns:
- 208.67.222.222
- 208.67.220.220
- 8.8.8.8
- 8.8.4.4
ports:
- "8842:8842"
environment:
- NODE_ENV=${NODE_ENV:-production}

redis:
image: redis:alpine
container_name: redis
restart: always

mongo:
image: mongo
container_name: mongo
restart: always
ulimits:
nofile: 65536
memlock:
soft: -1
hard: -1
volumes:
- ../data/mongo:/data/db:cached
- ../data/mongoDumps:/data/dumps:cached
ports:
- "27017:27017"
environment:
- "MONGO_INITDB_ROOT_USERNAME=mongo-admin"
- "MONGO_INITDB_ROOT_PASSWORD=1Lnl4ZEg!gPdF!zGKdILfww"
- "MONGO_INITIDB_DATABASE=admin"

mailout:
image: j33f/alpine-postfix
container_name: mailout
restart: always
environment:
- DOMAIN=nobs-consulting.com
- HOSTNAME=nobs-consulting.com
37 changes: 37 additions & 0 deletions docker-compose/scripts/run-prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

function setup_tz {
apk add --no-cache --no-progress tzdata
cp /usr/share/zoneinfo/${SETUP_TIMEZONE} /etc/localtime
echo "${SETUP_TIMEZONE}" > /etc/timezone
apk del tzdata
echo "Timezone is now set to $(< /etc/timezone)"
}

if [[ -z "${TIMEZONE}" ]]; then
if [ -f /etc/timezone ]; then
echo "Timezone is set to $(cat /etc/timezone)"
else
SETUP_TIMEZONE="$(< /var/app/timeZone)"
echo "Need to setup TZ to ${SETUP_TIMEZONE} (default)"
setup_tz
fi
else
if [ -f /etc/timezone ]; then
echo "Timezone is set to $(cat /etc/timezone)"
if [[ $(< /etc/timezone) != "${TIMEZONE}" ]]; then
SETUP_TIMEZONE="${TIMEZONE}"
echo "Need to change to ${SETUP_TIMEZONE}"
setup_tz
else
echo "No need to change TZ"
fi
else
SETUP_TIMEZONE="${TIMEZONE}"
echo "Need to setup TZ to ${SETUP_TIMEZONE} (custom)"
setup_tz
fi
fi

echo "[$(date)] - Starting..."
exec pm2-runtime /var/pm2Config/config.json --raw
13 changes: 0 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"bluebird": "^3.7.2",
"body-parser": "^1.19.0",
"cookie-parser": "^1.4.5",
"crypto": "^1.0.1",
"dot-object": "^2.1.4",
"express": "^4.17.1",
"express-fileupload": "^1.2.1",
Expand All @@ -65,7 +64,6 @@
"passport-github": "^1.1.0",
"passport-google-oauth2": "^0.2.0",
"rc": "^1.2.8",
"request": "^2.88.2",
"serve-favicon": "^2.5.0",
"socket.io": "^3.1.1",
"socketio-jwt": "^4.6.2",
Expand Down
7 changes: 7 additions & 0 deletions start-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

docker-compose -f docker-compose/prod.yml kill

chmod a+x bin/startServer

exec docker-compose -f docker-compose/prod.yml up --remove-orphans
8 changes: 8 additions & 0 deletions start-uat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

docker-compose -f docker-compose/prod.yml kill

chmod a+x bin/startServer

exec docker-compose -f docker-compose/prod.yml up --remove-orphans

0 comments on commit a90cfbf

Please sign in to comment.