diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e46a084 --- /dev/null +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/app/config/db.config.js b/app/config/db.config.js index 64ba9c5..acabbf1 100644 --- a/app/config/db.config.js +++ b/app/config/db.config.js @@ -1,7 +1,8 @@ module.exports = { - HOST: "localhost", + HOST: "db", USER: "postgres", - PASSWORD: "123", + PASSWORD: "postgres", + PORT: "5432", DB: "testdb", dialect: "postgres", pool: { diff --git a/app/models/index.js b/app/models/index.js index 02c3c9e..4177381 100644 --- a/app/models/index.js +++ b/app/models/index.js @@ -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, diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..e3681d1 --- /dev/null +++ b/docker-compose.yml @@ -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 + + \ No newline at end of file