sef-global / scholarx-backend

This is the backend of the ScholarX
MIT License
8 stars 32 forks source link

Dockerize the Application #84

Closed mayura-andrew closed 6 months ago

mayura-andrew commented 6 months ago

Description: In order to simplify the setup process and make our application more portable, I propose we dockerize our application. This will allow any developer to run our application in a Docker container with minimal setup, regardless of their operating system. Tasks:

  1. Create a Dockerfile for our Node.js application.
  2. Ensure the Dockerfile correctly installs all dependencies, copies our source code, and starts our application.
  3. Create a docker-compose.yml file for our services, including database configuration. Update the README with instructions on how to build and run the Docker image.

Dockerfile

# Use an official Node.js runtime as the base image
FROM node:18

# Set the working directory in the Docker container to /app
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install any needed packages specified in package.json
RUN npm install

# Bundle the app source inside the Docker image 
COPY . .

# Make port 8080 available to the world outside this container
EXPOSE 8080

# Run the app when the container launches
CMD [ "npm", "start" ]

docker-compoer.yml

version: '3'
services:
  app:
    build: .
    ports:
      - "${SERVER_PORT}:3000"
    depends_on:
      - db
    environment:
      - DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}
      - JWT_SECRET=${JWT_SECRET}
  db:
    image: postgres:13
    environment:
      - POSTGRES_USER=${DB_USER}
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=${DB_NAME}

Please let me know your thoughts on this proposal.