build: Dockerfile + docker-compose with ports driven by .env

- web: nginx:alpine serving the static SPA, listens on WEB_CONTAINER_PORT
  rendered from deploy/nginx.conf.template (envsubst), gzip + cache headers,
  /healthz, proxies /api/ to the api container
- api: julia:1.13-bookworm, libpq5 + curl, Pkg.instantiate from the committed
  Manifest, listens on FARM_API_PORT, healthcheck on /api/v1/health
- db: postgres:17-alpine with 001_init.sql mounted for first-run schema,
  pg_isready healthcheck, named volume
- every port comes from .env (container port + host port separated);
  .env.example committed, .env ignored
This commit is contained in:
Bkk1234 committed 2026-11-23 01:56:39 +07:00
1 parent 05fd682e33
commit af19d04496
8 files changed
+297

No files matched your search

+73
View File
@@ -0,0 +1,73 @@
# nginx config ของ farm-planning (ถูก envsubst ตอน start)
# ตัวแปรที่ใช้: ${WEB_CONTAINER_PORT} ${API_CONTAINER_PORT}
# หมายเหตุ: official nginx image แทนค่าเฉพาะ env var ที่มีอยู่จริง — $uri/$host ไม่ถูกแตะ
server {
listen ${WEB_CONTAINER_PORT};
listen [::]:${WEB_CONTAINER_PORT};
server_name _;
root /app;
index index.html;
charset utf-8;
gzip on;
gzip_comp_level 6;
gzip_min_length 1024;
gzip_proxied any;
gzip_types text/plain text/css application/javascript application/json
image/svg+xml application/manifest+json;
# ---- health ----
location = /healthz {
access_log off;
add_header Content-Type text/plain always;
return 200 "ok\n";
}
# ---- API (proxy ไปคอนเทนเนอร์ api) ----
location /api/ {
proxy_pass http://api:${API_CONTAINER_PORT};
proxy_http_version 1.1;
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_connect_timeout 5s;
proxy_read_timeout 30s;
add_header Cache-Control "no-store" always;
}
# ---- ไฟล์ที่ต้องได้ของใหม่ทุกครั้ง (SW, version, shell) ----
location = /sw.js {
add_header Cache-Control "no-cache, must-revalidate" always;
try_files $uri =404;
}
location = /app/version.json {
add_header Cache-Control "no-cache, must-revalidate" always;
try_files $uri =404;
}
location = /index.html {
add_header Cache-Control "no-cache, must-revalidate" always;
}
# ---- JSON ข้อมูล: ให้ cache สั้น ๆ (stale-while-revalidate ที่ฝั่ง SW อยู่แล้ว) ----
location /data/ {
expires 5m;
add_header Cache-Control "public, max-age=300" always;
try_files $uri =404;
}
# ---- asset: cache ยาว ----
location ~* \.(css|js|png|jpe?g|gif|svg|ico|woff2?|webp)$ {
expires 30d;
add_header Cache-Control "public, max-age=2592000, immutable" always;
try_files $uri =404;
}
# ---- SPA (hash router): ทุก path ที่ไม่ใช่ไฟล์ ให้ส่ง index.html ----
location / {
add_header Cache-Control "no-cache, must-revalidate" always;
try_files $uri $uri/ /index.html;
}
}