Skip to content

Commit

Permalink
Issue#974 in talawa-api (Docker for Easy Local Devlopment) (Palisadoe…
Browse files Browse the repository at this point in the history
…sFoundation#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
  • Loading branch information
vasujain275 authored Nov 17, 2023
1 parent 1b48583 commit b781dbe
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 19 deletions.
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:lts

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 4000

CMD ["npm", "run", "dev"]
41 changes: 34 additions & 7 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ This document provides instructions on how to set up and start a running instanc

<!-- TOC -->

- [Talawa-API Installation](#talawa-api-installation)
- [Table of Contents](#table-of-contents)
- [Installation](#installation)
- [Install node.js](#install-nodejs)
- [Install git](#install-git)
- [Setting up this repository](#setting-up-this-repository)

- [Prerequisites](#prerequisites)
- [Install Node.js](#install-nodejs)
- [Install Git](#install-git)
- [Setting Up This Repository](#setting-up-this-repository)
- [Install the Required Packages](#install-the-required-packages)
- [Installation with Docker](#installation-using-docker)
- [Installation without Docker](#installation-without-docker)
- [Install MongoDB](#install-mongodb)
- [Setting up the mongoDB database](#setting-up-the-mongodb-database)
- [Install Redis](#install-redis)
Expand Down Expand Up @@ -69,7 +70,7 @@ This document provides instructions on how to set up and start a running instanc

<!-- /TOC -->

# Installation
# Prerequisites

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

Expand Down Expand Up @@ -109,6 +110,32 @@ Install the packages required by `talawa-api` using this command:
npm install
```

# Installation with Docker

> - **Requires Docker and Docker Compose to be installed**
> - Will start a local mongodb and redis instances
It's important to configure Talawa-API to complete it's setup.

You can use our interactive setup script for the configuration. Use the following command for the same.

```
npm run setup
```

It can be done manually as well and here's how to do it. - [The .env Configuration File](#the-env-configuration-file)

Now use the following command to run docker containers -

```sh
docker compose up
```
OR
```sh
docker-compose up
```
# Installation without Docker

## Install MongoDB

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.
Expand Down
30 changes: 30 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
mongodb:
image: mongo:latest
ports:
- 27017:27017
volumes:
- mongodb-data:/data/db

redis-stack-server:
image: redis/redis-stack-server:latest
ports:
- 6379:6379
volumes:
- redis-data:/data/redis

talawa-api-container:
build: .
ports:
- 4000:4000
depends_on:
- mongodb
- redis-stack-server
environment:
- MONGO_DB_URL=mongodb://mongodb:27017
- REDIS_HOST=redis-stack-server
- REDIS_PORT=6379

volumes:
mongodb-data:
redis-data:
31 changes: 19 additions & 12 deletions setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,29 @@ async function main(): Promise<void> {

accessAndRefreshTokens(accessToken, refreshToken);

if (process.env.MONGO_DB_URL) {
console.log(
`\nMongoDB URL already exists with the value:\n${process.env.MONGO_DB_URL}`
);
}
const { shouldSetMongoDb } = await inquirer.prompt({
const { isDockerInstallation } = await inquirer.prompt({
type: "confirm",
name: "shouldSetMongoDb",
message: "Would you like to set up a MongoDB URL?",
default: true,
name: "isDockerInstallation",
message: "Are you setting up this project using Docker?",
default: false,
});
if (!isDockerInstallation) {
if (process.env.MONGO_DB_URL) {
console.log(
`\nMongoDB URL already exists with the value:\n${process.env.MONGO_DB_URL}`
);
}
const { shouldSetMongoDb } = await inquirer.prompt({
type: "confirm",
name: "shouldSetMongoDb",
message: "Would you like to set up a MongoDB URL?",
default: true,
});

if (shouldSetMongoDb) {
await mongoDB();
if (shouldSetMongoDb) {
await mongoDB();
}
}

if (process.env.RECAPTCHA_SECRET_KEY) {
console.log(
`\nreCAPTCHA secret key already exists with the value ${process.env.RECAPTCHA_SECRET_KEY}`
Expand Down

0 comments on commit b781dbe

Please sign in to comment.