mirror of
https://github.com/selfhosters-cc/container-census.git
synced 2026-01-19 21:19:32 -06:00
Backend changes: - Updated go.mod module path from github.com/container-census to github.com/selfhosters-cc to match correct GitHub organization - Updated all import paths across codebase to use new module name - This fixes ldflags injection of BuildTime during compilation - BuildTime now correctly shows in /api/health response Frontend changes: - Added build time badge next to version in header - Shows date and time in compact format (e.g., "🔨 12/11/2025 8:06 PM") - Hover shows full timestamp - Only displays if build_time is not "unknown" The build script already sets BuildTime via ldflags, but it was being ignored because the module path in go.mod didn't match the ldflags path. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
115 lines
3.7 KiB
Docker
115 lines
3.7 KiB
Docker
# Multi-stage build for Container Census
|
|
|
|
# Stage 1: Build the Go binary
|
|
FROM golang:1.23-alpine AS builder
|
|
ENV GOTOOLCHAIN=auto
|
|
|
|
# Install build dependencies
|
|
# Note: sqlite requires specific build tags on Alpine
|
|
RUN apk add --no-cache git gcc musl-dev sqlite-dev
|
|
|
|
# Set working directory
|
|
WORKDIR /build
|
|
|
|
# Copy dependency files first (better caching)
|
|
COPY go.mod go.sum* ./
|
|
|
|
# Download dependencies (cached unless go.mod/go.sum changes)
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Tidy if needed (rarely changes cache)
|
|
RUN go mod tidy -e
|
|
|
|
# Build the binary with proper tags for Alpine and inject build timestamp
|
|
RUN BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") && \
|
|
CGO_ENABLED=1 GOOS=linux go build \
|
|
-buildvcs=false \
|
|
-tags "sqlite_omit_load_extension" \
|
|
-ldflags "-X github.com/selfhosters-cc/container-census/internal/version.BuildTime=${BUILD_TIME}" \
|
|
-o census \
|
|
./cmd/server
|
|
|
|
# Stage 2: Create minimal runtime image
|
|
FROM alpine:3.21
|
|
|
|
# Build arg for docker group GID (defaults to 999, can be overridden at runtime)
|
|
ARG DOCKER_GID=999
|
|
|
|
# Install ca-certificates for HTTPS, timezone data, su-exec for user switching, and wget for Trivy installation
|
|
RUN apk --no-cache add ca-certificates tzdata su-exec wget
|
|
|
|
# Install Trivy for vulnerability scanning
|
|
# Download and install Trivy binary with architecture detection
|
|
ARG TRIVY_VERSION=0.58.1
|
|
RUN ARCH=$(uname -m) && \
|
|
case "$ARCH" in \
|
|
x86_64) TRIVY_ARCH="64bit" ;; \
|
|
aarch64) TRIVY_ARCH="ARM64" ;; \
|
|
armv7l) TRIVY_ARCH="ARM" ;; \
|
|
*) echo "Unsupported architecture: $ARCH" && exit 1 ;; \
|
|
esac && \
|
|
wget -qO- https://github.com/aquasecurity/trivy/releases/download/v${TRIVY_VERSION}/trivy_${TRIVY_VERSION}_Linux-${TRIVY_ARCH}.tar.gz | tar -xzf - -C /usr/local/bin trivy && \
|
|
chmod +x /usr/local/bin/trivy && \
|
|
trivy --version
|
|
|
|
# Create docker group with default GID and census user
|
|
# Note: The actual GID can be added at runtime using docker-compose group_add
|
|
# Delete existing group with same GID if it exists
|
|
RUN (getent group ${DOCKER_GID} && delgroup $(getent group ${DOCKER_GID} | cut -d: -f1)) || true && \
|
|
addgroup -g ${DOCKER_GID} docker && \
|
|
addgroup -g 1000 census && \
|
|
adduser -D -u 1000 -G census census && \
|
|
adduser census docker
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy binary from builder
|
|
COPY --from=builder /build/census .
|
|
|
|
# Copy version file
|
|
COPY --from=builder /build/.version ./.version
|
|
|
|
# Copy changelog for "What's New" feature
|
|
COPY --from=builder /build/CHANGELOG.md ./CHANGELOG.md
|
|
|
|
# Copy Next.js web frontend (pre-built static export)
|
|
# To build: cd web-next && npm run build
|
|
# Output is in web-next/out which gets copied here as ./web
|
|
COPY --from=builder /build/web-next/out ./web
|
|
|
|
# Copy example config
|
|
COPY --from=builder /build/config/config.yaml.example ./config/config.yaml.example
|
|
|
|
# Copy entrypoint script
|
|
COPY docker-entrypoint.sh /usr/local/bin/
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
# Create data directory and Trivy cache directory with correct permissions
|
|
RUN mkdir -p ./data ./data/.trivy && chown -R census:census /app
|
|
|
|
# Note: We start as root so the entrypoint can fix volume permissions
|
|
# The entrypoint will switch to census user after fixing permissions
|
|
|
|
# Expose HTTP port
|
|
EXPOSE 8080
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/api/health || exit 1
|
|
|
|
# Set environment variables
|
|
ENV CONFIG_PATH=/app/config/config.yaml
|
|
|
|
# Optional: Override Trivy cache directory (default: /app/data/.trivy)
|
|
# ENV TRIVY_CACHE_DIR=/custom/path
|
|
|
|
# Set entrypoint
|
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
|
|
|
# Run the application
|
|
CMD ["./census"]
|