部署docker化
This commit is contained in:
26
deploy/.env.production.example
Normal file
26
deploy/.env.production.example
Normal file
@@ -0,0 +1,26 @@
|
||||
# Frontend
|
||||
FRONTEND_PORT=8080
|
||||
CONDO_API_BASE_URL=/api
|
||||
CONDO_DEFAULT_MODE=api
|
||||
CONDO_PERIOD_YEAR=
|
||||
|
||||
# Backend
|
||||
NODE_ENV=production
|
||||
LOG_LEVEL=info
|
||||
CORS_ORIGINS=http://localhost:8080
|
||||
AUTH_USERNAME=wyndhamcondon
|
||||
AUTH_PASSWORD=replace-with-test-password
|
||||
AUTH_SESSION_TTL_HOURS=12
|
||||
|
||||
# Set true only when the public frontend is served over HTTPS.
|
||||
AUTH_COOKIE_SECURE=false
|
||||
|
||||
# Existing PostgreSQL. DB_HOST must be reachable from inside the backend container.
|
||||
DB_HOST=replace-with-existing-pg-host
|
||||
DB_PORT=5432
|
||||
DB_USER=replace-with-existing-pg-user
|
||||
DB_PASSWORD=replace-with-existing-pg-password
|
||||
DB_NAME=booking_test
|
||||
DB_SSL=false
|
||||
DB_POOL_MAX=10
|
||||
DB_STATEMENT_TIMEOUT_MS=15000
|
||||
34
deploy/frontend-entrypoint.sh
Normal file
34
deploy/frontend-entrypoint.sh
Normal file
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
runtime_config_path="/usr/share/nginx/html/runtime-config.js"
|
||||
default_mode="${CONDO_DEFAULT_MODE:-api}"
|
||||
api_base_url="${CONDO_API_BASE_URL:-/api}"
|
||||
period_year="${CONDO_PERIOD_YEAR:-}"
|
||||
|
||||
escape_js_string() {
|
||||
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
|
||||
}
|
||||
|
||||
case "$period_year" in
|
||||
"" )
|
||||
period_year_expression="new Date().getUTCFullYear()"
|
||||
;;
|
||||
*[!0-9]* )
|
||||
period_year_expression="new Date().getUTCFullYear()"
|
||||
;;
|
||||
* )
|
||||
period_year_expression="$period_year"
|
||||
;;
|
||||
esac
|
||||
|
||||
default_mode_escaped="$(escape_js_string "$default_mode")"
|
||||
api_base_url_escaped="$(escape_js_string "$api_base_url")"
|
||||
|
||||
cat > "$runtime_config_path" <<EOF
|
||||
window.CONDO_RUNTIME_CONFIG = Object.freeze({
|
||||
defaultMode: "$default_mode_escaped",
|
||||
apiBaseUrl: "$api_base_url_escaped",
|
||||
periodYear: $period_year_expression
|
||||
});
|
||||
EOF
|
||||
35
deploy/nginx.conf
Normal file
35
deploy/nginx.conf
Normal file
@@ -0,0 +1,35 @@
|
||||
upstream condo_backend {
|
||||
server backend:3000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
location = /api {
|
||||
return 308 /api/;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
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_set_header Connection "";
|
||||
proxy_pass http://condo_backend/;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location ~* \.(?:css|js|svg)$ {
|
||||
expires 1h;
|
||||
add_header Cache-Control "public";
|
||||
try_files $uri =404;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user