-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
59 lines (46 loc) · 1.55 KB
/
Dockerfile
File metadata and controls
59 lines (46 loc) · 1.55 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
# ---- Build Stage ----
FROM golang:1.23-alpine AS builder
# 1. Install build dependencies and setup environment in one layer
RUN apk add --no-cache git && \
addgroup -S app && \
adduser -S -G app app && \
mkdir -p /app /go-mod-cache && \
chown -R app:app /app /go-mod-cache
# 2. Set Go module environment variables
ENV GOMODCACHE=/go-mod-cache \
GOPATH=/go \
CGO_ENABLED=0
# 3. Switch to app user
USER app
WORKDIR /app
# 4. Copy dependency files
COPY --chown=app:app go.mod go.sum ./
# 5. Download dependencies
RUN go mod download
# 6. Copy source code
COPY --chown=app:app . .
# 7. Build optimized binary
RUN go build \
-ldflags="-s -w" \
-trimpath \
-o ./golaunch \
./cmd/golaunch
# ---- Final Stage ----
FROM alpine:3.21
# 1. Install runtime dependencies in one layer
RUN apk --no-cache add ca-certificates && \
addgroup -S app && \
adduser -S -G app app && \
mkdir -p /app/assets && \
chown -R app:app /app
# 2. Switch to app user
USER app
WORKDIR /app
# 3. Copy built artifacts
COPY --from=builder --chown=app:app /app/golaunch .
COPY --from=builder --chown=app:app /app/assets ./assets
# 4. Add metadata
LABEL maintainer="Your Name <your.email@example.com>"
LABEL org.opencontainers.image.source="https://github.com/raufzer/golaunch-cli"
# 5. Set entrypoint
ENTRYPOINT ["./golaunch"]