Skip to content

Commit

Permalink
ci: Deploy via Docker
Browse files Browse the repository at this point in the history
* created api.Dockerfile for the fox-deck-api
* created app.Dockerfile for the fox-deck-app
* create docker-compose.yml for connecting both apps via network
* use 'bcryptjs' instead of 'bcrypt'
  • Loading branch information
Eric-Schubert authored and Dominique Börner committed Mar 8, 2024
1 parent ca37316 commit 394a694
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 2 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 10 additions & 0 deletions api.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:20.11.1-alpine3.19 as api-stage
WORKDIR /usr/src/app
COPY apps/fox-deck-api/package*.json ./
RUN npm ci --prefer-offline --no-audit --progress=false
COPY apps/fox-deck-api/ .
COPY apps/fox-deck-api/.env.example /usr/src/app/.env
RUN npm rebuild # Rebuilds all native dependencies, used because we use c++ libraries
RUN npm run prisma:migrate
EXPOSE 3000
CMD ["npm", "run", "start:dev"]
11 changes: 11 additions & 0 deletions app.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:20.11.1-alpine3.19 as build-stage
WORKDIR /app
COPY apps/fox-deck-app/package*.json ./
RUN npm install --prefer-offline --no-audit --progress=false
COPY apps/fox-deck-app/ .
RUN npm run build
FROM nginx:alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY apps/fox-deck-app/nginx.conf /etc/nginx/conf.d/
EXPOSE 80
6 changes: 6 additions & 0 deletions apps/fox-deck-api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/fox-deck-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.1.15",
"@prisma/client": "^5.5.2",
"bcrypt": "^5.1.1",
"bcryptjs": "^2.4.3",
"better-sqlite3": "^9.4.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
Expand Down
2 changes: 1 addition & 1 deletion apps/fox-deck-api/src/shared/services/password.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from "@nestjs/common";
import * as bcrypt from "bcrypt";
import * as bcrypt from "bcryptjs";

/**
* Services which handles password generation and validation.
Expand Down
17 changes: 17 additions & 0 deletions apps/fox-deck-app/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server {
listen 80;

location /api/ {
proxy_pass http://fox-deck-api:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}

location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
}
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.8'

services:
fox-deck-app:
build:
context: .
dockerfile: app.Dockerfile
ports:
- "80:80"
fox-deck-api:
build:
context: .
dockerfile: api.Dockerfile
ports:
- "3000:3000"

0 comments on commit 394a694

Please sign in to comment.