mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
Moved the workspace to the root, Added the build scripts, ARM64 releases and the Docker image
Source/'s content is at the root now, Source/README.md merged into readme.md. Scripts at the root: build.ps1, test.ps1 (was check.ps1), release.ps1 (over release.py) and clean.ps1. Everything is LF except the .ps1 files. CI (.github/workflows/ci.yml) runs on a v* tag or by hand: the checks, then a release for Windows x64 and ARM64 and Linux x64 and ARM64, each on its own kind of runner, the archives kept as artifacts. release.py names the platform from the Rust host, make_wheel.py tags the wheel from the library's header. docker/: the server's image (built from source, the tools beside it, uid 10001), compose.yml and test.sh. CI builds amd64 and arm64 natively, checks them, and on a tag pushes them to ghcr.io with an index for <version> and latest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
# The BakaShrot server's image: bakashrot-server, with the bakashrot and
|
||||
# bakashrot-cert tools beside it. Built from the repository's root:
|
||||
# docker build -f docker/Dockerfile -t bakashrot-server .
|
||||
# CI builds it for amd64 and arm64 on a version tag, checks it
|
||||
# (docker/test.sh) and pushes it to ghcr.io/aziascreations/bakashrot-server
|
||||
# (.github/workflows/ci.yml).
|
||||
#
|
||||
# The config goes in /etc/bakashrot (read-only: server.toml, the CA's
|
||||
# certificate, the server's certificate and key, the CRL if any), the
|
||||
# database in /var/lib/bakashrot (a volume). In server.toml:
|
||||
# listen = "0.0.0.0:7000" every interface: 127.0.0.1 isn't reachable
|
||||
# from outside the container
|
||||
# database = "/var/lib/bakashrot/bakashrot.sqlite"
|
||||
# and the certificates relative to it (ca = "ca.crt", ...). The server runs
|
||||
# as uid 10001, which must be able to read its key (bakashrot-cert writes
|
||||
# keys readable by their owner only): chown 10001:10001 config/server-1.key
|
||||
#
|
||||
# docker run -d --name bakashrot -p 7000:7000 \
|
||||
# -v ./config:/etc/bakashrot:ro -v bakashrot-data:/var/lib/bakashrot \
|
||||
# ghcr.io/aziascreations/bakashrot-server
|
||||
#
|
||||
# Or docker/compose.yml. `docker stop` stops it cleanly (SIGTERM).
|
||||
# The tools: docker run --rm <image> bakashrot-cert ... (or bakashrot ...).
|
||||
|
||||
|
||||
# --- Build ---------------------------------------------------------------------
|
||||
|
||||
FROM rust:1-slim-trixie AS build
|
||||
|
||||
WORKDIR /src
|
||||
# Only what the programs are built from (Dockerfile.dockerignore).
|
||||
COPY . .
|
||||
# The toolchain rust-toolchain.toml pins, then the release build.
|
||||
RUN rustup toolchain install \
|
||||
&& cargo build --release --locked -p bakashrot-server -p bakashrot-tools \
|
||||
&& mkdir /out \
|
||||
&& cp target/release/bakashrot-server target/release/bakashrot target/release/bakashrot-cert /out/
|
||||
|
||||
|
||||
# --- Runtime -------------------------------------------------------------------
|
||||
|
||||
# The same Debian as the build: the programs only need its glibc.
|
||||
FROM debian:trixie-slim
|
||||
|
||||
# The source label links the package to the repository on ghcr.io. CI
|
||||
# pushes each architecture's image as is, then an index of both with the
|
||||
# same as annotations: GitHub reads those on an index.
|
||||
LABEL org.opencontainers.image.source="https://github.com/aziascreations/BakaShrot" \
|
||||
org.opencontainers.image.description="BakaShrot server" \
|
||||
org.opencontainers.image.licenses="CC0-1.0"
|
||||
|
||||
RUN groupadd --system --gid 10001 bakashrot \
|
||||
&& useradd --system --uid 10001 --gid 10001 --home-dir /var/lib/bakashrot --shell /usr/sbin/nologin bakashrot \
|
||||
&& mkdir -p /etc/bakashrot /var/lib/bakashrot \
|
||||
&& chown bakashrot:bakashrot /var/lib/bakashrot
|
||||
|
||||
COPY --from=build /out/ /usr/local/bin/
|
||||
|
||||
USER bakashrot
|
||||
WORKDIR /var/lib/bakashrot
|
||||
VOLUME /var/lib/bakashrot
|
||||
EXPOSE 7000
|
||||
|
||||
CMD ["bakashrot-server", "/etc/bakashrot/server.toml"]
|
||||
@@ -0,0 +1,8 @@
|
||||
# Only what the programs are built from: target/ alone can hold gigabytes
|
||||
# of builds and test databases, and keys.
|
||||
*
|
||||
!Cargo.toml
|
||||
!Cargo.lock
|
||||
!rust-toolchain.toml
|
||||
!.cargo
|
||||
!crates
|
||||
@@ -0,0 +1,27 @@
|
||||
# BakaShrot's server with docker compose, from this folder:
|
||||
# docker compose up -d pulls the image (--build: builds it here)
|
||||
# docker compose logs -f
|
||||
# docker compose down stops it cleanly (SIGTERM)
|
||||
#
|
||||
# config/, next to this file: server.toml, ca.crt, the server's certificate
|
||||
# and key, the CRL if any (the Dockerfile says what server.toml needs; its
|
||||
# key readable by uid 10001). The database lives in the bakashrot-data
|
||||
# volume, kept by `down` (`down -v` deletes it).
|
||||
|
||||
services:
|
||||
bakashrot:
|
||||
image: ghcr.io/aziascreations/bakashrot-server:latest
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: docker/Dockerfile
|
||||
container_name: bakashrot
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
# server.toml's listen port.
|
||||
- "7000:7000"
|
||||
volumes:
|
||||
- ./config:/etc/bakashrot:ro
|
||||
- bakashrot-data:/var/lib/bakashrot
|
||||
|
||||
volumes:
|
||||
bakashrot-data:
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/bin/sh
|
||||
# Smoke-tests a server image, as CI does before pushing it: certificates by
|
||||
# its bakashrot-cert, its server started with them, its bakashrot pushing
|
||||
# and reading back over a Docker network, then `docker stop`, which must
|
||||
# end it cleanly (exit code 0, "stopped").
|
||||
# Usage: docker/test.sh <image>
|
||||
set -eu
|
||||
image=$1
|
||||
name=bakashrot-test-$$
|
||||
work=$(mktemp -d)
|
||||
# The image's user (10001) writes the certificates there.
|
||||
chmod 777 "$work"
|
||||
|
||||
cleanup() {
|
||||
docker rm -f -v "$name" >/dev/null 2>&1 || true
|
||||
docker network rm "$name" >/dev/null 2>&1 || true
|
||||
rm -rf "$work"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
fail() {
|
||||
echo "FAILED: $1"
|
||||
docker logs "$name" 2>&1 || true
|
||||
exit 1
|
||||
}
|
||||
tool() {
|
||||
docker run --rm -v "$work:/w" -w /w --network "$name" "$image" "$@"
|
||||
}
|
||||
|
||||
docker network create "$name" >/dev/null
|
||||
tool bakashrot-cert ca --name "Image test CA"
|
||||
tool bakashrot-cert issue --name server-1 --server
|
||||
tool bakashrot-cert issue --name tester --role tester
|
||||
cat >"$work/server.toml" <<EOF
|
||||
[server]
|
||||
listen = "0.0.0.0:7000"
|
||||
ca = "ca.crt"
|
||||
certificate = "server-1.crt"
|
||||
key = "server-1.key"
|
||||
database = "/var/lib/bakashrot/test.sqlite"
|
||||
topics = ["imagetest"]
|
||||
|
||||
[roles.tester]
|
||||
push_topics = ["imagetest"]
|
||||
read_topics = ["*"]
|
||||
EOF
|
||||
cat >"$work/client.toml" <<EOF
|
||||
server = "$name:7000"
|
||||
ca = "ca.crt"
|
||||
certificate = "tester.crt"
|
||||
key = "tester.key"
|
||||
EOF
|
||||
|
||||
docker run -d --name "$name" --network "$name" -v "$work:/etc/bakashrot:ro" "$image" >/dev/null
|
||||
tries=0
|
||||
until docker logs "$name" 2>&1 | grep -q "listening on"; do
|
||||
tries=$((tries + 1))
|
||||
[ "$tries" -lt 100 ] || fail "the server isn't listening"
|
||||
[ "$(docker inspect -f '{{.State.Running}}' "$name")" = true ] || fail "the server exited"
|
||||
sleep 0.2
|
||||
done
|
||||
|
||||
tool bakashrot push imagetest '{"image":"test"}' | grep -q "message #1" || fail "push"
|
||||
tool bakashrot messages imagetest tester | grep -q '"image":"test"' || fail "messages"
|
||||
|
||||
docker stop "$name" >/dev/null
|
||||
[ "$(docker inspect -f '{{.State.ExitCode}}' "$name")" = 0 ] || fail "the server's exit code"
|
||||
docker logs "$name" 2>&1 | grep -q "stopped" || fail "no clean stop"
|
||||
echo "The image: certificates, the server, a push read back, a clean stop: OK"
|
||||
Reference in New Issue
Block a user