diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22e0eae736..037332376e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -97,10 +97,6 @@ jobs: name: fluidd-${{ github.sha }}.zip path: ./dist - - name: Update nginx configuration - run: | - sed -i "s/\${PORT} default_server;/${{ matrix.port }} default_server;/g" ./server/nginx/default.conf.template - - name: Prepare Docker image metadata id: docker_meta uses: docker/metadata-action@v6 @@ -136,6 +132,7 @@ jobs: platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8 build-args: | BASE_IMAGE=${{ matrix.base-image }} + PORT=${{ matrix.port }} push: true sbom: true provenance: true diff --git a/Dockerfile b/Dockerfile index 680bb0f44c..6cf5b5b03f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,5 +2,11 @@ ARG BASE_IMAGE=nginx:alpine-slim FROM $BASE_IMAGE +ARG PORT=80 +ENV PORT=${PORT} + COPY /dist /usr/share/nginx/html COPY /server/nginx /etc/nginx/templates + +HEALTHCHECK --interval=10s --timeout=3s --start-period=10s --retries=3 \ + CMD wget -q -O /dev/null -T 2 "http://127.0.0.1:${PORT}/healthz" || exit 1 diff --git a/docs/docs/getting-started.md b/docs/docs/getting-started.md index fd04dbba6b..3dbd919084 100644 --- a/docs/docs/getting-started.md +++ b/docs/docs/getting-started.md @@ -46,6 +46,27 @@ Both are updated on each release and each commit. Available tags: [View on GitHub Container registry](https://github.com/fluidd-core/fluidd/pkgs/container/fluidd){.md-button} +### Health Check + +Both images ship a Docker `HEALTHCHECK` that polls `/healthz` on the image's own +port, so `docker ps` reports the container as `healthy` once NGINX is serving: + +```bash +docker inspect --format '{{.State.Health.Status}}' fluidd +``` + +With Docker Compose, other services can wait for it: + +```yaml +depends_on: + fluidd: + condition: service_healthy +``` + +The endpoint is a plain `200 ok` response and is excluded from the access log. +The check runs every 10 seconds and can be overridden per-deployment with the +`healthcheck` key in Compose. + ## Manual Installation Every Fluidd release includes a pre-built `fluidd.zip` on the diff --git a/server/nginx/default.conf.template b/server/nginx/default.conf.template index fa4d3ef960..9a2d62669f 100644 --- a/server/nginx/default.conf.template +++ b/server/nginx/default.conf.template @@ -30,4 +30,10 @@ server { location = /index.html { add_header Cache-Control "no-store, no-cache, must-revalidate"; } + + location = /healthz { + access_log off; + default_type text/plain; + return 200 "ok\n"; + } }