forked from prasadhonrao/devcamper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request prasadhonrao#14 from prasadhonrao/feature/dockeriz…
…e-api Create Dockerfile and docker compose files to dockerize and deploy th…
- Loading branch information
Showing
8 changed files
with
216 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
"cSpell.words": [ | ||
"bootcamp", | ||
"bootcamps", | ||
"devcamper", | ||
"dsphere", | ||
"Geocoder", | ||
"mapquest", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
node_modules | ||
npm-debug.log | ||
Dockerfile | ||
.dockerignore | ||
docker-compose.yml | ||
.git | ||
.gitignore | ||
_postman | ||
tests | ||
eslint.config.js | ||
README.md | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Use the official Node.js image as the base image | ||
FROM node:20 | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /usr/src/app | ||
|
||
# Copy package.json and package-lock.json to the working directory | ||
COPY package*.json ./ | ||
|
||
# Install dependencies | ||
RUN npm install | ||
|
||
# Copy the rest of the application code to the working directory | ||
COPY . . | ||
|
||
# Expose the port the app runs on | ||
EXPOSE 3000 | ||
|
||
# Define the command to run the application | ||
CMD ["npm", "start"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,134 @@ | ||
# MERN Bootcamp API | ||
# DevCamper API | ||
|
||
## Description | ||
## Overview | ||
|
||
This is the API for the MERN Bootcamp project. It is a RESTful API that provides endpoints for the MERN Bootcamp project. | ||
The DevCamper API is a backend service for managing bootcamp-related data, including courses, reviews, and user authentication. This documentation provides detailed instructions for setting up the API in both local and production environments. | ||
|
||
<!-- TODO: Add documentation --> | ||
## Table of Contents | ||
|
||
- [Prerequisites](#prerequisites) | ||
- [Setup Geocoding Service](#setup-geocoding-service) | ||
- [Setup SMTP Service (Local Setup)](#setup-smtp-service) | ||
- [Setup Postman](#setup-postman) | ||
- [Local Setup](#local-setup) | ||
- [Install NodeJs](#install-nodejs) | ||
- [Install MongoDB](#install-mongodb) | ||
- [Setup Environment Variables](#setup-environment-variables) | ||
- [Seed the Database](#seed-the-database) | ||
- [Validate the Data in MongoDB Compass](#validate-the-data-in-mongodb-compass) | ||
- [Running the API](#running-the-api) | ||
- [Cleanup the Database](#cleanup-the-database) | ||
|
||
## Prerequisites | ||
|
||
Before setting up the DevCamper API, you need to sign up for the following services and obtain the necessary API keys and credentials. You would also need to install Postman client for testing. | ||
|
||
### Setup Geocoding Service | ||
|
||
1. Sign up for a free account on [MapQuest](https://developer.mapquest.com/). | ||
2. Create a new application to get an API key. | ||
|
||
### Setup SMTP Service | ||
|
||
1. Sign up for a free account on [Mailtrap](https://mailtrap.io/). | ||
2. Create a new inbox to get SMTP credentials. | ||
|
||
### Setup Postman | ||
|
||
1. Download and install [Postman](https://www.postman.com/downloads/). | ||
2. Import the Postman collection provided in the `postman` directory. | ||
|
||
## Local Setup | ||
|
||
### Install NodeJs | ||
|
||
1. Download and install Node.js from the [official website](https://nodejs.org/). | ||
|
||
### Install MongoDB | ||
|
||
1. Install MongoDB in local environment using one of the following options: | ||
|
||
- [MongoDB Community Server](https://www.mongodb.com/try/download/community) | ||
- [Docker](https://docs.docker.com/get-docker/) | ||
|
||
- Run the following command to start a MongoDB container: | ||
|
||
```bash | ||
docker run -d -p 27017:27017 --name devcamper-mongo mongo | ||
``` | ||
|
||
2. Download and install [MongoDB Compass](https://www.mongodb.com/try/download/compass) for a graphical user interface to interact with the database. | ||
3. Connect to the MongoDB server using the following connection string: | ||
|
||
```plaintext | ||
mongodb://localhost:27017 | ||
``` | ||
|
||
4. Create a new database named `devcamper-db`. | ||
|
||
### Setup Environment Variables | ||
|
||
Create a `.env` file in the root of your project directory and configure the following environment variables. Replace the placeholder values with your own credentials and API keys obtained from earlier steps. | ||
|
||
```plaintext | ||
PORT=6000 | ||
NODE_ENV=development | ||
MONGO_URI=mongodb://localhost:27017/devcamper-db | ||
GEOCODER_PROVIDER=mapquest | ||
GEOCODER_API_KEY=your_mapquest_api_key | ||
FILE_UPLOAD_PATH=./public/uploads | ||
MAX_FILE_UPLOAD=1000000 | ||
JWT_SECRET=your_jwt_secret | ||
JWT_EXPIRE=30d | ||
JWT_COOKIE_EXPIRE=30 | ||
SMTP_HOST=your_smtp_host | ||
SMTP_PORT=your_smtp_port | ||
SMTP_EMAIL=your_smtp_email | ||
SMTP_PASSWORD=your_smtp_password | ||
FROM_EMAIL=your_from_email | ||
FROM_NAME=your_from_name | ||
RATE_LIMIT_MAX=100 | ||
RATE_LIMIT_WINDOW_MS=60000 | ||
``` | ||
|
||
### Seed the Database | ||
|
||
Run the following command to seed the database with bootcamps, courses, and users. | ||
|
||
```bash | ||
node run data:import | ||
``` | ||
|
||
### Validate the Data in MongoDB Compass | ||
|
||
1. Open MongoDB Compass and connect | ||
2. Select the `devcamper-db` database | ||
3. Verify that the `bootcamps`, `courses`, and `users` collections have been created and populated with data. | ||
|
||
### Running the API | ||
|
||
1. Install dependencies: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
2. Start the API server: | ||
|
||
```bash | ||
npm run dev | ||
``` | ||
|
||
3. Use the Postman collection provided in the `postman` directory to interact with the API. | ||
|
||
4. Make sure that the environment is set to development in Postman. | ||
|
||
5. Test the API endpoints to verify that the API is working as expected. | ||
|
||
### Cleanup the Database | ||
|
||
Run the following command to delete all data from the database. This will remove all bootcamps, courses, and users. | ||
|
||
```bash | ||
node run data:delete | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
version: '3.8' | ||
|
||
services: | ||
api: | ||
image: prasadhonrao/devcamper-api:latest | ||
ports: | ||
- '${PORT}:${PORT}' | ||
environment: | ||
- PORT=${PORT} | ||
- NODE_ENV=${NODE_ENV} | ||
- MONGO_URI=${MONGO_URI} | ||
- GEOCODER_PROVIDER=${GEOCODER_PROVIDER} | ||
- GEOCODER_API_KEY=${GEOCODER_API_KEY} | ||
- FILE_UPLOAD_PATH=${FILE_UPLOAD_PATH} | ||
- MAX_FILE_UPLOAD=${MAX_FILE_UPLOAD} | ||
- JWT_SECRET=${JWT_SECRET} | ||
- JWT_EXPIRE=${JWT_EXPIRE} | ||
- JWT_COOKIE_EXPIRE=${JWT_COOKIE_EXPIRE} | ||
- SMTP_HOST=${SMTP_HOST} | ||
- SMTP_PORT=${SMTP_PORT} | ||
- SMTP_EMAIL=${SMTP_EMAIL} | ||
- SMTP_PASSWORD=${SMTP_PASSWORD} | ||
- FROM_EMAIL=${FROM_EMAIL} | ||
- FROM_NAME=${FROM_NAME} | ||
- RATE_LIMIT_MAX=${RATE_LIMIT_MAX} | ||
- RATE_LIMIT_WINDOW_MS=${RATE_LIMIT_WINDOW_MS} | ||
depends_on: | ||
- mongo | ||
|
||
mongo: | ||
image: mongo:latest | ||
ports: | ||
- '27017:27017' | ||
volumes: | ||
- mongo-data:/data/db | ||
|
||
volumes: | ||
mongo-data: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters