Fix Dockerfile static copy, dynamic port, health endpoint
Some checks failed
Build and Deploy citti / build-and-deploy (push) Has been cancelled

- Remove COPY static/ (runtime uploads live in DATA_DIR/uploads)
- Add /health endpoint
- Read PORT from env (NOMAD_PORT_http in production, 9756 local)
- citti.nomad: dynamic port, canary deploy, Consul/Traefik, health check

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Henrik Jess Nielsen
2026-06-06 01:04:29 +02:00
parent 77eed9aa50
commit d7ab8e02a1
3 changed files with 100 additions and 28 deletions

View File

@@ -1,19 +1,33 @@
FROM python:3.12-slim FROM python:3.12-slim
ARG BUILD_VERSION=unknown
ARG BUILD_TIME=unknown
ARG GIT_COMMIT=unknown
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
FLASK_APP=app.py \
FLASK_ENV=production \
BUILD_VERSION=${BUILD_VERSION} \
BUILD_TIME=${BUILD_TIME} \
GIT_COMMIT=${GIT_COMMIT}
WORKDIR /app WORKDIR /app
COPY requirements.txt . RUN pip install --upgrade --no-cache-dir pip
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt RUN pip install --no-cache-dir -r requirements.txt
COPY app.py . COPY app.py .
COPY templates/ templates/ COPY templates/ templates/
COPY static/ static/
ENV DATA_DIR=/data ENV DATA_DIR=/app/instance \
VOLUME ["/data"] PORT=9756 \
HOST=0.0.0.0
RUN mkdir -p /app/instance
EXPOSE 9756 EXPOSE 9756
RUN useradd -m appuser && chown -R appuser /app CMD ["sh", "-c", "python app.py"]
USER appuser
CMD ["python", "app.py"]

12
app.py
View File

@@ -191,6 +191,11 @@ def serve_upload(filename):
return send_from_directory(UPLOAD_DIR, filename) return send_from_directory(UPLOAD_DIR, filename)
@app.route('/health')
def health():
return jsonify({'status': 'healthy', 'service': 'citti'})
@app.route('/api/category', methods=['POST']) @app.route('/api/category', methods=['POST'])
def add_category(): def add_category():
d = request.json d = request.json
@@ -255,6 +260,7 @@ def analyse():
if __name__ == '__main__': if __name__ == '__main__':
init_db() init_db()
port = int(os.environ.get('PORT', 9756))
try: try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80)) s.connect(("8.8.8.8", 80))
@@ -262,6 +268,6 @@ if __name__ == '__main__':
s.close() s.close()
except Exception: except Exception:
local_ip = "127.0.0.1" local_ip = "127.0.0.1"
print(f"\n Computer: http://localhost:9756") print(f"\n Computer: http://localhost:{port}")
print(f" Telefon (samme WiFi): http://{local_ip}:9756\n") print(f" Telefon (samme WiFi): http://{local_ip}:{port}\n")
app.run(host='0.0.0.0', port=9756, debug=False) app.run(host='0.0.0.0', port=port, debug=False)

View File

@@ -1,50 +1,102 @@
job "citti" { job "citti" {
region = "global"
datacenters = ["dc1"] datacenters = ["dc1"]
type = "service" type = "service"
update {
stagger = "30s"
max_parallel = 1
canary = 1
min_healthy_time = "10s"
healthy_deadline = "5m"
auto_revert = true
auto_promote = true
progress_deadline = "10m"
}
group "app" { group "app" {
count = 1 count = 1
volume "citti-data" { network {
type = "host" port "http" {}
read_only = false
source = "citti-data"
} }
network { reschedule {
port "http" { attempts = 5
static = 9756 interval = "10m"
delay = "30s"
delay_function = "exponential"
max_delay = "120s"
unlimited = false
}
volume "citti-data" {
type = "host"
source = "citti-data"
read_only = false
}
service {
provider = "consul"
name = "citti"
port = "http"
tags = [
"traefik.enable=true",
"traefik.http.routers.citti.rule=Host(`citti.i80.dk`)",
"traefik.http.routers.citti.tls=true",
]
canary_tags = [
"traefik.enable=false",
]
check {
name = "http_health_check"
type = "http"
path = "/health"
interval = "10s"
timeout = "5s"
check_restart {
limit = 3
grace = "10s"
}
} }
} }
task "web" { task "web" {
driver = "docker" driver = "docker"
volume_mount {
volume = "citti-data"
destination = "/app/instance"
read_only = false
}
config { config {
image = "registry.i80.dk/gitea/citti:latest" image = "registry.i80.dk/gitea/citti:latest"
ports = ["http"] ports = ["http"]
force_pull = true force_pull = true
} }
volume_mount { restart {
volume = "citti-data" attempts = 10
destination = "/data" interval = "10m"
read_only = false delay = "10s"
mode = "fail"
} }
env { env {
DATA_DIR = "/data" DATA_DIR = "/app/instance"
PORT = "${NOMAD_PORT_http}"
HOST = "0.0.0.0"
} }
resources { resources {
cpu = 200 cpu = 200
memory = 256 memory = 256
} }
service {
name = "citti"
port = "http"
}
} }
} }
} }