-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (53 loc) · 1.81 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (53 loc) · 1.81 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
# Build stage - runs natively on build machine, cross-compiles to target
FROM --platform=$BUILDPLATFORM golang:1.26-bookworm AS build
ARG TARGETARCH
ARG TARGETOS=linux
WORKDIR /go/src/hilt
COPY go.mod go.sum* ./
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download || true
COPY . .
# Production build - stripped binary
FROM build AS build-prod
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -ldflags="-s -w" -o /hilt ./cmd/main.go
# Development build - debug-friendly binary
FROM build AS build-dev
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
go build -gcflags="all=-N -l" -o /hilt ./cmd/main.go
RUN GOARCH=${TARGETARCH} go install github.com/go-delve/delve/cmd/dlv@latest && \
cp /go/bin/linux_${TARGETARCH}/dlv /go/bin/dlv 2>/dev/null || cp /go/bin/dlv /go/bin/dlv 2>/dev/null || true
# Production target - minimal runtime
FROM debian:bookworm-slim AS prod
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build-prod /hilt /usr/bin/hilt
EXPOSE 8080
ENTRYPOINT ["/usr/bin/hilt", "serve"]
# Development target - includes debug tools
FROM debian:bookworm-slim AS dev
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
curl \
bash-completion \
less \
vim-tiny \
procps \
htop \
strace \
iputils-ping \
dnsutils \
net-tools \
tcpdump \
jq \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build-dev /hilt /usr/bin/hilt
COPY --from=build-dev /go/bin/dlv /usr/bin/dlv
EXPOSE 8080
ENTRYPOINT ["/usr/bin/hilt", "serve"]