-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (49 loc) · 1.36 KB
/
Dockerfile
File metadata and controls
67 lines (49 loc) · 1.36 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
# Build stage
FROM golang:1.22-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
# Set working directory
WORKDIR /app
# Copy go mod files
COPY go.mod go.sum ./
# Download and verify dependencies
RUN go mod download && go mod verify
# Copy source code
COPY . .
# Generate code
RUN go generate ./...
# Build static binary
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s" \
-o bin/bian-go \
./cmd/server 2>/dev/null || \
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-ldflags="-w -s" \
-o bin/bian-go \
./examples/basic
# Runtime stage
FROM alpine:3.19
# Install runtime dependencies
RUN apk add --no-cache ca-certificates tzdata wget
# Create non-root user
RUN addgroup -g 1000 bian && \
adduser -D -s /bin/sh -u 1000 -G bian bian
# Set working directory
WORKDIR /app
# Copy binary from builder stage
COPY --from=builder /app/bin/bian-go ./bian-go
# Set ownership and permissions
RUN chown bian:bian ./bian-go && \
chmod +x ./bian-go
# Switch to non-root user
USER bian
# Expose port
EXPOSE 8080
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
# Environment defaults
ENV PORT=8080
ENV GRAPHQL_PLAYGROUND=false
# Run the binary
CMD ["./bian-go"]