diff --git a/backend/.env.production b/backend/.env.production new file mode 100644 index 0000000..7c95d9d --- /dev/null +++ b/backend/.env.production @@ -0,0 +1,2 @@ +PORT=8000 +MONGODB_URI=mongodb://db:27017 diff --git a/backend/.env.test b/backend/.env.test deleted file mode 100644 index 9f63692..0000000 --- a/backend/.env.test +++ /dev/null @@ -1,2 +0,0 @@ -PORT=8000 -MONGODB_URI=mongodb://localhost:27017 diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..0e05edf --- /dev/null +++ b/backend/Dockerfile @@ -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"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..da535dd --- /dev/null +++ b/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/frontend/events/Dockerfile b/frontend/events/Dockerfile new file mode 100644 index 0000000..12c2225 --- /dev/null +++ b/frontend/events/Dockerfile @@ -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 diff --git a/frontend/events/nginx.conf b/frontend/events/nginx.conf new file mode 100644 index 0000000..ade6ad1 --- /dev/null +++ b/frontend/events/nginx.conf @@ -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; + } + } +} \ No newline at end of file diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..cd8c1a7 --- /dev/null +++ b/nginx.conf @@ -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; + } + } +} \ No newline at end of file