-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.dev
More file actions
101 lines (76 loc) · 2.3 KB
/
Dockerfile.dev
File metadata and controls
101 lines (76 loc) · 2.3 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# syntax = docker/dockerfile:1.4
# ==================== Development Stage ====================
FROM golang:1.24-alpine AS development
LABEL maintainer="GAAP Team <dev@gaap.cc>"
LABEL description="GAAP API Development Environment with Hot-Reload & Delve Debugger"
WORKDIR /app
# Install build dependencies and debugging tools
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
apk add --no-cache \
build-base \
gcc \
musl-dev \
git \
&& go install github.com/air-verse/air@v1.61.7 \
&& go install github.com/go-delve/delve/cmd/dlv@latest
# Copy Go module files for dependency caching
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download
# Copy source code
COPY . .
# Air configuration for hot-reload
RUN cat > .air.toml <<'EOF'
root = "."
tmp_dir = "tmp"
[build]
cmd = "go build -gcflags='all=-N -l' -o ./tmp/main ."
bin = "tmp/main"
include_ext = ["go", "yaml", "toml", "ini"]
exclude_dir = ["tmp", "vendor", "testdata"]
include_dir = []
exclude_file = []
delay = 1000
stop_on_error = true
send_interrupt = false
kill_delay = 500
[log]
time = true
[color]
main = "magenta"
watcher = "cyan"
build = "yellow"
runner = "green"
[misc]
clean_on_exit = true
EOF
# Expose ports: 8000 (API), 40000 (Delve debugger)
EXPOSE 8000 40000
# Use Air for hot-reload or Delve for debugging
CMD if [ "$ENABLE_DELVE" = "true" ]; then \
dlv debug --headless --listen=:40000 --api-version=2 --accept-multiclient --continue --log; \
else \
air; \
fi
# ==================== Production Stage ====================
FROM golang:1.24-alpine AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY . .
# Build optimized binary
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o main .
# ==================== Production Runtime ====================
FROM alpine:latest AS production
RUN apk --no-cache add ca-certificates tzdata
WORKDIR /app
# Create non-root user for security
RUN addgroup -g 1001 -S gaap && \
adduser -u 1001 -S gaap -G gaap
COPY --from=builder --chown=gaap:gaap /app/main .
COPY --chown=gaap:gaap ./manifest ./manifest
USER gaap
EXPOSE 8000
CMD ["./main"]