Skip to content

Commit

Permalink
chore: add docker-compose
Browse files Browse the repository at this point in the history
  • Loading branch information
minenwerfer committed Feb 18, 2024
1 parent fc0e034 commit d123ce6
Show file tree
Hide file tree
Showing 12 changed files with 490 additions and 357 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MONGODB_STORAGE=/data/mongodb-test
16 changes: 16 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:20

ARG MONGODB_URL
ENV MONGODB_URL $MONGODB_URL

WORKDIR /opt/application/api
COPY . .

RUN npm install
RUN npm run build

CMD npm run migrate \
&& rm -rf ../api-build/node_modules \
&& cp -r node_modules ../api-build \
&& npm start

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"types": "dist/index.d.ts",
"scripts": {
"build": "sonata-build",
"migrate": "sonata-build -m migrate",
"dev": "sonata-build -w",
"start": "node -r sonata-api/loader ./release/index.js"
},
Expand Down
2 changes: 1 addition & 1 deletion api/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../node_modules/sonata-build/dist/config/tsconfig.json",
"extends": "sonata-build/config/tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"preserveSymlinks": true
Expand Down
52 changes: 52 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
version: '3.8'

services:
mongo:
image: mongo
restart: always
volumes:
- /tmp/mongodb-test:/data/db
- api-build:/opt/application/api-build
ports:
- 27017:27017
logging:
driver: none
network_mode: host

api:
build:
context: api
network: host
args:
MONGODB_URL: mongodb://0.0.0.0:27017/testdb
restart: always
depends_on:
- mongo
volumes:
- api-build:/opt/application/api-build
env_file: api/production.env
network_mode: host

web:
build:
context: web
depends_on:
- api
volumes:
- api-build:/opt/application/api
- web-build:/var/www/html

nginx:
build:
context: nginx
restart: always
depends_on:
- web
volumes:
- web-build:/var/www/html
network_mode: host

volumes:
api-build:
web-build:

6 changes: 6 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx

COPY nginx.conf /etc/nginx/nginx.conf
COPY sites-enabled/ /etc/nginx/sites-enabled

CMD nginx -g 'daemon off;'
20 changes: 20 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
events {}

http {
include /etc/nginx/mime.types;
include /etc/nginx/sites-enabled/*.conf;
client_max_body_size 50m;
proxy_read_timeout 600s;

gzip on;
gzip_min_length 1000;
gzip_comp_level 9;
gzip_types
text/plain
text/html
text/css
application/javascript;

proxy_cache_path /var/nginx-cache keys_zone=static:10m;
}

20 changes: 20 additions & 0 deletions nginx/sites-enabled/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
server {
listen 80;
root /var/www/html;

location ~ ^/(static|assets)/ {
proxy_cache static;
expires 30d;
add_header Cache-Control "public, no-transform";
}

location / {
try_files $uri $uri/ /index.html;
}

location /api {
proxy_pass http://0.0.0.0:3000;
proxy_set_header Host $host;
proxy_cache off;
}
}
Loading

0 comments on commit d123ce6

Please sign in to comment.