initial commit
This commit is contained in:
commit
88c14b627e
224 files changed
+17204
No files matched your search
@@ -0,0 +1,83 @@
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
ROOT := $(abspath ..)
|
||||
DOCKER ?= docker
|
||||
APP_PROJECT ?= app
|
||||
ML_PROJECT ?= ml
|
||||
MONITORING_PROJECT ?= monitoring
|
||||
APP_NETWORK ?= $(APP_PROJECT)_default
|
||||
ENV_FILE ?= $(ROOT)/.env
|
||||
CHECK_ENV_FILE := $(ROOT)/.env.example
|
||||
CORE_FILE := $(ROOT)/deploy/docker/docker-compose.yml
|
||||
ML_FILE := $(ROOT)/deploy/docker/docker-compose.ml.yml
|
||||
MONITORING_FILE := $(ROOT)/deploy/docker/docker-compose.monitoring.yml
|
||||
|
||||
.PHONY: help config build up down logs monitoring-config monitoring-up monitoring-down monitoring-logs ml-config ml-build ml-up ml-down ml-logs check smoke test-e2e
|
||||
|
||||
help: ## Show deployment commands
|
||||
@awk 'BEGIN {FS = ":.*## "} /^[a-zA-Z0-9_-]+:.*## / {printf "%-18s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
|
||||
|
||||
config: ## Render all Compose files with safe example values
|
||||
@test -f "$(ROOT)/backend/Dockerfile" || { printf 'Missing backend/Dockerfile.\n' >&2; exit 2; }
|
||||
@test -f "$(ROOT)/frontend/Dockerfile" || { printf 'Missing frontend/Dockerfile.\n' >&2; exit 2; }
|
||||
@test -f "$(ROOT)/ml/Dockerfile" || { printf 'Missing ml/Dockerfile.\n' >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" config --quiet
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(ML_PROJECT)" -f "$(ML_FILE)" config --quiet
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(MONITORING_PROJECT)" -f "$(MONITORING_FILE)" config --quiet
|
||||
|
||||
build: ## Build local frontend and backend images
|
||||
APP_PROJECT="$(APP_PROJECT)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" build
|
||||
|
||||
up: ## Start the core app and PostgreSQL without monitoring
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s. Copy .env.example to .env and replace the placeholder passwords.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" up -d
|
||||
|
||||
down: ## Stop core services and keep named volumes
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" down
|
||||
|
||||
logs: ## Follow core service logs
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(APP_PROJECT)" -f "$(CORE_FILE)" logs -f
|
||||
|
||||
monitoring-config: ## Render the separate monitoring Compose file
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(MONITORING_PROJECT)" -f "$(MONITORING_FILE)" config --quiet
|
||||
|
||||
monitoring-up: ## Start monitoring as a separate Compose project
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s. Copy .env.example to .env and replace the placeholder passwords.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(MONITORING_PROJECT)" -f "$(MONITORING_FILE)" up -d
|
||||
|
||||
monitoring-down: ## Stop monitoring and keep named volumes
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(MONITORING_PROJECT)" -f "$(MONITORING_FILE)" down
|
||||
|
||||
monitoring-logs: ## Follow monitoring service logs
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(MONITORING_PROJECT)" -f "$(MONITORING_FILE)" logs -f
|
||||
|
||||
ml-config: ## Render the separate ML Compose file
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(ML_PROJECT)" -f "$(ML_FILE)" config --quiet
|
||||
|
||||
ml-build: ## Build the ML image without starting it
|
||||
APP_PROJECT="$(APP_PROJECT)" $(DOCKER) compose --env-file "$(CHECK_ENV_FILE)" -p "$(ML_PROJECT)" -f "$(ML_FILE)" build
|
||||
|
||||
ml-up: ## Start the ML service as a separate Compose project
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s. Copy .env.example to .env and replace the placeholder passwords.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(ML_PROJECT)" -f "$(ML_FILE)" up -d
|
||||
|
||||
ml-down: ## Stop the ML service and keep named volumes
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(ML_PROJECT)" -f "$(ML_FILE)" down
|
||||
|
||||
ml-logs: ## Follow ML service logs
|
||||
@test -f "$(ENV_FILE)" || { printf 'Missing %s.\n' "$(ENV_FILE)" >&2; exit 2; }
|
||||
APP_PROJECT="$(APP_PROJECT)" APP_NETWORK="$(APP_NETWORK)" $(DOCKER) compose --env-file "$(ENV_FILE)" -p "$(ML_PROJECT)" -f "$(ML_FILE)" logs -f
|
||||
|
||||
check: config ## Validate all Compose files without starting services
|
||||
|
||||
smoke: ## Start an isolated stack and check infrastructure health routes
|
||||
@bash scripts/smoke.sh
|
||||
|
||||
test-e2e: ## Reserved for the future synthetic business-flow E2E suite
|
||||
@printf '%s\n' 'test-e2e is deferred until the synthetic business-flow suite is implemented.' >&2
|
||||
@exit 2
|
||||
@@ -0,0 +1,29 @@
|
||||
services:
|
||||
ml:
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: ml/Dockerfile
|
||||
ports:
|
||||
- "${ML_BIND_ADDRESS:-127.0.0.1}:${ML_HTTP_PORT:-8000}:8000"
|
||||
healthcheck:
|
||||
test:
|
||||
- CMD
|
||||
- python
|
||||
- -c
|
||||
- "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/healthz', timeout=2)"
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
start_period: 15s
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "2.0"
|
||||
memory: 4G
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
services:
|
||||
prometheus-targets:
|
||||
image: busybox:latest
|
||||
command:
|
||||
- /bin/sh
|
||||
- -ec
|
||||
- |
|
||||
target="$${ML_METRICS_TARGET}"
|
||||
if [ -z "$$target" ]; then
|
||||
printf '%s\n' '[]' > /targets/ml.yml
|
||||
exit 0
|
||||
fi
|
||||
case "$$target" in
|
||||
*[!A-Za-z0-9._:-]*|*:*:*)
|
||||
printf '%s\n' 'ML_METRICS_TARGET must be a private hostname or IPv4 address followed by a port.' >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
host="$${target%:*}"
|
||||
port="$${target##*:}"
|
||||
case "$$host" in
|
||||
''|.*|*..*|-*|*-) printf '%s\n' 'ML_METRICS_TARGET has an invalid host.' >&2; exit 1 ;;
|
||||
esac
|
||||
case "$$port" in
|
||||
''|*[!0-9]*) printf '%s\n' 'ML_METRICS_TARGET must end with a numeric port.' >&2; exit 1 ;;
|
||||
esac
|
||||
if [ "$$port" -lt 1 ] || [ "$$port" -gt 65535 ]; then
|
||||
printf '%s\n' 'ML_METRICS_TARGET port must be between 1 and 65535.' >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s\n' '- targets:' " - \"$$host:$$port\"" > /targets/ml.yml
|
||||
environment:
|
||||
ML_METRICS_TARGET: ${ML_METRICS_TARGET:-}
|
||||
volumes:
|
||||
- prometheus_targets:/targets
|
||||
networks:
|
||||
- observability
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: "no"
|
||||
|
||||
prometheus:
|
||||
image: prom/prometheus:latest
|
||||
command:
|
||||
- --config.file=/etc/prometheus/prometheus.yml
|
||||
- --storage.tsdb.path=/prometheus
|
||||
- --storage.tsdb.retention.time=14d
|
||||
- --storage.tsdb.retention.size=4GB
|
||||
depends_on:
|
||||
prometheus-targets:
|
||||
condition: service_completed_successfully
|
||||
volumes:
|
||||
- ../../observability/prometheus:/etc/prometheus:ro
|
||||
- prometheus_targets:/etc/prometheus/targets:ro
|
||||
- prometheus_data:/prometheus
|
||||
expose:
|
||||
- "9090"
|
||||
networks:
|
||||
- observability
|
||||
- app
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 1G
|
||||
|
||||
postgres-exporter:
|
||||
image: ghcr.io/prometheus-community/postgres-exporter:latest
|
||||
environment:
|
||||
DATA_SOURCE_URI: postgres:5432/${POSTGRES_DB:?Set POSTGRES_DB in the root .env file}?sslmode=disable
|
||||
DATA_SOURCE_USER: ${POSTGRES_EXPORTER_USER:?Set POSTGRES_EXPORTER_USER in the root .env file}
|
||||
DATA_SOURCE_PASS: ${POSTGRES_EXPORTER_PASSWORD:?Set POSTGRES_EXPORTER_PASSWORD in the root .env file}
|
||||
expose:
|
||||
- "9187"
|
||||
networks:
|
||||
- observability
|
||||
- app
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.25"
|
||||
memory: 128M
|
||||
|
||||
node-exporter:
|
||||
image: prom/node-exporter:latest
|
||||
command:
|
||||
- --path.procfs=/host/proc
|
||||
- --path.sysfs=/host/sys
|
||||
- --path.rootfs=/host/root
|
||||
- --collector.filesystem.mount-points-exclude=^/(dev|proc|sys|host|etc)($$|/)
|
||||
volumes:
|
||||
- /proc:/host/proc:ro
|
||||
- /sys:/host/sys:ro
|
||||
- /:/host/root:ro,rslave
|
||||
expose:
|
||||
- "9100"
|
||||
networks:
|
||||
- observability
|
||||
read_only: true
|
||||
user: "65534:65534"
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.25"
|
||||
memory: 128M
|
||||
|
||||
loki:
|
||||
image: grafana/loki:latest
|
||||
command:
|
||||
- -config.file=/etc/loki/loki.yml
|
||||
- -target=all
|
||||
volumes:
|
||||
- ../../observability/loki/loki.yml:/etc/loki/loki.yml:ro
|
||||
- loki_data:/loki
|
||||
expose:
|
||||
- "3100"
|
||||
networks:
|
||||
- observability
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 1G
|
||||
|
||||
alloy:
|
||||
image: grafana/alloy:latest
|
||||
user: "473:473"
|
||||
environment:
|
||||
APP_PROJECT: ${APP_PROJECT:-app}
|
||||
command:
|
||||
- run
|
||||
- --server.http.listen-addr=127.0.0.1:12345
|
||||
- --storage.path=/var/lib/alloy/data
|
||||
- /etc/alloy/app.alloy
|
||||
depends_on:
|
||||
- loki
|
||||
- docker-socket-proxy
|
||||
volumes:
|
||||
- ../../observability/alloy/app.alloy:/etc/alloy/app.alloy:ro
|
||||
- alloy_data:/var/lib/alloy/data
|
||||
expose:
|
||||
- "12347"
|
||||
networks:
|
||||
observability: {}
|
||||
app:
|
||||
aliases:
|
||||
- faro-receiver
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.5"
|
||||
memory: 512M
|
||||
|
||||
docker-socket-proxy:
|
||||
image: tecnativa/docker-socket-proxy:latest
|
||||
environment:
|
||||
CONTAINERS: "1"
|
||||
EVENTS: "1"
|
||||
IMAGES: "0"
|
||||
INFO: "0"
|
||||
NETWORKS: "0"
|
||||
PING: "1"
|
||||
POST: "0"
|
||||
VERSION: "1"
|
||||
volumes:
|
||||
- type: bind
|
||||
source: ${DOCKER_SOCKET_PATH:-/var/run/docker.sock}
|
||||
target: /var/run/docker.sock
|
||||
read_only: true
|
||||
bind:
|
||||
create_host_path: false
|
||||
expose:
|
||||
- "2375"
|
||||
networks:
|
||||
- observability
|
||||
# The image entrypoint renders HAProxy configuration before starting.
|
||||
tmpfs:
|
||||
- /tmp
|
||||
cap_drop:
|
||||
- ALL
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
|
||||
grafana:
|
||||
image: grafana/grafana:latest
|
||||
environment:
|
||||
GF_SERVER_PROTOCOL: http
|
||||
GF_SERVER_DOMAIN: localhost
|
||||
GF_SERVER_ROOT_URL: http://localhost:${GRAFANA_PORT:-3000}/
|
||||
GF_SECURITY_ADMIN_USER: ${GRAFANA_ADMIN_USER:?Set GRAFANA_ADMIN_USER in the root .env file}
|
||||
GF_SECURITY_ADMIN_PASSWORD: ${GRAFANA_ADMIN_PASSWORD:?Set GRAFANA_ADMIN_PASSWORD in the root .env file}
|
||||
GF_USERS_ALLOW_SIGN_UP: "false"
|
||||
GF_ANALYTICS_REPORTING_ENABLED: "false"
|
||||
ports:
|
||||
- "127.0.0.1:${GRAFANA_PORT:-3000}:3000"
|
||||
volumes:
|
||||
- grafana_data:/var/lib/grafana
|
||||
- ../../observability/grafana/provisioning:/etc/grafana/provisioning:ro
|
||||
- ../../observability/grafana/dashboards:/var/lib/grafana/dashboards:ro
|
||||
networks:
|
||||
- observability
|
||||
- app
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 768M
|
||||
|
||||
networks:
|
||||
app:
|
||||
name: ${APP_NETWORK:-app_default}
|
||||
external: true
|
||||
observability:
|
||||
internal: true
|
||||
|
||||
volumes:
|
||||
alloy_data:
|
||||
grafana_data:
|
||||
loki_data:
|
||||
prometheus_data:
|
||||
prometheus_targets:
|
||||
@@ -0,0 +1,88 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:alpine
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:?Set POSTGRES_DB in the root .env file}
|
||||
POSTGRES_USER: ${POSTGRES_USER:?Set POSTGRES_USER in the root .env file}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD in the root .env file}
|
||||
POSTGRES_EXPORTER_USER: ${POSTGRES_EXPORTER_USER:-}
|
||||
POSTGRES_EXPORTER_PASSWORD: ${POSTGRES_EXPORTER_PASSWORD:-}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql
|
||||
- ./initdb/10-postgres-exporter.sh:/docker-entrypoint-initdb.d/10-postgres-exporter.sh:ro
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U \"$${POSTGRES_USER}\" -d \"$${POSTGRES_DB}\""]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 20s
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 2G
|
||||
|
||||
backend:
|
||||
build:
|
||||
context: ../../backend
|
||||
dockerfile: Dockerfile
|
||||
environment:
|
||||
DATABASE_URL: postgres://${POSTGRES_USER:?Set POSTGRES_USER}:${POSTGRES_PASSWORD:?Set POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:?Set POSTGRES_DB}?sslmode=disable
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
expose:
|
||||
- "8080"
|
||||
- "9090"
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1.0"
|
||||
memory: 768M
|
||||
|
||||
frontend:
|
||||
build:
|
||||
context: ../..
|
||||
dockerfile: frontend/Dockerfile
|
||||
depends_on:
|
||||
backend:
|
||||
condition: service_started
|
||||
ports:
|
||||
- "127.0.0.1:${APP_HTTP_PORT:-8080}:8080"
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1:8080/healthz"]
|
||||
interval: 10s
|
||||
timeout: 3s
|
||||
retries: 5
|
||||
start_period: 5s
|
||||
restart: unless-stopped
|
||||
logging:
|
||||
driver: json-file
|
||||
options:
|
||||
max-size: 10m
|
||||
max-file: "3"
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "0.5"
|
||||
memory: 256M
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
name: ${APP_PROJECT:-app}_postgres_data
|
||||
|
||||
networks:
|
||||
default:
|
||||
name: ${APP_NETWORK:-app_default}
|
||||
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ -z "${POSTGRES_EXPORTER_USER:-}" && -z "${POSTGRES_EXPORTER_PASSWORD:-}" ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
: "${POSTGRES_EXPORTER_USER:?POSTGRES_EXPORTER_USER and POSTGRES_EXPORTER_PASSWORD must both be set}"
|
||||
: "${POSTGRES_EXPORTER_PASSWORD:?POSTGRES_EXPORTER_USER and POSTGRES_EXPORTER_PASSWORD must both be set}"
|
||||
|
||||
psql \
|
||||
--username "$POSTGRES_USER" \
|
||||
--dbname "$POSTGRES_DB" \
|
||||
--set=exporter_user="$POSTGRES_EXPORTER_USER" \
|
||||
--set=exporter_password="$POSTGRES_EXPORTER_PASSWORD" <<'SQL'
|
||||
SELECT format('CREATE ROLE %I LOGIN PASSWORD %L', :'exporter_user', :'exporter_password')
|
||||
WHERE NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = :'exporter_user')
|
||||
\gexec
|
||||
|
||||
GRANT pg_monitor TO :"exporter_user";
|
||||
SQL
|
||||
@@ -0,0 +1,53 @@
|
||||
server {
|
||||
listen 8080;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
add_header X-Content-Type-Options nosniff always;
|
||||
add_header Referrer-Policy strict-origin-when-cross-origin always;
|
||||
add_header X-Frame-Options DENY always;
|
||||
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
|
||||
|
||||
location = /healthz {
|
||||
access_log off;
|
||||
default_type text/plain;
|
||||
return 200 "ok\n";
|
||||
}
|
||||
|
||||
location = /api {
|
||||
return 404;
|
||||
}
|
||||
|
||||
location ^~ /api/ {
|
||||
proxy_pass http://backend:8080;
|
||||
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 X-Request-ID $request_id;
|
||||
proxy_connect_timeout 3s;
|
||||
proxy_send_timeout 30s;
|
||||
proxy_read_timeout 30s;
|
||||
}
|
||||
|
||||
location = /telemetry {
|
||||
limit_req zone=telemetry_rate burst=10 nodelay;
|
||||
client_max_body_size 1m;
|
||||
set $faro_receiver faro-receiver:12347;
|
||||
proxy_pass http://$faro_receiver/collect;
|
||||
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 2s;
|
||||
proxy_send_timeout 5s;
|
||||
proxy_read_timeout 5s;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
worker_processes auto;
|
||||
pid /tmp/nginx.pid;
|
||||
error_log /dev/stderr warn;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$request_method $uri $status $request_time '
|
||||
'$upstream_response_time $request_id';
|
||||
access_log /dev/stdout main;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
keepalive_timeout 30s;
|
||||
server_tokens off;
|
||||
client_max_body_size 10m;
|
||||
|
||||
client_body_temp_path /tmp/client_body;
|
||||
proxy_temp_path /tmp/proxy;
|
||||
fastcgi_temp_path /tmp/fastcgi;
|
||||
scgi_temp_path /tmp/scgi;
|
||||
uwsgi_temp_path /tmp/uwsgi;
|
||||
|
||||
limit_req_zone $binary_remote_addr zone=telemetry_rate:10m rate=30r/m;
|
||||
resolver 127.0.0.11 valid=30s ipv6=off;
|
||||
|
||||
include /etc/nginx/conf.d/*.conf;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)
|
||||
compose_file="$root/deploy/docker/docker-compose.yml"
|
||||
env_file="$root/.env.example"
|
||||
project=lincodex-smoke
|
||||
app_network="${project}_default"
|
||||
port=18080
|
||||
volume="${project}_postgres_data"
|
||||
network="${project}_default"
|
||||
started=0
|
||||
|
||||
compose() {
|
||||
APP_PROJECT="$project" APP_NETWORK="$app_network" APP_HTTP_PORT="$port" docker compose \
|
||||
--env-file "$env_file" \
|
||||
-p "$project" \
|
||||
-f "$compose_file" \
|
||||
"$@"
|
||||
}
|
||||
|
||||
if docker volume inspect "$volume" >/dev/null 2>&1; then
|
||||
printf 'Refusing to use existing smoke volume %s.\n' "$volume" >&2
|
||||
exit 2
|
||||
fi
|
||||
if docker network inspect "$network" >/dev/null 2>&1; then
|
||||
printf 'Refusing to use existing smoke network %s.\n' "$network" >&2
|
||||
exit 2
|
||||
fi
|
||||
for dockerfile in "$root/backend/Dockerfile" "$root/frontend/Dockerfile"; do
|
||||
if [[ ! -f "$dockerfile" ]]; then
|
||||
printf 'Missing required build file %s.\n' "$dockerfile" >&2
|
||||
exit 2
|
||||
fi
|
||||
done
|
||||
if [[ -n "$(compose ps -q 2>/dev/null || true)" ]]; then
|
||||
printf 'Refusing to use existing Compose project %s.\n' "$project" >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cleanup() {
|
||||
local result=$?
|
||||
trap - EXIT
|
||||
if (( started )); then
|
||||
if ! compose down --volumes --remove-orphans; then
|
||||
printf '%s\n' 'Smoke cleanup failed; inspect only the lincodex-smoke Compose project.' >&2
|
||||
result=1
|
||||
fi
|
||||
fi
|
||||
exit "$result"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
compose config --quiet
|
||||
started=1
|
||||
compose up --build -d --wait --wait-timeout 120
|
||||
|
||||
wait_for() {
|
||||
local url=$1
|
||||
local attempt
|
||||
for attempt in {1..60}; do
|
||||
if curl --fail --silent --show-error "$url" >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
printf 'Timed out waiting for %s.\n' "$url" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for "http://127.0.0.1:$port/healthz"
|
||||
wait_for "http://127.0.0.1:$port/api/v1/healthz"
|
||||
readiness=$(compose exec -T frontend wget -q -O - http://backend:8080/readyz)
|
||||
if [[ "$readiness" != '{"status":"ready"}' ]]; then
|
||||
printf 'Backend did not confirm database readiness: %s\n' "$readiness" >&2
|
||||
exit 1
|
||||
fi
|
||||
status=$(curl --silent --show-error --output /dev/null --write-out '%{http_code}' \
|
||||
"http://127.0.0.1:$port/api/v1/missing")
|
||||
if [[ "$status" != 404 ]]; then
|
||||
printf 'Unknown API route returned %s instead of 404.\n' "$status" >&2
|
||||
exit 1
|
||||
fi
|
||||
printf '%s\n' 'Technical smoke passed: frontend, API routing, and PostgreSQL readiness.'
|
||||
Reference in new issue
Block a user