uptimesebi-checker and uptimesebi-statuspage for linux/amd64, arm64, arm/v7 and arm/v6, from a Raspberry Pi Zero to servers. tools/image assembles them from the cross-compiled binaries without Docker or emulation: one layer on an empty base with the binary, a data volume owned by the unprivileged user and a HEALTHCHECK running the new `checker health` / `statuspage health` commands. The binaries embed time zone data and fallback CA roots, so no base image ever needs updating. CI pushes them with the same channel tags as the main image; releases carry tarballs for all four platforms. Refs #128 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
236 lines
10 KiB
YAML
236 lines
10 KiB
YAML
name: ci
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
tags: ["v*"]
|
|
pull_request:
|
|
|
|
concurrency:
|
|
group: ci-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
GOLANGCI_LINT_VERSION: v2.15.0
|
|
SQLC_VERSION: v1.31.1
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
# The runners are ephemeral and clone every action from GitHub, which
|
|
# takes minutes; Go comes as a tarball instead, and the job image
|
|
# already has the Node version the frontend build needs.
|
|
- name: Install Go
|
|
run: |
|
|
v="$(awk '/^go /{print $2}' go.mod)"
|
|
curl -fsSL "https://go.dev/dl/go${v}.linux-amd64.tar.gz" | tar -C /usr/local -xz
|
|
echo /usr/local/go/bin >> "$GITHUB_PATH"
|
|
echo "$HOME/go/bin" >> "$GITHUB_PATH"
|
|
- name: Build frontend
|
|
run: npm ci --no-audit --no-fund && npm run build
|
|
- name: Generated code is up to date
|
|
run: |
|
|
go tool templ generate
|
|
# The release binary avoids compiling sqlc's cgo parser.
|
|
curl -fsSL "https://github.com/sqlc-dev/sqlc/releases/download/${SQLC_VERSION}/sqlc_${SQLC_VERSION#v}_linux_amd64.tar.gz" | tar -xz -C /usr/local/bin sqlc
|
|
sqlc generate
|
|
git diff --exit-code -- '*.go'
|
|
- name: gofmt
|
|
run: test -z "$(gofmt -l internal cmd)" || { gofmt -l internal cmd; exit 1; }
|
|
- name: go vet
|
|
run: go vet ./...
|
|
- name: golangci-lint
|
|
run: |
|
|
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_LINT_VERSION}
|
|
"$(go env GOPATH)/bin/golangci-lint" run ./...
|
|
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
services:
|
|
timescaledb:
|
|
image: timescale/timescaledb:2.30.1-pg16
|
|
env:
|
|
POSTGRES_PASSWORD: postgres
|
|
redis:
|
|
image: redis:8-alpine
|
|
# Targets of the database checks; SQL Server is left to local runs,
|
|
# its image is too large for ephemeral runners.
|
|
mariadb:
|
|
image: mariadb:11@sha256:e1d5495f445654134f226f55a41ce0da227116f6f27f283101f405c794d841fc
|
|
env:
|
|
MARIADB_ROOT_PASSWORD: checkpw
|
|
MARIADB_DATABASE: shop
|
|
options: --health-cmd "healthcheck.sh --connect" --health-interval 2s --health-retries 60
|
|
mongo:
|
|
image: mongo:8
|
|
env:
|
|
MONGO_INITDB_ROOT_USERNAME: root
|
|
MONGO_INITDB_ROOT_PASSWORD: checkpw
|
|
rabbitmq:
|
|
image: rabbitmq:4-alpine
|
|
env:
|
|
RABBITMQ_DEFAULT_USER: check
|
|
RABBITMQ_DEFAULT_PASS: checkpw
|
|
kafka:
|
|
image: apache/kafka-native:4.4.0@sha256:11fde816adf384402de9f3e57aeaf2c3722ba0671610247817688d07441714b4
|
|
env:
|
|
KAFKA_NODE_ID: 1
|
|
KAFKA_PROCESS_ROLES: broker,controller
|
|
KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
|
|
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
|
|
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
|
|
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
|
|
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
|
|
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
|
|
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
|
|
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
|
|
env:
|
|
UPTIME_TEST_DATABASE_URL: postgres://uptime:uptime@timescaledb:5432/uptime_test?sslmode=disable
|
|
UPTIME_TEST_REDIS_URL: redis://redis:6379/15
|
|
UPTIME_TEST_MYSQL_ADDR: mariadb:3306
|
|
UPTIME_TEST_MONGO_ADDR: mongo:27017
|
|
UPTIME_TEST_RABBITMQ_ADDR: rabbitmq:5672
|
|
UPTIME_TEST_KAFKA_ADDR: kafka:9092
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
# The runners are ephemeral and clone every action from GitHub, which
|
|
# takes minutes; Go comes as a tarball instead, and the job image
|
|
# already has the Node version the frontend build needs.
|
|
- name: Install Go
|
|
run: |
|
|
v="$(awk '/^go /{print $2}' go.mod)"
|
|
curl -fsSL "https://go.dev/dl/go${v}.linux-amd64.tar.gz" | tar -C /usr/local -xz
|
|
echo /usr/local/go/bin >> "$GITHUB_PATH"
|
|
echo "$HOME/go/bin" >> "$GITHUB_PATH"
|
|
- name: Build frontend
|
|
run: npm ci --no-audit --no-fund && npm run build
|
|
- name: Prepare database
|
|
# The same roles and databases as the local environment: the
|
|
# application role must not be a superuser, or row-level security
|
|
# is bypassed and the isolation tests prove nothing.
|
|
run: go run ./internal/devtools/pginit "postgres://postgres:postgres@timescaledb:5432/postgres?sslmode=disable" deploy/dev/postgres-init.sql
|
|
- name: Test
|
|
# Integration tests share one database, so packages run one at a time.
|
|
run: go test -p 1 -count=1 ./...
|
|
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
# The runners are ephemeral and clone every action from GitHub, which
|
|
# takes minutes; Go comes as a tarball instead, and the job image
|
|
# already has the Node version the frontend build needs.
|
|
- name: Install Go
|
|
run: |
|
|
v="$(awk '/^go /{print $2}' go.mod)"
|
|
curl -fsSL "https://go.dev/dl/go${v}.linux-amd64.tar.gz" | tar -C /usr/local -xz
|
|
echo /usr/local/go/bin >> "$GITHUB_PATH"
|
|
echo "$HOME/go/bin" >> "$GITHUB_PATH"
|
|
- name: Build frontend
|
|
run: npm ci --no-audit --no-fund && npm run build
|
|
- name: Build binaries
|
|
run: |
|
|
set -eu
|
|
pkg=git.zb-server.de/ZB-Server/uptimesebi/internal/buildinfo
|
|
case "$GITHUB_REF" in
|
|
refs/tags/v*) version="$GITHUB_REF_NAME" ;;
|
|
*) version="$(git log -1 --format=%cd --date=format:%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)" ;;
|
|
esac
|
|
echo "VERSION=$version" >> "$GITHUB_ENV"
|
|
for platform in linux/amd64 linux/arm64 linux/arm/v7 linux/arm/v6; do
|
|
IFS=/ read -r os arch variant <<< "$platform"
|
|
CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=${variant#v} go build -trimpath \
|
|
-ldflags "-s -w -X $pkg.Version=$version -X $pkg.Commit=$(git rev-parse --short=12 HEAD)" \
|
|
-o "dist/$(echo "$platform" | tr / _)/" ./cmd/...
|
|
done
|
|
ls -lR dist
|
|
# Checker and status page images for every platform, assembled from the
|
|
# binaries above without Docker; pushed like the main image.
|
|
- name: Agent images
|
|
env:
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
run: |
|
|
set -eu
|
|
host="${GITHUB_SERVER_URL#*://}"
|
|
owner="$(printf '%s' "${GITHUB_REPOSITORY%/*}" | tr 'A-Z' 'a-z')"
|
|
flags="-version $VERSION -commit $GITHUB_SHA -ref $GITHUB_REF -created $(git log -1 --format=%ct) -source $GITHUB_SERVER_URL/$GITHUB_REPOSITORY"
|
|
case "$GITHUB_SERVER_URL" in http://*) flags="$flags -insecure" ;; esac
|
|
case "$GITHUB_REF" in
|
|
refs/heads/main|refs/tags/v*)
|
|
if [ -n "${PACKAGE_TOKEN:-}" ]; then flags="$flags -push"; else echo "PACKAGE_TOKEN is not set; building without pushing."; fi ;;
|
|
esac
|
|
export REGISTRY_USER="$GITHUB_ACTOR" REGISTRY_PASSWORD="${PACKAGE_TOKEN:-}"
|
|
go run ./tools/image -name checker -repo "$host/$owner/uptimesebi-checker" -port 8081/tcp $flags
|
|
go run ./tools/image -name statuspage -repo "$host/$owner/uptimesebi-statuspage" -port 8082/tcp \
|
|
-env UPTIME_STATUSPAGE_CACHE_DIR=/var/lib/uptimesebi $flags
|
|
|
|
image:
|
|
# Kaniko runs rootless from docker:cli, the same way as the other
|
|
# repositories on this instance: the default job image has no docker
|
|
# CLI, and Kaniko's own image lacks what the runner needs to keep a job
|
|
# container alive. Images are pushed only from main and tags, and only
|
|
# once the PACKAGE_TOKEN secret (write:package) exists.
|
|
runs-on: ubuntu-latest
|
|
container:
|
|
image: docker:cli@sha256:34507eb5069d8be82c95dd3b6987d4250fd5fee49b82e2509b7d7a7030740d6d
|
|
defaults:
|
|
run:
|
|
shell: sh
|
|
steps:
|
|
- name: Build (and push from main and tags)
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
PACKAGE_TOKEN: ${{ secrets.PACKAGE_TOKEN }}
|
|
run: |
|
|
set -eu
|
|
REGISTRY="${GITHUB_SERVER_URL#*://}"
|
|
IMAGE="$(printf '%s/%s' "$REGISTRY" "$GITHUB_REPOSITORY" | tr 'A-Z' 'a-z')"
|
|
SHORT="$(printf '%s' "$GITHUB_SHA" | cut -c1-12)"
|
|
case "$GITHUB_REF" in
|
|
refs/tags/v*) TAG="$GITHUB_REF_NAME" ;;
|
|
*) TAG="$(date -u +%Y%m%d%H%M%S)-$SHORT" ;;
|
|
esac
|
|
PUSH="--no-push"
|
|
DEST="--destination ${IMAGE}:${TAG#v}"
|
|
# Channels: edge follows main, beta the newest prerelease, latest
|
|
# and stable the newest release, X.Y its newest patch.
|
|
case "$GITHUB_REF" in
|
|
refs/heads/main) CHANNELS="edge" ;;
|
|
refs/tags/v*-beta.*) CHANNELS="beta" ;;
|
|
refs/tags/v*)
|
|
MINOR="$(printf '%s' "${TAG#v}" | cut -d. -f1-2)"
|
|
CHANNELS="latest stable $MINOR" ;;
|
|
esac
|
|
case "$GITHUB_REF" in
|
|
refs/heads/main|refs/tags/v*)
|
|
if [ -n "${PACKAGE_TOKEN:-}" ]; then
|
|
PUSH=""
|
|
for c in $CHANNELS; do DEST="$DEST --destination ${IMAGE}:$c"; done
|
|
else
|
|
echo "PACKAGE_TOKEN is not set; building without pushing."
|
|
fi ;;
|
|
esac
|
|
case "$GITHUB_SERVER_URL" in https://*) PULL=https ;; *) PULL=http ;; esac
|
|
# Pull requests are built from their head, which Gitea exposes as
|
|
# refs/pull/<n>/head.
|
|
REF="$GITHUB_REF"
|
|
case "$REF" in refs/pull/*/merge) REF="${REF%/merge}/head" ;; esac
|
|
AUTH="$(printf '%s:%s' "$GITHUB_ACTOR" "${PACKAGE_TOKEN:-none}" | base64 | tr -d '\n')"
|
|
CFG="$(printf '{"auths":{"%s":{"auth":"%s"}}}' "$REGISTRY" "$AUTH")"
|
|
docker run --rm \
|
|
-e GIT_PULL_METHOD="$PULL" \
|
|
-e GIT_USERNAME="x-access-token" \
|
|
-e GIT_PASSWORD="$GITEA_TOKEN" \
|
|
-e CFG="$CFG" \
|
|
--entrypoint /busybox/sh \
|
|
gcr.io/kaniko-project/executor:v1.23.2-debug \
|
|
-c 'mkdir -p /kaniko/.docker && printf %s "$CFG" > /kaniko/.docker/config.json && exec /kaniko/executor "$@"' _ \
|
|
--context "git://${REGISTRY}/${GITHUB_REPOSITORY}.git#${REF}" \
|
|
--dockerfile Dockerfile \
|
|
--build-arg VERSION="$TAG" \
|
|
--build-arg COMMIT="$SHORT" \
|
|
$DEST $PUSH \
|
|
--compressed-caching=false
|