Skip to content

Commit

Permalink
(BE) Dockerize the Backend (#94)
Browse files Browse the repository at this point in the history
* Add dockerfile

* Create docker-compose-full.yml

* Update .env

* Update .dockerignore
  • Loading branch information
devleejb authored Jan 23, 2024
1 parent 1b085a9 commit 0adc83f
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
8 changes: 8 additions & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Dockerfile
.dockerignore
node_modules
dist
.env
.env.*
README.md
docker
7 changes: 6 additions & 1 deletion backend/.env
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
DATABASE_URL="mongodb://localhost:27017/codepair"
DATABASE_URL=""
GITHUB_CLIENT_ID=""
GITHUB_CLIENT_SECRET=""
GITHUB_CLIENT_CALLBACK_URL=""
JWT_AUTH_SECRET=""
FRONTEND_BASE_URL=""
16 changes: 16 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:18-slim AS builder
WORKDIR /app
COPY . .
# Dependency for Prisma
RUN apt-get update -y && apt-get install -y openssl
RUN npm ci
RUN npm run build

FROM node:18-slim
WORKDIR /app
ENV NODE_ENV production
COPY --from=builder /app ./
# Dependency for Prisma
RUN apt-get update -y && apt-get install -y openssl
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
41 changes: 41 additions & 0 deletions backend/docker/docker-compose-full.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: "3.8"

services:
codepair-backend:
build:
context: ../
environment:
DATABASE_URL: "mongodb://mongo:27017/codepair"
# Environment variables need to be passed to the container
GITHUB_CLIENT_ID: "GITHUB_CLIENT_ID"
GITHUB_CLIENT_SECRET: "GITHUB_CLIENT_SECRET"
GITHUB_CLIENT_CALLBACK_URL: "GITHUB_CLIENT_CALLBACK_URL"
JWT_AUTH_SECRET: "JWT_AUTH_SECRET"
FRONTEND_BASE_URL: "FRONTEND_BASE_URL"
ports:
- "3000:3000"
depends_on:
- mongo
restart: unless-stopped
links:
- "mongo:mongo"

mongo:
build:
context: ./mongodb_replica
args:
MONGO_VERSION: 4
environment:
MONGO_REPLICA_HOST: "mongo"
MONGO_REPLICA_PORT: 27017
MONGO_INITDB_DATABASE: "codepair"
MONGO_COMMAND: "mongo"
ports:
- "27017:27017"
restart: unless-stopped
healthcheck:
test:
["CMD", "mongo", "admin", "--port", "27017", "--eval", "db.adminCommand('ping').ok"]
interval: 5s
timeout: 2s
retries: 20
16 changes: 16 additions & 0 deletions backend/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.8"

services:
codepair-backend:
build:
context: ../
environment:
DATABASE_URL: "DATABASE_URL"
GITHUB_CLIENT_ID: "GITHUB_CLIENT_ID"
GITHUB_CLIENT_SECRET: "GITHUB_CLIENT_SECRET"
GITHUB_CLIENT_CALLBACK_URL: "<BACKEND_BASE_URL>/auth/login/github"
JWT_AUTH_SECRET: "JWT_AUTH_SECRET"
FRONTEND_BASE_URL: "FRONTEND_BASE_URL"
ports:
- "3000:3000"
restart: unless-stopped

0 comments on commit 0adc83f

Please sign in to comment.