fix: embed HTML templates at compile time with go:embed (Dockerfile path mismatch) #220
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Handlers load templates at runtime using relative paths like
"internal/templates/error.html", but the Dockerfile copies them to/templates/in the container image.Additionally, the deployment manifest sets
readOnlyRootFilesystem: true, which prevents any file system access outside of explicitly mounted paths. The container will crash-loop whenever any handler attempts to parse a template file.What to do
Replace all
template.ParseFiles("internal/templates/*.html")calls withgo:embedso templates are compiled directly into the binary://go:embeddirective ininternal/handlers/handlers.go(or a newinternal/handlers/templates.go):template.ParseFiles("internal/templates/foo.html")call with:COPY internal/templates/ /templates/line from the Dockerfile — templates are now baked into the binary.Acceptance Criteria
go:embedused for all template loading — zero runtime filesystem reads of.htmlfilesinternal/templates/as a separate layergo test -race ./...passesreadOnlyRootFilesystem: truestatic/) still served viahttp.FileServer(OK to keep — those are read from the container filesystem, but/static/is a COPY that still works)References
readOnlyRootFilesystem: trueintesting1/first-cluster/apps/gitea-mobile/deployment.yamlAI-Manager referenced this issue2026-04-20 20:25:25 +00:00
Note: This issue is superseded by #231 which consolidates both template and static asset embedding. Work will be done under #231. This issue will be closed when #231 is merged.
Repo Manager status: PR #232 is open and awaiting review. This PR embeds HTML templates at compile time with go:embed, resolving the Dockerfile path mismatch described in this issue.
Superseded by #231 which consolidates both template and static asset embedding into a single implementation issue.