fix(template): dotnet scaffold passes its own checks and builds a non-root image #5

Merged
jonnxor merged 1 commit from fix/template-dotnet into main 2026-10-29 20:22:39 +00:00
Owner

Scaffolding repos/sogin with language: dotnet showed three gaps in the template. This fixes them.

Gaps

  1. A fresh dotnet scaffold failed its own pre-commit. mise run fmt runs dotnet format, which errors with no project or solution present. An empty .slnx doesn't help either: dotnet build -warnaserror turns NuGet's "Unable to find a project to restore" warning into an error. Fix: fmt, lint and test check for a .sln, .slnx or *.*proj in the root. Without one they print "no .sln, .slnx or project file in the root yet, nothing to …" and exit 0; with one they run the real dotnet command unchanged. This is the honest option: it says nothing exists yet, rather than generating a solution that pretends to build.
  2. dotnet = "latest" could drift to a preview major while the Containerfile hardcodes the 10.0 images. Fix: pinned to dotnet = "10".
  3. The Containerfile built the DLL name from project_name. That gave Sögin.dll for a non-ASCII name and assumed a single project. Fix: a required PROJECT build arg publishes src/$PROJECT and runs $PROJECT.dll. The build fails with a clear message when PROJECT is missing. compose.yaml passes PROJECT as a build arg for dotnet. A dotnet-only .containerignore keeps the host's bin/ and obj/ out of the build. The image now sets USER $APP_UID: aspnet:10.0 ships the app user (1654) but has no USER, so it started as root.

Proof (local, scratch dirs outside the repo)

  • copier copy --trust --defaults --vcs-ref HEAD --data language=dotnet --data project_name="Prófun": mise run fmt, lint and test all exit 0 with the "nothing to …" message. git commit passes the lefthook pre-commit (fmt, lint) and commit-msg hooks with no hand edits.
  • The same scaffold with use_podman=true, plus src/Profun.Web (dotnet new web), tests/Profun.Tests (xunit) and Profun.slnx:
    • fmt, lint and test run for real: build clean, 1 test passed.
    • A planted unused variable makes mise run lint fail with CS0168, so the guard hides nothing.
    • podman build without PROJECT fails with the message.
    • podman build --build-arg PROJECT=Profun.Web builds; image User=1654. The container serves Hello World! on 8080 and id gives uid=1654(app).
  • language=none and language=node render identically to main, apart from sops ciphertext. The none scaffold passes its tasks and a commit.

Not in this PR

  • A fresh language: node scaffold fails mise run lint (and so its pre-commit hook): npx eslint . finds no config. Same on main.
  • project_slug defaults to project_name | lower, so "Prófun" gives the slug prófun, and compose tags the image localhost/prófun:dev, which is not a valid image reference.

🤖 Generated with Claude Code

Scaffolding `repos/sogin` with `language: dotnet` showed three gaps in the template. This fixes them. ## Gaps 1. **A fresh dotnet scaffold failed its own pre-commit.** `mise run fmt` runs `dotnet format`, which errors with no project or solution present. An empty `.slnx` doesn't help either: `dotnet build -warnaserror` turns NuGet's "Unable to find a project to restore" warning into an error. **Fix:** `fmt`, `lint` and `test` check for a `.sln`, `.slnx` or `*.*proj` in the root. Without one they print "no .sln, .slnx or project file in the root yet, nothing to …" and exit 0; with one they run the real dotnet command unchanged. This is the honest option: it says nothing exists yet, rather than generating a solution that pretends to build. 2. **`dotnet = "latest"` could drift to a preview major** while the Containerfile hardcodes the 10.0 images. **Fix:** pinned to `dotnet = "10"`. 3. **The Containerfile built the DLL name from `project_name`.** That gave `Sögin.dll` for a non-ASCII name and assumed a single project. **Fix:** a required `PROJECT` build arg publishes `src/$PROJECT` and runs `$PROJECT.dll`. The build fails with a clear message when `PROJECT` is missing. `compose.yaml` passes `PROJECT` as a build arg for dotnet. A dotnet-only `.containerignore` keeps the host's `bin/` and `obj/` out of the build. The image now sets `USER $APP_UID`: `aspnet:10.0` ships the `app` user (1654) but has no `USER`, so it started as root. ## Proof (local, scratch dirs outside the repo) - `copier copy --trust --defaults --vcs-ref HEAD --data language=dotnet --data project_name="Prófun"`: `mise run fmt`, `lint` and `test` all exit 0 with the "nothing to …" message. `git commit` passes the lefthook `pre-commit` (fmt, lint) and `commit-msg` hooks with no hand edits. - The same scaffold with `use_podman=true`, plus `src/Profun.Web` (`dotnet new web`), `tests/Profun.Tests` (xunit) and `Profun.slnx`: - fmt, lint and test run for real: build clean, 1 test passed. - A planted unused variable makes `mise run lint` fail with CS0168, so the guard hides nothing. - `podman build` without `PROJECT` fails with the message. - `podman build --build-arg PROJECT=Profun.Web` builds; image `User=1654`. The container serves `Hello World!` on 8080 and `id` gives `uid=1654(app)`. - `language=none` and `language=node` render identically to `main`, apart from sops ciphertext. The none scaffold passes its tasks and a commit. ## Not in this PR - A fresh `language: node` scaffold fails `mise run lint` (and so its pre-commit hook): `npx eslint .` finds no config. Same on `main`. - `project_slug` defaults to `project_name | lower`, so "Prófun" gives the slug `prófun`, and compose tags the image `localhost/prófun:dev`, which is not a valid image reference. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(template): dotnet scaffold passes its own checks and builds a non-root image
All checks were successful
CI / sanity (pull_request) Successful in 6s
2e983d6c5c
- fmt/lint/test say "no solution yet" and pass when the root has no
  .sln/.slnx/project file; dotnet fails without one, so a fresh scaffold
  could not pass its own pre-commit hook.
- Pin dotnet to 10, the major of the Containerfile's sdk/aspnet images.
- Containerfile takes a PROJECT build arg (src/$PROJECT) instead of
  deriving the DLL from project_name, and sets USER $APP_UID: the aspnet
  image ships the `app` user but starts as root. compose passes PROJECT;
  a .containerignore keeps host bin/obj out of the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
WAAAGH/_workdesk!5
No description provided.