From ce673531b12d082350a4996f4ed54a84ac007e3c Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 27 Oct 2020 15:42:10 +0300 Subject: build: add docker configs --- .dockerignore | 1 + Dockerfile | 13 +++++++++++++ docker-compose.yml | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bcb00cc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM node:12 + +WORKDIR /app + +COPY package*.json ./ + +RUN npm install + +COPY . . + +EXPOSE 3030 + +CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..392d48a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: '3' +services: + app: + container_name: which-api + restart: always + build: . + ports: + - '3030:3030' + links: + - db + db: + container_name: mongo + image: mongo -- cgit v1.2.3 From c24ff8d26b916b1340cdaf1f1c33c314a6d4a23e Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 27 Oct 2020 15:47:51 +0300 Subject: build: add MONGODB_URI to Dockerfile --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index bcb00cc..aeafcc9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,8 @@ RUN npm install COPY . . +ENV MONGODB_URI=mongodb://db:27017/which + EXPOSE 3030 CMD ["npm", "start"] -- cgit v1.2.3 From 1b48b401ad64f0b8994338fd88dad78d78be3bf0 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 27 Oct 2020 15:50:04 +0300 Subject: build: expose 27017 port on Mongo --- docker-compose.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 392d48a..1894901 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,3 +11,5 @@ services: db: container_name: mongo image: mongo + ports: + - '27017:27017' -- cgit v1.2.3 From 59bb116afd8d2be1cdd4ccf45a646d58eabab357 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 7 Nov 2020 12:27:41 +0300 Subject: feat: add MONGODB_USER and MONGODB_PASSWORD vars --- index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index e2146cd..eec102d 100644 --- a/index.ts +++ b/index.ts @@ -6,10 +6,13 @@ import app from './app'; mongoose.Promise = Promise; -const MONGODB_URL = process.env.MONGODB_URI || 'mongodb://localhost:27017/which'; const PORT = process.env.PORT || 3030; +const MONGODB_URL = process.env.MONGODB_URI || 'mongodb://localhost:27017/which'; +const { MONGODB_USER, MONGODB_PASSWORD } = process.env; mongoose.connect(MONGODB_URL, { + user: MONGODB_USER, + pass: MONGODB_PASSWORD, useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true, -- cgit v1.2.3 From a5feeaaca74d82a99bbb8063afee51cb9984f978 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 7 Nov 2020 12:36:39 +0300 Subject: feat: provide local MONGODB_URI in correct step --- Dockerfile | 4 ++-- docker-compose.yml | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index aeafcc9..892c159 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,5 @@ +# Dockerfile to build which-api image + FROM node:12 WORKDIR /app @@ -8,8 +10,6 @@ RUN npm install COPY . . -ENV MONGODB_URI=mongodb://db:27017/which - EXPOSE 3030 CMD ["npm", "start"] diff --git a/docker-compose.yml b/docker-compose.yml index 1894901..f163ecd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,16 @@ +# Build and run which-api with database in container +# +# If you are getting "port already in use" error, +# try changing exposed ports, e.g 27017:27017 -> 27018:27017 + version: '3' services: app: container_name: which-api restart: always build: . + environment: + - MONGODB_URI=mongodb://db:27017/which ports: - '3030:3030' links: -- cgit v1.2.3 From aaf784ab9fe5894c18493f116c6599faf3c92895 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 7 Nov 2020 12:54:09 +0300 Subject: docs: update development and deployment sections --- README.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 47ef59c..70145eb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,29 @@ Track our progress - [KANBAN board](https://github.com/orgs/which-ecosystem/proj ### Building and running + +#### Running in Docker :whale: +You only need to have `Docker` and `docker-compose` installed for this step. +Turn off Mongo service to avoid port conflicts (container also exposes port 2707). +``` +docker-compose up +``` +This will build and run `which-api` container along with linked `mongo` container. + + +#### For local development :construction: +You need to have Mongo running at port 27017. ``` -ts-node populateDb.ts -ts-node-dev index.ts +npm install +npm start ``` + + +## Deployment :rocket: +Despite having Docker setup, `which-api` is currently deployed to [Heroku](https://dashboard.heroku.com/), +and MongoDB is located in [Mongo Atlas](https://www.mongodb.com/cloud/atlas). + +**API BASE URL**: https://which-api.herokuapp.com/ + +**MONGODB_URI**: mongodb+srv://cluster0.iayve.mongodb.net/which + -- cgit v1.2.3