-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
53 lines (37 loc) · 1.12 KB
/
Dockerfile
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
# Stage 1: Build the Go binary
FROM golang:1.21-alpine AS builder
WORKDIR /app
# Install necessary build tools
RUN apk add --no-cache git
# Copy go mod files first to leverage Docker cache
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the project files
COPY . .
# Build the application with production settings
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-w -s" -o github-trends cmd/github-trends/main.go
# Stage 2: Create a minimal production image
FROM alpine:latest
# Add necessary certificates and security updates
RUN apk --no-cache add ca-certificates && \
apk --no-cache add tzdata && \
update-ca-certificates
# Create a non-root user
RUN adduser -D -H -h /app appuser
WORKDIR /app
# Copy the binary from builder
COPY --from=builder /app/github-trends .
# Copy web assets and config
COPY --from=builder /app/web ./web
COPY --from=builder /app/config.yaml .
# Set proper permissions
RUN chown -R appuser:appuser /app
# Use non-root user
USER appuser
# Set production environment
ENV GIN_MODE=release
ENV ENV=production
# Expose the application port
EXPOSE 9090
# Run the binary
CMD ["./github-trends"]