Files
KeepNote/Dockerfile.debug
T
Admin c58e193038 [chore](dev): keep one Delve server across hot reloads
Replace Air's kill-and-rerun loop in the debug image with the pilot
persistent-delve supervisor: src/dev/dlv-watch.sh owns one headless
`dlv exec --multiclient --continue` server, rebuilds ./tmp/main on save and
restarts only the debug target through the tiny rpc2 client in
src/dev/dlv-restart. An attached VS Code session (and its breakpoints) now
survives saves instead of reconnecting after every reload.

The debug compose builds locally with `pull_policy: build` and without
`build.network: host`: compose cannot grant the network.host entitlement, so
a cold `up` previously failed with "additional privileges requested"; the
default bridge reaches the dev Gitea for module resolution.
2026-10-19 09:26:50 +01:00

67 lines
2.5 KiB
Docker

# Source: https://oneuptime.com/blog/post/2026-01-07-go-hot-reloading-docker-air/view#step-3-create-the-development-dockerfile
# Dockerfile (Development)
# This Dockerfile is optimized for development with hot reloading
# It includes Air and mounts your source code as a volume
# Use the official Go image as our base
# Alpine variant is smaller but we use the full image for better compatibility
FROM golang:1.26-bookworm
# Set the working directory inside the container
# All subsequent commands will run from this directory
WORKDIR /app
# Shared modules (git.dcntrlized.org/dcntrlized/dcntrlized-auth) are served by
# the dev Gitea Go module proxy. Override via --build-arg in production.
ARG GOPROXY_VALUE=http://192.168.122.183:3000/api/packages/Dcntrlized/go
ARG GONOSUMDB_VALUE=git.dcntrlized.org
ENV GOPROXY=${GOPROXY_VALUE},https://proxy.golang.org,direct
ENV GONOSUMDB=${GONOSUMDB_VALUE}
# Install Air for hot reloading
# We install it globally so it's available in the PATH
RUN go install github.com/air-verse/air@latest
# Install additional development tools (optional but useful)
# - delve: Go debugger for debugging inside containers
# - golangci-lint: Linter for code quality checks
RUN go install github.com/go-delve/delve/cmd/dlv@latest && \
curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.11.2
# Copy go.mod and go.sum first for better layer caching
# This layer only rebuilds when dependencies change
COPY src/go.mod src/go.sum* ./
# Download all dependencies
# This is cached separately from source code changes
RUN go mod download && go mod verify
# Copy the Air configuration file
# This tells Air how to watch and rebuild our application
COPY ./src/.air.toml ./
# Note: We do NOT copy source code here!
# Source code is mounted as a volume in Docker Compose
# This enables hot reloading without rebuilding the image
# Expose the application port
# Make sure this matches your application's listening port
EXPOSE 8080
# Expose delve debugger port (optional, for debugging)
EXPOSE 2345
# Set environment variables for development
ENV GO111MODULE=on
# Default command: persistent-delve hot-reload supervisor (src/dev/dlv-watch.sh).
# Unlike Air, it never kills the dlv server, so an attached VS Code debug
# session survives file saves (Delve's `restart` only re-launches the target).
# src/ is live-mounted at /app, so this runs the in-repo copy you can edit.
CMD ["bash", "/app/dev/dlv-watch.sh"]
##
LABEL org.dcntrlized.service=KeepNote
LABEL org.dcntrlized.port=8080