From 7c3657d015e547b50eb9fed8f9b680dd7e0a503c Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 14 Nov 2026 17:25:11 +0100 Subject: [PATCH] Add versioning, release workflow and changelog Co-Authored-By: Claude Opus 5.5 --- .gitea/workflows/deploy.yml | 11 +- .gitea/workflows/release.yml | 110 ++++++++++++++++++ CHANGELOG.md | 33 ++++++ Directory.Build.props | 1 + Dockerfile | 3 +- README.md | 25 ++++ deploy/unraid/README.md | 28 ++++- deploy/unraid/compose.yaml | 3 +- src/Flypaper.Web/AppVersion.cs | 15 +++ .../Components/Layout/MainLayout.razor | 2 +- src/Flypaper.Web/Program.cs | 2 + 11 files changed, 222 insertions(+), 11 deletions(-) create mode 100644 .gitea/workflows/release.yml create mode 100644 CHANGELOG.md create mode 100644 src/Flypaper.Web/AppVersion.cs diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index bb69892..e8db5eb 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,6 +1,7 @@ # Builds the image on every push to main, pushes it to the Gitea registry (tagged -# :latest AND the short commit SHA, for rollback) and deploys the stack on Unraid -# from deploy/unraid/compose.yaml (Tom's personal Unraid setup). +# :main AND the short commit SHA, for rollback) and deploys the stack on Unraid +# from deploy/unraid/compose.yaml (Tom's personal Unraid setup). Releases (:latest, +# :X.Y.Z) come from version tags in release.yml and are never deployed here. # # The deploy works because the act_runner runs ON Unraid and hands its Docker # socket to the job: every `docker` command here talks to the Unraid daemon, so @@ -58,13 +59,15 @@ jobs: id: sha run: echo "short=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" - - name: Build and push (:latest and :) + - name: Build and push (:main and :) uses: docker/build-push-action@v6 with: context: . push: true + build-args: | + VERSION=0.0.0-dev+${{ steps.sha.outputs.short }} tags: | - ${{ env.IMAGE }}:latest + ${{ env.IMAGE }}:main ${{ env.IMAGE }}:${{ steps.sha.outputs.short }} deploy: diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..dd6a174 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,110 @@ +# Builds a release when a version tag (vX.Y.Z) is pushed: the image is tagged +# :X.Y.Z, :X.Y, :X and :latest in the Gitea registry, and a Gitea release is +# created with the matching section of CHANGELOG.md as notes. Nothing is +# deployed; Tom's Unraid follows :main through deploy.yml. +# +# A pre-release tag such as v0.2.0-rc.1 only gets its own :0.2.0-rc.1 tag and a +# release marked as pre-release; :latest and the short tags stay on the last +# stable version. +# +# Required repository secrets: REGISTRY_USER, REGISTRY_TOKEN (see deploy.yml). +# The release itself uses the job's built-in token. + +name: Release + +on: + push: + tags: ["v*"] + +env: + IMAGE: gitea.anticarnist.de/tom/flypaper + +jobs: + image: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + prerelease: ${{ steps.version.outputs.prerelease }} + steps: + - name: Check out the source + uses: actions/checkout@v4 + + - name: Read the version from the tag + id: version + run: | + version="${GITHUB_REF_NAME#v}" + if ! echo "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then + echo "Tag $GITHUB_REF_NAME is not vX.Y.Z" >&2 + exit 1 + fi + echo "version=$version" >> "$GITHUB_OUTPUT" + { + echo "tags<> "$GITHUB_OUTPUT" + case "$version" in + *-*) echo "prerelease=true" >> "$GITHUB_OUTPUT" ;; + *) echo "prerelease=false" >> "$GITHUB_OUTPUT" ;; + esac + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to the Gitea registry + uses: docker/login-action@v3 + with: + registry: gitea.anticarnist.de + username: ${{ secrets.REGISTRY_USER }} + password: ${{ secrets.REGISTRY_TOKEN }} + + - name: Build and push the release tags + uses: docker/build-push-action@v6 + with: + context: . + push: true + build-args: | + VERSION=${{ steps.version.outputs.version }} + tags: ${{ steps.version.outputs.tags }} + + release: + needs: image + runs-on: ubuntu-latest + steps: + - name: Check out the source + uses: actions/checkout@v4 + + # The notes are the CHANGELOG.md section of this version, from its heading + # up to the next one. If the API call fails, the images are still pushed; + # the release can then be created by hand (deploy/unraid/README.md). + - name: Create the Gitea release + env: + VERSION: ${{ needs.image.outputs.version }} + PRERELEASE: ${{ needs.image.outputs.prerelease }} + TOKEN: ${{ github.token }} + API: ${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases + run: | + notes=$(awk -v version="$VERSION" ' + /^## \[/ { if (found) exit; if (index($0, "[" version "]")) { found = 1; next } } + /^\[[^]]+\]: / { if (found) exit } + found { print } + ' CHANGELOG.md) + [ -n "$notes" ] || notes="See CHANGELOG.md." + jq -n \ + --arg tag "$GITHUB_REF_NAME" \ + --arg name "Flypaper $VERSION" \ + --arg body "$notes" \ + --argjson prerelease "$PRERELEASE" \ + '{tag_name: $tag, name: $name, body: $body, prerelease: $prerelease}' > release.json + curl -fsS -X POST "$API" \ + -H "Authorization: token $TOKEN" \ + -H "Content-Type: application/json" \ + --data @release.json diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2e25632 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,33 @@ +# Changelog + +All notable changes to Flypaper are documented in this file. The format follows +[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses +[Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [0.1.0] - 2026-11-14 + +First release. + +### Added + +- HTTP tarpit on its own port (8080): every request is caught and answered with endless, + plausible HTML in random chunks of 1–64 bytes with random pauses of 50 ms–1 s. +- Connection governor with limits overall and per IP and a maximum hold time; requests + without a free slot get a quick 404. +- Optional known hosts that are caught only on configurable trap paths. +- Client IP from `X-Real-IP` / `X-Forwarded-For`, trusting private networks by default. +- One log line per catch and storage in SQLite, enriched with country, city and ASN from the + DB-IP Lite databases (downloaded and refreshed monthly, existing catches backfilled). +- Dashboard on its own port (8081): totals, world map, top countries, providers, IPs and + paths, latest catches with expandable rows. +- Settings page for trap paths, known hosts, limits, retention and the private-network filter, + effective without a restart; deleting private or all catches. +- Admin password set on first visit (stored as a salted hash) and changeable later, or fixed + with `Flypaper__Admin__Password`. +- Daily retention cleanup (90 days by default), `/health` endpoint, Docker image running as + non-root with all data under `/data`. + +[Unreleased]: https://gitea.anticarnist.de/Tom/Flypaper/compare/v0.1.0...main +[0.1.0]: https://gitea.anticarnist.de/Tom/Flypaper/releases/tag/v0.1.0 diff --git a/Directory.Build.props b/Directory.Build.props index a7782a4..5733842 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -4,5 +4,6 @@ enable enable true + 0.0.0-dev diff --git a/Dockerfile b/Dockerfile index 86fdc19..4040d66 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,7 +10,8 @@ COPY src/Flypaper.Web/Flypaper.Web.csproj src/Flypaper.Web/ RUN dotnet restore src/Flypaper.Web/Flypaper.Web.csproj COPY src/ src/ -RUN dotnet publish src/Flypaper.Web/Flypaper.Web.csproj -c Release -o /app --no-restore +ARG VERSION=0.0.0-dev +RUN dotnet publish src/Flypaper.Web/Flypaper.Web.csproj -c Release -o /app --no-restore -p:Version=$VERSION FROM mcr.microsoft.com/dotnet/aspnet:10.0 WORKDIR /app diff --git a/README.md b/README.md index 8d688e6..427dfc6 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,31 @@ The files in [`deploy/unraid/`](deploy/unraid) and `.gitea/workflows/deploy.yml` author's personal deployment (Gitea Actions to Unraid). They are an example only and not needed to run Flypaper. +## Versions and updates + +Flypaper follows [Semantic Versioning](https://semver.org); every release is listed in +[CHANGELOG.md](CHANGELOG.md). The running version is shown in the dashboard footer and in the +first log line. + +| Image tag | Meaning | +|---|---| +| `:latest` | The newest release. The right choice for most setups. | +| `:X.Y.Z` | A fixed release, e.g. `:0.1.0`. Pin it if you update deliberately. | +| `:X.Y`, `:X` | The newest release of that minor or major line. | +| `:main` | Development build of every commit on `main`. May break. | + +There is no public image yet. To build a specific release from source: + +```bash +git checkout v0.1.0 +docker build --build-arg VERSION=0.1.0 -t flypaper:0.1.0 . +``` + +To update, pull or rebuild the image and recreate the container +(`docker compose pull && docker compose up -d`). The database is migrated automatically on +start; back up the `/data` volume first. Before 1.0, a minor version may contain breaking +changes, so read the changelog. + ## Behind a reverse proxy Flypaper is meant to sit behind the reverse proxy that already owns ports 80/443. The proxy diff --git a/deploy/unraid/README.md b/deploy/unraid/README.md index 8309a95..7b161f1 100644 --- a/deploy/unraid/README.md +++ b/deploy/unraid/README.md @@ -5,9 +5,29 @@ describes a generic installation. Every push to `main` (except docs and `.md` files) runs `.gitea/workflows/deploy.yml` on the act_runner on Unraid: it builds the image, pushes it to -`gitea.anticarnist.de/tom/flypaper` (`:latest` and `:`), deploys +`gitea.anticarnist.de/tom/flypaper` (`:main` and `:`), deploys `deploy/unraid/compose.yaml` and waits for `/health`. A manual run is possible from the Actions -tab (`workflow_dispatch`). +tab (`workflow_dispatch`). The stack follows `:main`, not the releases. + +## Releases + +A version tag runs `.gitea/workflows/release.yml`: it builds the image with that version, +pushes `:X.Y.Z`, `:X.Y`, `:X` and `:latest` (a pre-release such as `v0.2.0-rc.1` gets only +its own tag) and creates a Gitea release with the version's section of `CHANGELOG.md` as +notes. Nothing is deployed. + +1. Move the entries under `[Unreleased]` in `CHANGELOG.md` into a new version section with + today's date, update the links at the bottom, commit and push. +2. Tag and push: + + ```bash + git tag -a v0.1.0 -m "Flypaper 0.1.0" + git push origin v0.1.0 + ``` + +If the release step fails (e.g. the built-in token may not create releases), the images are +already pushed. Create the release by hand: Gitea → repo → Releases → New Release, pick the +tag, title `Flypaper X.Y.Z`, paste the changelog section. ## Secrets @@ -41,5 +61,5 @@ deploy. ## Rollback -Pin the image in `compose.yaml` to a previous `:` and push, or deploy that tag -manually on Unraid. +Pin the image in `compose.yaml` to a previous `:` or a release `:X.Y.Z` and push, +or deploy that tag manually on Unraid. diff --git a/deploy/unraid/compose.yaml b/deploy/unraid/compose.yaml index 65e1d20..b4b8533 100644 --- a/deploy/unraid/compose.yaml +++ b/deploy/unraid/compose.yaml @@ -14,7 +14,8 @@ name: flypaper services: flypaper: - image: gitea.anticarnist.de/tom/flypaper:latest + # :main follows every push to main; releases are tagged :X.Y.Z and :latest. + image: gitea.anticarnist.de/tom/flypaper:main container_name: flypaper restart: always ports: diff --git a/src/Flypaper.Web/AppVersion.cs b/src/Flypaper.Web/AppVersion.cs new file mode 100644 index 0000000..1eb48be --- /dev/null +++ b/src/Flypaper.Web/AppVersion.cs @@ -0,0 +1,15 @@ +using System.Reflection; + +namespace Flypaper.Web; + +public static class AppVersion +{ + public static string Current { get; } = Read(); + + private static string Read() + { + var version = typeof(AppVersion).Assembly.GetCustomAttribute()?.InformationalVersion ?? "0.0.0-dev"; + var plus = version.IndexOf('+'); + return plus >= 0 && version.Length > plus + 8 ? version[..(plus + 8)] : version; + } +} diff --git a/src/Flypaper.Web/Components/Layout/MainLayout.razor b/src/Flypaper.Web/Components/Layout/MainLayout.razor index 69bcf0c..9dfef68 100644 --- a/src/Flypaper.Web/Components/Layout/MainLayout.razor +++ b/src/Flypaper.Web/Components/Layout/MainLayout.razor @@ -11,6 +11,6 @@ @Body diff --git a/src/Flypaper.Web/Program.cs b/src/Flypaper.Web/Program.cs index 14953a4..6c30c7b 100644 --- a/src/Flypaper.Web/Program.cs +++ b/src/Flypaper.Web/Program.cs @@ -2,6 +2,7 @@ using Flypaper.Core; using Flypaper.GeoIp; using Flypaper.Http; using Flypaper.Storage; +using Flypaper.Web; using Flypaper.Web.Auth; using Flypaper.Web.Components; using Flypaper.Web.Health; @@ -50,6 +51,7 @@ builder.Services.AddAuthorizationBuilder() var app = builder.Build(); +app.Logger.LogInformation("Flypaper {Version} starting", AppVersion.Current); await app.Services.MigrateFlypaperDatabaseAsync(); app.UseFlypaper();