Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerized the application. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:12
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8080

ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.2.1/wait /wait
RUN chmod +x /wait

## Launch the wait tool and then your application
CMD /wait && npm start
# CMD [ "node", "server"]
5 changes: 3 additions & 2 deletions app/config/db.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
module.exports = {
HOST: "localhost",
HOST: "db",
USER: "postgres",
PASSWORD: "123",
PASSWORD: "postgres",
PORT: "5432",
DB: "testdb",
dialect: "postgres",
pool: {
Expand Down
2 changes: 1 addition & 1 deletion app/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Sequelize = require("sequelize");
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
host: dbConfig.HOST,
dialect: dbConfig.dialect,

port: dbConfig.PORT,
pool: {
max: dbConfig.pool.max,
min: dbConfig.pool.min,
Expand Down
28 changes: 28 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "3.7"
services:
node_backend:
container_name: "node_backend"
build: .
environment:
WAIT_HOSTS: db:5432
ports:
- "8080:8080"
depends_on:
- db

db:
image: "postgres:12"
container_name: "postgres"
ports:
- "5432:5432"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=testdb
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"pg": "^7.17.1",
"pg": "^8.5.1",
"pg-hstore": "^2.3.3",
"sequelize": "^5.21.3"
}
Expand Down