Compare commits
1 Commits
chore/cont
...
chore/ci-p
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84a033a0fb |
12
.env.example
12
.env.example
@@ -1,13 +1,23 @@
|
||||
# Copy to .env for `docker compose up --build`. Local-dev runs (cargo run
|
||||
# / npm run dev) read backend/.env if present, or pick up the variables
|
||||
# from your shell.
|
||||
#
|
||||
# Production note: COOKIE_SECURE=true (the default below) makes browsers
|
||||
# refuse to send the session cookie over plain HTTP. Run with a TLS-
|
||||
# terminating reverse proxy (Caddy, Traefik, nginx) in front — the
|
||||
# compose file here doesn't ship one. Local/dev runs without HTTPS
|
||||
# should set COOKIE_SECURE=false.
|
||||
|
||||
# ----- Postgres -----
|
||||
# These are read by the Postgres container *and* by DATABASE_URL below;
|
||||
# changing them after the first boot won't migrate existing data, so set
|
||||
# them up front for any new deployment.
|
||||
#
|
||||
# POSTGRES_PASSWORD is REQUIRED — docker-compose.yml fails fast if it
|
||||
# isn't set in this file, to prevent a deploy without an .env booting
|
||||
# Postgres with a publicly-known credential.
|
||||
POSTGRES_USER=mangalord
|
||||
POSTGRES_PASSWORD=mangalord
|
||||
POSTGRES_PASSWORD=change-me-to-a-strong-random-string
|
||||
POSTGRES_DB=mangalord
|
||||
|
||||
# ----- Backend -----
|
||||
|
||||
@@ -3,6 +3,8 @@ name: deploy
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
@@ -63,6 +65,10 @@ jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [test-backend, test-frontend]
|
||||
# PRs only run the test jobs; build + deploy are reserved for
|
||||
# post-merge pushes to main. Without this gate every PR would push
|
||||
# a tagged image to the registry and SSH-deploy to prod.
|
||||
if: github.event_name != 'pull_request'
|
||||
outputs:
|
||||
image_tag: ${{ steps.meta.outputs.image_tag }}
|
||||
version: ${{ steps.meta.outputs.version }}
|
||||
@@ -117,6 +123,7 @@ jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build-and-push
|
||||
if: github.event_name != 'pull_request'
|
||||
steps:
|
||||
- name: SSH deploy
|
||||
uses: appleboy/ssh-action@v1.0.3
|
||||
|
||||
@@ -19,49 +19,12 @@ COPY migrations ./migrations
|
||||
RUN touch src/main.rs src/lib.rs && cargo build --locked --release
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
# `curl` is for the container HEALTHCHECK; `ca-certificates` is for
|
||||
# outbound HTTPS (crawler covers/pages).
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates curl \
|
||||
&& apt-get install -y --no-install-recommends ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Non-root runtime user. The API binary doesn't need any root
|
||||
# privilege; the crawler daemon's Chromium launcher uses --no-sandbox
|
||||
# precisely because user-namespace sandboxing is fragile, so dropping
|
||||
# privileges costs nothing operationally and shrinks the blast radius
|
||||
# of any RCE.
|
||||
ARG APP_UID=10001
|
||||
ARG APP_GID=10001
|
||||
RUN groupadd --system --gid ${APP_GID} app \
|
||||
&& useradd --system --uid ${APP_UID} --gid app --home-dir /home/app --create-home --shell /usr/sbin/nologin app
|
||||
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/target/release/mangalord /usr/local/bin/mangalord
|
||||
COPY --from=builder /app/migrations /app/migrations
|
||||
|
||||
ENV STORAGE_DIR=/var/lib/mangalord/storage
|
||||
# Pre-create the storage dir so the entrypoint doesn't need to
|
||||
# mkdir-as-root and so the named volume mount inherits the right
|
||||
# ownership.
|
||||
#
|
||||
# UPGRADE NOTE for operators: if you're moving from an older image
|
||||
# that ran as root, the existing `storage-data` volume has files owned
|
||||
# by UID 0 and the new UID-10001 user can't write them. Run once
|
||||
# before the upgrade:
|
||||
# docker compose run --rm --user 0 backend \
|
||||
# chown -R 10001:10001 /var/lib/mangalord/storage
|
||||
# (Postgres is unaffected — that image's `postgres` user UID hasn't
|
||||
# changed.)
|
||||
RUN mkdir -p ${STORAGE_DIR} \
|
||||
&& chown -R app:app ${STORAGE_DIR} /app /home/app
|
||||
|
||||
USER app
|
||||
EXPOSE 8080
|
||||
|
||||
# `--start-period` is generous because first boot runs sqlx::migrate
|
||||
# against postgres which can take a few seconds; subsequent restarts
|
||||
# are sub-second.
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
||||
CMD curl -fsS http://localhost:8080/api/v1/health > /dev/null || exit 1
|
||||
|
||||
CMD ["mangalord"]
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
# Production-like compose. Requires a populated `.env` next to this
|
||||
# file: at minimum POSTGRES_PASSWORD must be set to a non-default
|
||||
# value (the `?required` form below fails fast otherwise). The
|
||||
# frontend container expects HTTPS in front (Caddy/Traefik/nginx)
|
||||
# because COOKIE_SECURE=true browsers will refuse to send the session
|
||||
# cookie over plain HTTP.
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16-alpine
|
||||
environment:
|
||||
POSTGRES_USER: ${POSTGRES_USER:-mangalord}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-mangalord}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set in .env}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-mangalord}
|
||||
volumes:
|
||||
- postgres-data:/var/lib/postgresql/data
|
||||
@@ -19,7 +25,7 @@ services:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
DATABASE_URL: postgres://${POSTGRES_USER:-mangalord}:${POSTGRES_PASSWORD:-mangalord}@postgres:5432/${POSTGRES_DB:-mangalord}
|
||||
DATABASE_URL: postgres://${POSTGRES_USER:-mangalord}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD must be set in .env}@postgres:5432/${POSTGRES_DB:-mangalord}
|
||||
BIND_ADDRESS: 0.0.0.0:8080
|
||||
STORAGE_DIR: /var/lib/mangalord/storage
|
||||
RUST_LOG: ${RUST_LOG:-info,mangalord=debug}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
FROM node:22-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY package.json package-lock.json* ./
|
||||
# `npm ci` installs the locked versions exactly; `npm install` would
|
||||
# silently rewrite package-lock.json mid-build. CI (.gitea/workflows)
|
||||
# also uses `npm ci`, so this keeps the image build deterministic and
|
||||
# matches what the test job validated.
|
||||
RUN npm ci
|
||||
RUN npm install
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
@@ -14,20 +10,8 @@ WORKDIR /app
|
||||
ENV NODE_ENV=production
|
||||
ENV HOST=0.0.0.0
|
||||
ENV PORT=3000
|
||||
|
||||
# node:22-alpine ships a `node` user (UID 1000); use it instead of
|
||||
# running the SvelteKit server as root.
|
||||
COPY --from=builder --chown=node:node /app/build ./build
|
||||
COPY --from=builder --chown=node:node /app/node_modules ./node_modules
|
||||
COPY --from=builder --chown=node:node /app/package.json ./
|
||||
|
||||
USER node
|
||||
COPY --from=builder /app/build ./build
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/package.json ./
|
||||
EXPOSE 3000
|
||||
|
||||
# Alpine's busybox `wget` is the canonical lightweight HTTP probe.
|
||||
# `--spider` doesn't follow redirects; `node build` serves a 200 on
|
||||
# `/` for the homepage so this works without a dedicated /health.
|
||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
|
||||
CMD wget -q --spider http://localhost:3000/ || exit 1
|
||||
|
||||
CMD ["node", "build"]
|
||||
|
||||
Reference in New Issue
Block a user