aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.dockerignore1
-rw-r--r--Dockerfile15
-rw-r--r--README.md26
-rw-r--r--docker-compose.yml22
-rw-r--r--index.ts5
5 files changed, 66 insertions, 3 deletions
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..892c159
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,15 @@
+# Dockerfile to build which-api image
+
+FROM node:12
+
+WORKDIR /app
+
+COPY package*.json ./
+
+RUN npm install
+
+COPY . .
+
+EXPOSE 3030
+
+CMD ["npm", "start"]
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
+
diff --git a/docker-compose.yml b/docker-compose.yml
new file mode 100644
index 0000000..f163ecd
--- /dev/null
+++ b/docker-compose.yml
@@ -0,0 +1,22 @@
+# 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:
+ - db
+ db:
+ container_name: mongo
+ image: mongo
+ ports:
+ - '27017:27017'
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,