-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile.server
More file actions
75 lines (59 loc) · 2.73 KB
/
Dockerfile.server
File metadata and controls
75 lines (59 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Multi-stage Chainguard TMI application build
# Stage 1: Build environment using Chainguard Go image
FROM cgr.dev/chainguard/go:latest AS builder
# Metadata for tracking
LABEL security.scan-date="AUTO_GENERATED"
LABEL security.patch-level="high-critical"
LABEL maintainer="TMI Security Team"
# Set working directory
WORKDIR /app
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies with security verification
RUN go mod download && \
go mod verify
# Copy source code
COPY . .
# Build the application with security flags (CGO disabled for static binary)
# Note: Oracle support is excluded (requires CGO). To include Oracle, use -tags oracle with CGO_ENABLED=1
# Chainguard Go image includes git, so git commands will work
# Read version from .version file (same source of truth as Makefile)
RUN MAJOR=$(cat .version | grep '"major"' | grep -o '[0-9]*') && \
MINOR=$(cat .version | grep '"minor"' | grep -o '[0-9]*') && \
PATCH=$(cat .version | grep '"patch"' | grep -o '[0-9]*') && \
PRERELEASE=$(cat .version | grep '"prerelease"' | sed 's/.*: *"\(.*\)".*/\1/') && \
CGO_ENABLED=0 GOOS=linux go build \
-ldflags "-s -w -X github.com/ericfitz/tmi/api.VersionMajor=${MAJOR} -X github.com/ericfitz/tmi/api.VersionMinor=${MINOR} -X github.com/ericfitz/tmi/api.VersionPatch=${PATCH} -X github.com/ericfitz/tmi/api.VersionPreRelease=${PRERELEASE} -X github.com/ericfitz/tmi/api.GitCommit=$(git rev-parse --short HEAD 2>/dev/null || echo 'development') -X github.com/ericfitz/tmi/api.BuildDate=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
-trimpath \
-buildmode=exe \
-o tmiserver \
./cmd/server
# Stage 2: Chainguard static runtime (minimal attack surface)
FROM cgr.dev/chainguard/static:latest
# Metadata for tracking security patches
LABEL security.chainguard="true"
LABEL security.scan-date="AUTO_GENERATED"
LABEL security.patch-level="minimal-attack-surface"
LABEL maintainer="TMI Security Team"
LABEL org.opencontainers.image.title="TMI Server"
LABEL org.opencontainers.image.description="TMI Server on Chainguard static base"
LABEL org.opencontainers.image.name="tmi/tmi-server"
# Copy binary from builder
COPY --from=builder /app/tmiserver /tmiserver
# Note: No static files needed - migrations use GORM AutoMigrate (schema from Go code)
# Set working directory
WORKDIR /
# Expose port 8080
EXPOSE 8080
# Set secure environment variables
ENV ENV=development
ENV LOG_LEVEL=info
ENV SERVER_PORT=8080
ENV SERVER_INTERFACE=0.0.0.0
ENV GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn
# Note: Chainguard static doesn't include a shell
# Health checks should be done externally via Kubernetes/Docker probes
# Run as non-root user (Chainguard static runs as nonroot by default)
USER nonroot:nonroot
# Run the application
ENTRYPOINT ["/tmiserver"]