-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (32 loc) · 921 Bytes
/
Dockerfile
File metadata and controls
47 lines (32 loc) · 921 Bytes
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
# Build stage
FROM golang:1.23-alpine AS builder
# Install dependencies
RUN apk add --no-cache git
# Set working directory
WORKDIR /app
# Copy go.mod and go.sum files first to leverage Docker cache
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code
COPY . .
# Build the application with optimizations
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-w -s" -o gorack .
# Run stage
FROM alpine:latest
# Install CA certificates and timezone data
RUN apk --no-cache add ca-certificates tzdata
# Create a non-root user to run the application
RUN adduser -D -H -h /app appuser
WORKDIR /app
# Copy the binary from the builder stage
COPY --from=builder /app/gorack /app/
# Set ownership
RUN chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose API port
EXPOSE 8080
# Set environment variables
ENV API_PORT=8080
# Run the application
CMD ["/app/gorack"]