From cbda62f046a399ce7d8ece8989109cd520b8df1f Mon Sep 17 00:00:00 2001 From: Tom Scott Date: Sat, 22 Nov 2025 20:49:51 -0500 Subject: [PATCH] add build stage for the spindle server --- Dockerfile | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 004ea33..9d4d381 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ from golang:1.24-alpine as builder -env KNOT_REPO_SCAN_PATH=/home/git/repositories env CGO_ENABLED=1 arg TAG='v1.10.0-alpha' @@ -7,9 +6,15 @@ arg TAG='v1.10.0-alpha' workdir /app run apk add git gcc musl-dev run git clone -b ${TAG} https://tangled.org/@tangled.org/core . -run go build -o /usr/bin/knot -ldflags '-s -w -extldflags "-static"' ./cmd/knot -from alpine:edge +FROM builder AS build-knot +RUN go build -o /usr/bin/knot -ldflags '-s -w -extldflags "-static"' ./cmd/knot + +FROM builder AS build-spindle +RUN go build -o /usr/bin/spindle ./cmd/spindle + +from alpine:edge AS knot +ENV KNOT_REPO_SCAN_PATH=/home/git/repositories expose 5555 expose 22 @@ -31,10 +36,34 @@ run groupadd -g $GID -f git run useradd -u $UID -g $GID -d /home/git git run openssl rand -hex 16 | passwd --stdin git run mkdir -p /home/git/repositories && chown -R git:git /home/git -copy --from=builder /usr/bin/knot /usr/bin +copy --from=build-knot /usr/bin/knot /usr/bin run mkdir /app && chown -R git:git /app healthcheck --interval=60s --timeout=30s --start-period=5s --retries=3 \ cmd curl -f http://localhost:5555 || exit 1 - entrypoint ["/init"] + +FROM alpine:edge AS spindle +EXPOSE 6555 + +LABEL org.opencontainers.image.title="spindle" +LABEL org.opencontainers.image.description="ci server for tangled" +LABEL org.opencontainers.image.source="https://tangled.org/@tangled.org/knot-docker" +LABEL org.opencontainers.image.url="https://tangled.org" +LABEL org.opencontainers.image.vendor="tangled.org" +LABEL org.opencontainers.image.licenses="MIT" + +ARG UID=1000 +ARG GID=1000 + +RUN groupadd --system -g $GID -f spindle +RUN useradd --system -u $UID -g $GID spindle +RUN mkdir -p /app && chown -R spindle:spindle /app + +COPY --from=build-spindle /usr/bin/spindle /usr/bin + +WORKDIR /app +CMD ["spindle"] +VOLUME ["/app"] +HEALTHCHECK --interval=60s --timeout=30s --start-period=5s --retries=3 \ + CMD curl -f http://localhost:6555 || exit 1 -- 2.43.0 From f8140b9fd173176bb20b2d6d5f39594622781c5e Mon Sep 17 00:00:00 2001 From: Tom Scott Date: Sat, 22 Nov 2025 21:13:39 -0500 Subject: [PATCH] bump tag to v1.11.0 in Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9d4d381..1639470 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ from golang:1.24-alpine as builder env CGO_ENABLED=1 -arg TAG='v1.10.0-alpha' +arg TAG='v1.11.0-alpha' workdir /app run apk add git gcc musl-dev -- 2.43.0 From 982d224c272cf1b95b1cb47d405d74ae93870f9a Mon Sep 17 00:00:00 2001 From: Tom Scott Date: Sat, 22 Nov 2025 21:14:04 -0500 Subject: [PATCH] add spindle to docker-compose and configure builds for each image --- docker-compose.yml | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 558b19f..9bd1d36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,16 @@ +name: tangled services: knot: + image: tngl/knot:latest build: - context: . + target: knot args: UID: 1000 GID: 1000 + TAG: ${TAG:-v1.11.0-alpha} + tags: + - tngl/spindle:latest + - tngl/spindle:${TAG:-v1.11.0-alpha} environment: KNOT_SERVER_HOSTNAME: ${KNOT_SERVER_HOSTNAME} KNOT_SERVER_OWNER: ${KNOT_SERVER_OWNER} @@ -19,15 +25,35 @@ services: - "5555:5555" - "2222:22" restart: always + spindle: + image: tngl/spindle:latest + build: + target: spindle + args: + UID: 1000 + GID: 1000 + TAG: ${TAG:-v1.11.0-alpha} + tags: + - tngl/spindle:latest + - tngl/spindle:${TAG:-v1.11.0-alpha} + environment: + SPINDLE_SERVER_HOSTNAME: ${SPINDLE_SERVER_HOSTNAME} + SPINDLE_SERVER_OWNER: ${KNOT_SERVER_OWNER} + volumes: + - ./logs:/var/log/spindle + - ./spindle:/app + ports: + - "6555:6555" frontend: image: caddy:alpine - command: > - caddy - reverse-proxy - --from ${KNOT_SERVER_HOSTNAME} - --to knot:5555 depends_on: - - knot + knot: + condition: service_healthy + spindle: + condition: service_healthy + configs: + - source: caddyfile + target: /etc/caddy/Caddyfile ports: - ${KNOT_SERVER_PORT:-443}:443 - ${KNOT_SERVER_PORT:-443}:443/udp @@ -35,3 +61,8 @@ services: - ./caddy_data:/data restart: always profiles: ["caddy"] +configs: + caddyfile: + content: | + ${KNOT_SERVER_HOSTNAME} { reverse_proxy knot:5555 } + ${SPINDLE_SERVER_HOSTNAME} { reverse_proxy spindle:6555 } -- 2.43.0 From e06b78fb97eeea6ddf2efcd82af0b9b619125702 Mon Sep 17 00:00:00 2001 From: Tom Scott Date: Sat, 22 Nov 2025 21:14:18 -0500 Subject: [PATCH] add docker bake config for building edge releases --- docker-bake.hcl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 docker-bake.hcl diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000..cfd0824 --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,19 @@ +group "edge" { + targets = ["knot-edge", "spindle-edge"] +} + +target "knot-edge" { + context = "." + args = { + TAG = "master" + } + tags = ["tngl/knot:edge"] +} + +target "spindle-edge" { + context = "." + args = { + TAG = "master" + } + tags = ["tngl/spindle:edge"] +} -- 2.43.0 From 3aea6d5a3437016a2f28e2e02b15bf9b4cbad56a Mon Sep 17 00:00:00 2001 From: Tom Scott Date: Sat, 22 Nov 2025 21:14:35 -0500 Subject: [PATCH] update readme to reference the spindle and document how to build images using docker bake --- readme.md | 57 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/readme.md b/readme.md index 11f7a33..cd73ede 100644 --- a/readme.md +++ b/readme.md @@ -4,42 +4,69 @@ > This is a community maintained repository, support is not guaranteed. Docker container and compose setup to run a [Tangled](https://tangled.org) knot -and host your own repository data. +and spindle, hosting your own repository data and CI. ## Pre-built Images -There is a [repository](https://hub.docker.com/r/tngl/knot) of pre-built images +There is a [repository](https://hub.docker.com/r/tngl) of pre-built images for tags starting at `v1.8.0-alpha` if you prefer. ``` docker pull tngl/knot:v1.10.0-alpha +docker pull tngl/spindle:v1.10.0-alpha ``` Note that these are *not* official images, you use them at your own risk. -## Building The Image +## Building The Images + +Both the knot and spindle images are built using the same `Dockerfile`, since +they're sourced from the same codebase and can therefore share a lot of the +build steps (such as `go mod download`), caching results between them. You +can build the images locally by running `docker bake`: + +```sh +docker bake +``` + +Optionally, choose a target image to build: + +```sh +docker bake knot +docker bake spindle +``` By default the `Dockerfile` will build the latest tag, but you can change it with the `TAG` build argument. ```sh -docker build -t knot:latest --build-arg TAG=master . +docker bake --build-arg TAG=v1.10.0-alpha ``` -The command above for example will build the latest commit on the `master` -branch. +The command above for example will build the `v1.10.0-alpha` tag. -By default it will also create a `git` user with user and group ID 1000:1000, +By default it will also create a `git` / `spindle` user with user and group ID 1000:1000, but you can change it with the `UID` and `GID` build arguments. ```sh -docker build -t knot:latest --build-arg UID=$(id -u) GID=$(id -g) +docker bake --build-arg UID=$(id -u) --build-arg GID=$(id -g) ``` The command above for example will create a user with the host user's UID and GID. This is useful if you are bind mounting the repositories and app folder on the host, as in the provided `docker-compose.yml` file. +You can also build the latest commit on `master` for both services by using +the `-edge` targets. These will build to a tag named `:edge` to distinguish +it from the `:latest` release: + +```sh +docker bake edge +# or, with a specific target image +docker bake edge-knot +docker bake edge-spindle +``` +
When using compose, these can be specified as build arguments which will be @@ -59,14 +86,16 @@ the command. ## Setting Up The Image -The simplest way to set up your own knot is to use the provided compose file -and run the following: +The simplest way to set up your own knot and spindle is to use the provided +compose file and run the following: ```sh -export KNOT_SERVER_HOSTNAME=example.com -export KNOT_SERVER_OWNER=did:plc:yourdidgoeshere -export KNOT_SERVER_PORT=443 -docker compose up -d +export KNOT_SERVER_HOSTNAME="knot.example.com" +export SPINDLE_SERVER_HOSTNAME="spindle.example.com" +export KNOT_SERVER_OWNER="did:plc:yourdidgoeshere" +export KNOT_SERVER_PORT="443" + +docker compose up --detach ``` This will setup everything for you including a reverse proxy. -- 2.43.0 From 864829a374d88402a1ddfbdbc2830765ed540ca5 Mon Sep 17 00:00:00 2001 From: Tom Scott Date: Sat, 22 Nov 2025 21:21:01 -0500 Subject: [PATCH] fix adduser/group commands in spindle stage --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1639470..48a9ac3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,8 +56,8 @@ LABEL org.opencontainers.image.licenses="MIT" ARG UID=1000 ARG GID=1000 -RUN groupadd --system -g $GID -f spindle -RUN useradd --system -u $UID -g $GID spindle +RUN adduser --system --uid $UID spindle +RUN addgroup --system --gid $UID spindle RUN mkdir -p /app && chown -R spindle:spindle /app COPY --from=build-spindle /usr/bin/spindle /usr/bin -- 2.43.0