Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ name: Docker
on:
push:
tags: ["v*"]
pull_request:
branches: [main]
workflow_dispatch:

permissions:
Expand All @@ -23,7 +25,70 @@ env:
IMAGE_NAME: kolektiv/kalendee

jobs:
pack-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up pnpm
uses: pnpm/action-setup@v4
with:
version: 11.25.0

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
cache-dependency-path: server/pack/pnpm-lock.yaml

- name: Install pack dependencies
run: pnpm --dir server/pack install --frozen-lockfile

- name: Check page context bindings
run: node scripts/check-page-context.mjs

flake-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Install Nix
uses: cachix/install-nix-action@v31

- name: Check flake
run: scripts/check-flake.sh

smoke-image:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v7

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build runtime image
uses: docker/build-push-action@v6
with:
context: .
target: runtime
platforms: linux/amd64
load: true
push: false
tags: kalendee-smoke:ci
build-args: VERSION=ci
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Smoke test the image
run: IMAGE_TAG=kalendee-smoke:ci scripts/smoke-image.sh --no-build

docker:
if: github.event_name != 'pull_request'
needs: [pack-check, flake-check, smoke-image]
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
11 changes: 11 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This is a Kotlin Multiplatform project targeting Android, iOS, Desktop (JVM), an
- [Demo data and screenshots](#demo-data-and-screenshots)
- [Docker](#docker)
- [NixOS](#nixos)
- [Pre-publish verification](#pre-publish-verification)
- [Releasing](#releasing)
- [Running tests](#running-tests)
- [Troubleshooting](#troubleshooting)
Expand Down Expand Up @@ -318,6 +319,16 @@ Configuration is HOCON-file-first there too: `configFile` mounts an operator-man

Options: `enable` (bool), `image` (`docker.yuri.capital/kolektiv/kalendee`), `imageTag` (`latest`; pin a release for reproducibility), `port` (8080; host port to container 8080), `publicUrl` (exported as `KALENDEE_PUBLIC_URL`), `configFile` (HOCON file mounted read-only at `/config/application.conf` and exported as `KALENDEE_CONFIG`; it is copied into the Nix store, so never put secrets in it — start from [`application.conf.example`](./application.conf.example)), `environment` (extra non-secret variables), `environmentFile` (runtime secrets file; never put secrets in the Nix store), `volumes` (extra mounts; a named volume `kalendee-data` is always mounted at `/data`), `extraOptions` (podman/docker flags), and `openFirewall`. Podman is the default container backend; set `virtualisation.oci-containers.backend = "docker";` for Docker. Plain-HTTP deployments need `KALENDEE_COOKIE_SECURE = "false"` via `environment`.

## Pre-publish verification

Run `scripts/pre-publish-checks.sh` before publishing. It runs, in order:

- `scripts/check-page-context.mjs` — static guard for the v0.2.0 `+page.svelte` bug class: a template that uses `ctx` while the script never binds the `page<...>()` return value. `pnpm typecheck` only covers `.ts` files and `vite build` happily bundles the broken page, so this inspects the page templates directly.
- `scripts/check-flake.sh` — `nix flake check --no-build` then `nix flake show`; requires Nix (install it or skip this check).
- `scripts/smoke-image.sh` — builds the Dockerfile's `runtime` stage, boots it with a disposable PostgreSQL, then checks `/api/v1/health`, the `/login` HTML shell, the served `bootstrap.js` and `kalendee.login.js` pack modules, an end-to-end admin login, and an authenticated `/api/v1/calendars` fetch. Prerequisites: docker and curl. `--no-build` reuses `IMAGE_TAG` (default `kalendee-smoke:local`) instead of building; `--keep` leaves the containers and network up on failure for debugging; `HOST_PORT` (default `18080`) and `PG_IMAGE` (default `postgres:17-alpine`) are configurable.

`.github/workflows/docker.yml` runs all three gates (`pack-check`, `flake-check`, `smoke-image`) before the multi-arch build and push, so nothing is published unless they pass.

## Releasing

Pushing a `v*` tag runs both release workflows; the version is the tag without the leading `v`:
Expand Down
19 changes: 19 additions & 0 deletions scripts/check-flake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Evaluate the Nix flake the way a consumer would: check it, then show it.
#
# Prerequisites: nix with flakes enabled (install Nix or skip this check).
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"

if ! command -v nix >/dev/null 2>&1; then
echo "check-flake: nix is not installed; install Nix or skip this check" >&2
exit 1
fi

echo "==> nix flake check --no-build"
nix flake check --no-build

echo "==> nix flake show"
nix flake show
55 changes: 55 additions & 0 deletions scripts/check-page-context.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node
// Guard against the v0.2.0 `/login` crash class: a page component that uses
// `ctx` in its template but never binds the `page<...>()` return value, so the
// rendered page throws at runtime. `pnpm typecheck` only runs tsc over `.ts`
// files, and `vite build` happily bundles the broken component, so this check
// walks every `+page.svelte` template itself.
//
// Run from anywhere: `node scripts/check-page-context.mjs`.

import { readdirSync, readFileSync, statSync } from "node:fs"
import { dirname, join, relative, resolve } from "node:path"
import { fileURLToPath } from "node:url"

const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..")
const pagesRoot = join(repoRoot, "server/pack/src/pages")

const templateUsesCtx = /(?<![\w$.])ctx\b/
const scriptBindsCtx = /^\s*(?:const|let|var)\s+ctx\s*(?::[^=\n]+)?=/m

function findPages(dir) {
const pages = []
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const path = join(dir, entry.name)
if (entry.isDirectory()) pages.push(...findPages(path))
else if (entry.name === "+page.svelte") pages.push(path)
}
return pages
}

if (!statSync(pagesRoot, { throwIfNoEntry: false })?.isDirectory()) {
console.error(`page-context guard: no pages directory at ${relative(repoRoot, pagesRoot)}`)
process.exit(1)
}

const offenders = []
const pages = findPages(pagesRoot)

for (const file of pages) {
const source = readFileSync(file, "utf8")
const scriptEnd = source.lastIndexOf("</script>")
const script = scriptEnd === -1 ? "" : source.slice(0, scriptEnd)
const template = scriptEnd === -1 ? source : source.slice(scriptEnd + "</script>".length)
if (!templateUsesCtx.test(template)) continue
if (!scriptBindsCtx.test(script)) offenders.push(relative(repoRoot, file))
}

if (offenders.length > 0) {
console.error("page-context guard failed:")
for (const file of offenders) {
console.error(`${file}: template uses ctx but the script does not bind the page() return value`)
}
process.exit(1)
}

console.log(`page-context guard: ${pages.length} page components checked; every ctx reference is bound`)
40 changes: 40 additions & 0 deletions scripts/pre-publish-checks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Run every pre-publish gate in order. Used locally and by the Docker workflow
# before the runtime image is pushed.
#
# Usage:
# scripts/pre-publish-checks.sh [--no-build]
#
# --no-build forwarded to scripts/smoke-image.sh (reuse an existing image)
# SMOKE_ARGS extra arguments forwarded to scripts/smoke-image.sh
set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"

smoke_args=()
for arg in "$@"; do
case "$arg" in
--no-build) smoke_args+=("$arg") ;;
*)
echo "pre-publish-checks: unknown argument: $arg (expected --no-build)" >&2
exit 2
;;
esac
done
if [ -n "${SMOKE_ARGS:-}" ]; then
# Deliberately word-split: SMOKE_ARGS is a space-separated list of flags.
read -r -a extra_args <<<"$SMOKE_ARGS"
smoke_args+=("${extra_args[@]}")
fi

echo "==> pack page-context guard"
node scripts/check-page-context.mjs

echo "==> flake check"
scripts/check-flake.sh

echo "==> runtime image smoke test"
scripts/smoke-image.sh ${smoke_args[@]+"${smoke_args[@]}"}

echo "pre-publish-checks: all gates passed"
Loading
Loading