Allow dev users to select the port that is listened on when building docs (#1274).

Reviewed-on: https://projects.torsion.org/borgmatic-collective/borgmatic/pulls/1274
Reviewed-by: Dan Helfman <witten@torsion.org>
This commit is contained in:
Dan Helfman
2026-03-01 19:37:13 +00:00
7 changed files with 43 additions and 14 deletions
+1
View File
@@ -0,0 +1 @@
PORT=8080
+2 -1
View File
@@ -12,6 +12,7 @@ RUN /app/docs/fetch-contributors >> /contributors.html
FROM docker.io/node:22.4.0-alpine AS html
ARG ENVIRONMENT=production
ARG PORT=${PORT}
WORKDIR /source
@@ -28,7 +29,7 @@ COPY --from=borgmatic /etc/borgmatic/options.json /source/docs/reference/configu
COPY --from=borgmatic /command-line/* /source/docs/_includes/borgmatic/command-line/
COPY --from=borgmatic /contributors.html /source/docs/_includes/borgmatic/contributors.html
COPY . /source
RUN NODE_ENV=${ENVIRONMENT} npx eleventy --input=/source/docs --output=/output
RUN NODE_ENV=${ENVIRONMENT} PORT=${PORT} npx eleventy --input=/source/docs --output=/output
RUN npx -y pagefind --site /output
FROM docker.io/nginx:1.26.1-alpine
+2 -1
View File
@@ -1,5 +1,6 @@
module.exports = function() {
return {
environment: process.env.NODE_ENV || "development"
environment: process.env.NODE_ENV || "development",
port: process.env.PORT || 8080
};
};
+1 -1
View File
@@ -21,7 +21,7 @@ headerClass: elv-header-default
{% set navPages = collections.all | eleventyNavigation %}
{% macro renderNavListItem(entry) -%}
<li{% if entry.url == page.url %} class="elv-toc-active"{% endif %}>
<a {% if entry.url %}href="{% if borgmatic.environment == "production" %}https://torsion.org/borgmatic{% else %}http://localhost:8080/borgmatic{% endif %}{{ entry.url | url }}"{% endif %}>{{ entry.title }}</a>
<a {% if entry.url %}href="{% if borgmatic.environment == "production" %}https://torsion.org/borgmatic{% else %}http://localhost:{{ borgmatic.port }}/borgmatic{% endif %}{{ entry.url | url }}"{% endif %}>{{ entry.title }}</a>
{%- if entry.children.length -%}
<ul>
{%- for child in entry.children %}{{ renderNavListItem(child) }}{% endfor -%}
+8 -3
View File
@@ -2,10 +2,12 @@ services:
traefik:
image: public.ecr.aws/docker/library/traefik:3.5.3
container_name: borgmatic-docs-traefik
environment:
- PORT=${PORT:-8080}
command:
- "--global.checkNewVersion=false"
- "--global.sendAnonymousUsage=false"
- "--entrypoints.web.address=:8080"
- "--entrypoints.web.address=:${PORT}"
- "--accesslog"
- "--accesslog.fields.headers.defaultmode=keep"
- "--providers.docker"
@@ -14,7 +16,7 @@ services:
- "--api.dashboard=false"
- "--log.level=WARN"
ports:
- "127.0.0.1:8080:8080"
- "127.0.0.1:${PORT}:${PORT}"
volumes:
- ${CONTAINER_SOCKET_PATH:-/run/user/docker.sock}:/var/run/docker.sock:ro
docs:
@@ -37,6 +39,9 @@ services:
context: ..
args:
ENVIRONMENT: development
PORT: ${PORT:-8080}
environment:
- PORT=${PORT:-8080}
message:
image: alpine
container_name: borgmatic-docs-message
@@ -44,6 +49,6 @@ services:
- sh
- -c
- |
echo; echo "You can view dev docs at http://localhost:8080/borgmatic/"; echo
echo; echo "You can view dev docs at http://localhost:${PORT}/borgmatic/"; echo
depends_on:
- docs
+23 -2
View File
@@ -190,8 +190,28 @@ This requires Docker (or Podman; see below) to be installed on your system.
This script assumes you have permission to run `docker`. If you don't, then
you may need to run with `sudo`.
### How to choose a different port
You can choose a different listening port in two ways:
#### 1. Modify the `.env` file
1. Open `docs/.env`.
2. Change `PORT=8080` to your desired port number (e.g., `PORT=3000`).
3. Run the development script: `scripts/dev-docs`.
#### 2. Use an environment variable
Alternatively, you can override the port directly from your terminal without
modifying any files:
```bash
PORT=3000 ./scripts/dev-docs
```
After you run the script, you can point your web browser at
http://localhost:8080/borgmatic/ to view the documentation with your changes.
http://localhost:8080/borgmatic/ (or your chosen port) to view the documentation
with your changes.
To close the documentation server, ctrl-C the script. Note that it does not
currently auto-reload, so you'll need to stop it and re-run it for any
@@ -206,7 +226,8 @@ borgmatic's developer build for documentation optionally supports using
Setting up Podman is outside the scope of this documentation. But once you
install and configure Podman, then `scripts/dev-docs` should automatically use
Podman instead of Docker.
Podman instead of Docker (make sure you have
[`podman-compose`](https://github.com/containers/podman-compose) installed).
## Use of generative AI
+6 -6
View File
@@ -2,11 +2,11 @@
set -e
USER_PODMAN_SOCKET_PATH=/run/user/$UID/podman/podman.sock
if [ -e "$USER_PODMAN_SOCKET_PATH" ]; then
export DOCKER_HOST="unix://$USER_PODMAN_SOCKET_PATH"
export CONTAINER_SOCKET_PATH="$USER_PODMAN_SOCKET_PATH"
if command -v podman-compose >/dev/null 2>&1; then
COMPOSE_CMD="podman-compose"
export CONTAINER_SOCKET_PATH="${XDG_RUNTIME_DIR:-/run/user/$UID}/podman/podman.sock"
else
COMPOSE_CMD="docker-compose"
fi
BUILDKIT_PROGRESS=plain docker-compose --file docs/docker-compose.yaml up --build --force-recreate
BUILDKIT_PROGRESS=plain $COMPOSE_CMD --file docs/docker-compose.yaml up --build --force-recreate