Skip to content

Commit

Permalink
Add dockerfiles and docker-compose config (aerabi#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
steve192 authored Oct 13, 2022
1 parent 7f0ef26 commit dc7b4a7
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 2 deletions.
2 changes: 2 additions & 0 deletions backend/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PORT=8000
MONGODB_URI=mongodb://db:27017
2 changes: 0 additions & 2 deletions backend/.env.test

This file was deleted.

28 changes: 28 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Builder container to compile typescript
FROM node:lts-alpine AS build
WORKDIR /usr/src/app

# Install dependencies
COPY package.json .
COPY package-lock.json .
RUN npm ci

# Copy the application source
COPY . .
# Build typescript
RUN npm run build



FROM node:lts-alpine
WORKDIR /app
COPY package.json .
COPY package-lock.json .
COPY .env.production .env

RUN npm ci --production

COPY --from=build /usr/src/app/dist /app

EXPOSE 8000
CMD [ "node", "index.js"]
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
frontend:
build:
context: "./frontend/events"
dockerfile: "./Dockerfile"
backend:
build:
context: "./backend"
dockerfile: "./Dockerfile"
db:
image: mongo:latest
ports:
- 27017:27017
proxy:
image: nginx:stable-alpine
environment:
- NGINX_ENVSUBST_TEMPLATE_SUFFIX=.conf
- NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx
volumes:
- ${PWD}/nginx.conf:/etc/nginx/templates/nginx.conf.conf
ports:
- 80:80
22 changes: 22 additions & 0 deletions frontend/events/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Builder container to compile typescript
FROM node:lts-alpine AS build
WORKDIR /usr/src/app

# Install dependencies
COPY package.json .
COPY package-lock.json .
RUN npm ci

# Copy the application source
COPY . .
# Build typescript
RUN npm run build



FROM nginx:stable-alpine

COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist/events /usr/share/nginx/html

EXPOSE 80
13 changes: 13 additions & 0 deletions frontend/events/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
events{}
http {
include /etc/nginx/mime.types;
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
}
34 changes: 34 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log debug;

events {}
http {
server {
listen 80;
location / {
# Route frontend stuff
error_page 404 /;
proxy_intercept_errors on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_pass http://frontend:80/;
}
location ~ ^/(api) {
# Route api requests to api server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
include uwsgi_params;
proxy_pass http://backend:8000;
}
}
}

0 comments on commit dc7b4a7

Please sign in to comment.