diff --git a/.build/prod/app.Dockerfile b/.build/prod/app.Dockerfile new file mode 100644 index 0000000..e20d875 --- /dev/null +++ b/.build/prod/app.Dockerfile @@ -0,0 +1,19 @@ +FROM node:20-slim AS frontendbuilder + +WORKDIR /tmp/frontendbuilder +COPY public/ . +RUN npm ci && npm run build + + +FROM python:3.11.4-slim-buster + +WORKDIR /var/www/html/ +COPY . . + +RUN pip install -r requirements.txt + +COPY --from=frontendbuilder /tmp/frontendbuilder/dist/ /var/www/html/public + +VOLUME /var/www/html/public + +CMD uvicorn app.main:app --host 0.0.0.0 --port 8000 diff --git a/.build/prod/compose.yml b/.build/prod/compose.yml new file mode 100644 index 0000000..d4e8f5b --- /dev/null +++ b/.build/prod/compose.yml @@ -0,0 +1,13 @@ +services: + app: + build: + context: ../../ + dockerfile: .build/prod/app.Dockerfile + hostname: mapmaker + image: git.shihaam.dev/sarlink/mapmaker/api + nginx: + build: + context: . + dockerfile: ./nginx.Dockerfile + hostname: mapmaker-nginx + image: git.shihaam.dev/sarlink/mapmaker/nginx diff --git a/.build/prod/nginx.conf b/.build/prod/nginx.conf index ae4aad4..bee1617 100644 --- a/.build/prod/nginx.conf +++ b/.build/prod/nginx.conf @@ -6,7 +6,7 @@ server { error_log /dev/stdout info; location /api/ { - proxy_pass http://api:8000/api/; + proxy_pass http://mapmaker:8000/api/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; @@ -15,7 +15,7 @@ server { } location /ws/ { - proxy_pass http://api:8000/ws/; + proxy_pass http://mapmaker:8000/ws/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; @@ -23,22 +23,19 @@ server { 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; - - # WebSocket timeout settings proxy_read_timeout 86400s; proxy_send_timeout 86400s; proxy_connect_timeout 60s; } location / { - # In development, proxy to Vite dev server - proxy_pass http://node:3000; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - 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; + root /var/www/html/public; + try_files $uri $uri/ /index.html; + + # Cache static assets + location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { + expires 1y; + add_header Cache-Control "public, immutable"; + } } } diff --git a/.build/prod/node.Dockerfile b/.build/prod/node.Dockerfile deleted file mode 100644 index 4e42054..0000000 --- a/.build/prod/node.Dockerfile +++ /dev/null @@ -1,5 +0,0 @@ -FROM node:24-bookworm-slim - -WORKDIR /var/www/html/public - -CMD npm run dev -- --host 0.0.0.0 diff --git a/.build/prod/python.Dockerfile b/.build/prod/python.Dockerfile deleted file mode 100644 index 74798ca..0000000 --- a/.build/prod/python.Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM python:3.11.4-slim-buster - -WORKDIR /var/www/html/ - -COPY requirements.txt . - -RUN pip install -r requirements.txt