Compare commits

..

9 Commits

Author SHA1 Message Date
cal
26549a7210 Merge pull request 'security: add non-root user to Dockerfile (#120)' (#122) from issue/120-security-add-non-root-user-to-dockerfile into main
Reviewed-on: #122
2026-04-12 15:00:07 +00:00
Cal Corum
8ed7405c8a fix: move uvicorn to port 8080 so non-root user can bind
Non-root users cannot bind to privileged ports (<1024) without ambient
capabilities, which Docker does not set by default. Switch uvicorn,
healthcheck, and docker-compose port mapping from 80 to 8080. Also
combine the two RUN instructions for user/directory setup into one layer.

Addresses review feedback on #122.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 14:31:11 -05:00
Cal Corum
17a39e7eca security: add non-root user to Dockerfile (#120)
Closes #120

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 14:31:02 -05:00
cal
6972cbe610 Merge pull request 'feat: expose running CalVer version via API (#126)' (#127) from issue/126-feat-expose-running-calver-version-via-api into main
Reviewed-on: #127
2026-04-10 15:54:13 +00:00
Cal Corum
4acf7b2afa feat: expose running CalVer version via API (#126)
Closes #126

- Dockerfile: ARG BUILD_VERSION=dev baked into ENV APP_VERSION + OCI label
- CI: passes BUILD_VERSION build-arg from git tag to docker build
- main.py: adds GET /health returning {"status": "ok", "version": "..."}
- Dockerfile: updates HEALTHCHECK to use /health (no SQL, lightweight)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 15:53:55 +00:00
cal
1b10933ca1 Merge pull request 'chore: remove vestigial env vars from docker-compose (#121)' (#123) from issue/121-chore-remove-vestigial-env-vars-from-docker-compos into main
Reviewed-on: #123
2026-04-10 15:53:32 +00:00
Cal Corum
99fbb3848b chore: remove vestigial env vars from docker-compose (#121)
Closes #121

WORKERS_PER_CORE, TIMEOUT, and GRACEFUL_TIMEOUT were consumed by the
old tiangolo/uvicorn-gunicorn-fastapi base image and are silently
ignored since switching to python:3.12-slim with an explicit uvicorn CMD.

Also applied the same removal to dev (ssh sba-db) and prod (ssh akamai)
docker-compose files directly. Added WEB_WORKERS=4 to prod to override
the Dockerfile default of 2.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-10 15:53:21 +00:00
cal
18d7a8a758 Merge pull request 'chore: drop libpq-dev from Dockerfile (#118)' (#124) from issue/118-chore-drop-libpq-dev-from-dockerfile into main
Reviewed-on: #124
2026-04-10 15:52:48 +00:00
Cal Corum
c22e6072a2 chore: drop libpq-dev from Dockerfile (#118)
psycopg2-binary bundles its own libpq and does not need libpq-dev at
build time. curl is kept for the HEALTHCHECK.

Closes #118

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-09 13:31:34 -05:00
5 changed files with 22 additions and 127 deletions

View File

@ -58,6 +58,8 @@ jobs:
tags: |
manticorum67/major-domo-database:${{ steps.version.outputs.version }}
manticorum67/major-domo-database:${{ steps.version.outputs.environment }}
build-args: |
BUILD_VERSION=${{ steps.version.outputs.version }}
cache-from: type=registry,ref=manticorum67/major-domo-database:buildcache
cache-to: type=registry,ref=manticorum67/major-domo-database:buildcache,mode=max

View File

@ -1,16 +1,21 @@
# Use official Python slim image
FROM python:3.12-slim
# Build-time version arg — passed by CI from the git tag
ARG BUILD_VERSION=dev
LABEL org.opencontainers.image.version=$BUILD_VERSION
# Set Python optimizations
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PIP_NO_CACHE_DIR=1
# Bake the CalVer version into the image so it's readable at runtime
ENV APP_VERSION=$BUILD_VERSION
WORKDIR /usr/src/app
# Install system dependencies (PostgreSQL client libraries)
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq-dev \
curl \
&& rm -rf /var/lib/apt/lists/*
@ -22,13 +27,17 @@ RUN pip install --no-cache-dir --upgrade pip && \
# Copy application code
COPY ./app /usr/src/app/app
# Create directories for volumes
RUN mkdir -p /usr/src/app/storage
# Create non-root user and set up directories for volumes
RUN addgroup --system appuser && \
adduser --system --ingroup appuser appuser && \
mkdir -p /usr/src/app/storage /usr/src/app/logs && \
chown -R appuser:appuser /usr/src/app
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:80/api/v3/current || exit 1
CMD curl -f http://localhost:8080/health || exit 1
# Start uvicorn
ENV WEB_WORKERS=2
CMD ["sh", "-c", "exec uvicorn app.main:app --host 0.0.0.0 --port 80 --workers $WEB_WORKERS"]
CMD ["sh", "-c", "exec uvicorn app.main:app --host 0.0.0.0 --port 8080 --workers $WEB_WORKERS"]

View File

@ -139,6 +139,11 @@ app.include_router(views.router)
logger.info(f"Loaded all routers.")
@app.get("/health")
async def health():
return {"status": "ok", "version": os.environ.get("APP_VERSION", "dev")}
@app.get("/api/docs", include_in_schema=False)
async def get_docs(req: Request):
logger.debug(req.scope)

View File

@ -1,118 +0,0 @@
version: '3'
networks:
nginx-proxy-manager_npm_network:
external: true
services:
api:
# build: .
image: manticorum67/major-domo-database:production
restart: unless-stopped
container_name: sba_db_api
volumes:
- ./storage:/usr/src/app/storage
- ./logs:/usr/src/app/logs
ports:
- 801:80
networks:
- default
- nginx-proxy-manager_npm_network
environment:
- TESTING=False
- LOG_LEVEL=${LOG_LEVEL}
- API_TOKEN=${API_TOKEN}
- TZ=${TZ}
- DATABASE_TYPE=postgresql
- POSTGRES_HOST=sba_postgres
- POSTGRES_DB=${SBA_DATABASE}
- POSTGRES_USER=${SBA_DB_USER}
- POSTGRES_PASSWORD=${SBA_DB_USER_PASSWORD}
- WEB_WORKERS=4
- REDIS_HOST=sba_redis
- REDIS_PORT=6379
- REDIS_DB=0
- CACHE_ENABLED=False
depends_on:
- postgres
- redis
postgres:
image: postgres:17-alpine
restart: unless-stopped
container_name: sba_postgres
environment:
- POSTGRES_DB=${SBA_DATABASE}
- POSTGRES_USER=${SBA_DB_USER}
- POSTGRES_PASSWORD=${SBA_DB_USER_PASSWORD}
- TZ=${TZ}
volumes:
- postgres_data:/var/lib/postgresql/data
- ./logs:/var/log/postgresql
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${SBA_DB_USER} -d ${SBA_DATABASE}"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
redis:
image: redis:7-alpine
restart: unless-stopped
container_name: sba_redis
ports:
- "6379:6379"
volumes:
- redis_data:/data
environment:
- TZ=${TZ}
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
command: redis-server --appendonly yes
adminer:
image: adminer:latest
restart: unless-stopped
container_name: sba_adminer
ports:
- "8080:8080"
environment:
- ADMINER_DEFAULT_SERVER=sba_postgres
- TZ=${TZ}
# - ADMINER_DESIGN=pepa-linha-dark
depends_on:
- postgres
sync-prod:
image: alpine:latest
container_name: sba_sync_prod
volumes:
- ./scripts:/scripts
- /home/cal/.ssh:/tmp/ssh:ro
environment:
- SBA_DB_USER=${SBA_DB_USER}
- SBA_DATABASE=${SBA_DATABASE}
- SBA_DB_USER_PASSWORD=${SBA_DB_USER_PASSWORD}
command: >
sh -c "
cp -r /tmp/ssh /root/.ssh &&
chmod 700 /root/.ssh &&
chmod 600 /root/.ssh/* &&
chown -R root:root /root/.ssh &&
/scripts/sync_from_prod.sh
"
profiles: ["sync"]
depends_on:
- postgres
networks:
- default
volumes:
postgres_data:
redis_data:

View File

@ -14,7 +14,7 @@ services:
- ./storage:/usr/src/app/storage
- ./logs:/usr/src/app/logs
ports:
- 801:80
- 801:8080
networks:
- default
# - nginx-proxy-manager_npm_network # Commented for local testing
@ -23,9 +23,6 @@ services:
- LOG_LEVEL=${LOG_LEVEL}
- API_TOKEN=${API_TOKEN}
- TZ=${TZ}
- WORKERS_PER_CORE=1.5
- TIMEOUT=120
- GRACEFUL_TIMEOUT=120
- DATABASE_TYPE=postgresql
- POSTGRES_HOST=sba_postgres
- POSTGRES_DB=${SBA_DATABASE}