-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile.dev
More file actions
62 lines (44 loc) · 1.66 KB
/
Dockerfile.dev
File metadata and controls
62 lines (44 loc) · 1.66 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
# Development Dockerfile - uses Alpine for shell access and healthcheck support
# For production, use Dockerfile (distroless)
FROM golang:1.26-alpine AS builder
WORKDIR /app
RUN apk add --no-cache \
ca-certificates \
git \
tzdata \
&& update-ca-certificates
WORKDIR /tracer
# Copy only go.mod and go.sum first to cache dependencies
COPY go.mod go.sum ./
RUN go mod download
COPY . .
ARG TARGETPLATFORM
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$(echo $TARGETPLATFORM | cut -d'/' -f2) go build -a -tags netgo -ldflags '-w -extldflags "-static"' -o /app/tracer ./cmd/app
# Development image with Alpine (shell + wget for healthcheck)
FROM alpine:3.23 AS dev
ARG SERVER_PORT=8080
ENV SERVER_PORT=${SERVER_PORT}
WORKDIR /app
RUN apk add --no-cache \
ca-certificates \
tzdata \
&& update-ca-certificates
# Create non-root user for security
RUN addgroup -g 1000 tracer && \
adduser -u 1000 -G tracer -s /bin/sh -D tracer
COPY --from=builder /app/tracer /app/tracer
COPY --from=builder /tracer/migrations /app/migrations
# Set ownership
RUN chown -R tracer:tracer /app
# Switch to non-root user
USER tracer
EXPOSE ${SERVER_PORT} 7001
# Health check using wget to verify app readiness (wget is included in Alpine base image)
# interval: check every 30 seconds
# timeout: wait up to 10 seconds for response
# start-period: wait 40 seconds before first check (app startup time)
# retries: mark unhealthy after 3 consecutive failures
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:${SERVER_PORT}/ready || exit 1
ENTRYPOINT ["/app/tracer"]