Skip to content

Commit b781dbe

Browse files
authored
Issue#974 in talawa-api (Docker for Easy Local Devlopment) (PalisadoesFoundation#1418)
* feat: Dockerfile and docker-compose.yaml created * Added env vars to compose file and modified setup.ts for docker-compose * Added Docker Installation Steps to Documentation * Updated Table of Contents for INSTALLATION.md * docs: made a separate section for docker installation * refactor: Skips MonogoURL Setup if docker installation in setup.ts * refactor: Changed node:19 to node:lts in Dockerfile
1 parent 1b48583 commit b781dbe

File tree

4 files changed

+96
-19
lines changed

4 files changed

+96
-19
lines changed

Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:lts
2+
3+
WORKDIR /usr/src/app
4+
5+
COPY package*.json ./
6+
7+
RUN npm install
8+
9+
COPY . .
10+
11+
EXPOSE 4000
12+
13+
CMD ["npm", "run", "dev"]

INSTALLATION.md

+34-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ This document provides instructions on how to set up and start a running instanc
66

77
<!-- TOC -->
88

9-
- [Talawa-API Installation](#talawa-api-installation)
10-
- [Table of Contents](#table-of-contents)
11-
- [Installation](#installation)
12-
- [Install node.js](#install-nodejs)
13-
- [Install git](#install-git)
14-
- [Setting up this repository](#setting-up-this-repository)
9+
10+
- [Prerequisites](#prerequisites)
11+
- [Install Node.js](#install-nodejs)
12+
- [Install Git](#install-git)
13+
- [Setting Up This Repository](#setting-up-this-repository)
1514
- [Install the Required Packages](#install-the-required-packages)
15+
- [Installation with Docker](#installation-using-docker)
16+
- [Installation without Docker](#installation-without-docker)
1617
- [Install MongoDB](#install-mongodb)
1718
- [Setting up the mongoDB database](#setting-up-the-mongodb-database)
1819
- [Install Redis](#install-redis)
@@ -69,7 +70,7 @@ This document provides instructions on how to set up and start a running instanc
6970

7071
<!-- /TOC -->
7172

72-
# Installation
73+
# Prerequisites
7374

7475
You will need to have copies of your code on your local system. Here's how to do that.
7576

@@ -109,6 +110,32 @@ Install the packages required by `talawa-api` using this command:
109110
npm install
110111
```
111112

113+
# Installation with Docker
114+
115+
> - **Requires Docker and Docker Compose to be installed**
116+
> - Will start a local mongodb and redis instances
117+
118+
It's important to configure Talawa-API to complete it's setup.
119+
120+
You can use our interactive setup script for the configuration. Use the following command for the same.
121+
122+
```
123+
npm run setup
124+
```
125+
126+
It can be done manually as well and here's how to do it. - [The .env Configuration File](#the-env-configuration-file)
127+
128+
Now use the following command to run docker containers -
129+
130+
```sh
131+
docker compose up
132+
```
133+
OR
134+
```sh
135+
docker-compose up
136+
```
137+
# Installation without Docker
138+
112139
## Install MongoDB
113140

114141
Talawa-api makes use of `MongoDB` for its database needs. We make use of `mongoose ODM` to interact with the MongoDB database from within the code.

docker-compose.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
services:
2+
mongodb:
3+
image: mongo:latest
4+
ports:
5+
- 27017:27017
6+
volumes:
7+
- mongodb-data:/data/db
8+
9+
redis-stack-server:
10+
image: redis/redis-stack-server:latest
11+
ports:
12+
- 6379:6379
13+
volumes:
14+
- redis-data:/data/redis
15+
16+
talawa-api-container:
17+
build: .
18+
ports:
19+
- 4000:4000
20+
depends_on:
21+
- mongodb
22+
- redis-stack-server
23+
environment:
24+
- MONGO_DB_URL=mongodb://mongodb:27017
25+
- REDIS_HOST=redis-stack-server
26+
- REDIS_PORT=6379
27+
28+
volumes:
29+
mongodb-data:
30+
redis-data:

setup.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -311,22 +311,29 @@ async function main(): Promise<void> {
311311

312312
accessAndRefreshTokens(accessToken, refreshToken);
313313

314-
if (process.env.MONGO_DB_URL) {
315-
console.log(
316-
`\nMongoDB URL already exists with the value:\n${process.env.MONGO_DB_URL}`
317-
);
318-
}
319-
const { shouldSetMongoDb } = await inquirer.prompt({
314+
const { isDockerInstallation } = await inquirer.prompt({
320315
type: "confirm",
321-
name: "shouldSetMongoDb",
322-
message: "Would you like to set up a MongoDB URL?",
323-
default: true,
316+
name: "isDockerInstallation",
317+
message: "Are you setting up this project using Docker?",
318+
default: false,
324319
});
320+
if (!isDockerInstallation) {
321+
if (process.env.MONGO_DB_URL) {
322+
console.log(
323+
`\nMongoDB URL already exists with the value:\n${process.env.MONGO_DB_URL}`
324+
);
325+
}
326+
const { shouldSetMongoDb } = await inquirer.prompt({
327+
type: "confirm",
328+
name: "shouldSetMongoDb",
329+
message: "Would you like to set up a MongoDB URL?",
330+
default: true,
331+
});
325332

326-
if (shouldSetMongoDb) {
327-
await mongoDB();
333+
if (shouldSetMongoDb) {
334+
await mongoDB();
335+
}
328336
}
329-
330337
if (process.env.RECAPTCHA_SECRET_KEY) {
331338
console.log(
332339
`\nreCAPTCHA secret key already exists with the value ${process.env.RECAPTCHA_SECRET_KEY}`

0 commit comments

Comments
 (0)