-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.app
More file actions
49 lines (35 loc) · 1.16 KB
/
Dockerfile.app
File metadata and controls
49 lines (35 loc) · 1.16 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
# Stage 1: Build Stage
FROM golang:1.24-alpine AS builder
# Set environment variables for Go
ENV GO111MODULE=on \
GOPROXY=https://proxy.golang.org
# Install build dependencies
RUN apk update && apk add --no-cache \
git \
bash \
make \
&& rm -rf /var/cache/apk/*
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy go mod and sum files to leverage Docker cache
COPY go.mod go.sum ./
# Download dependencies
RUN go mod tidy
# Copy the entire application code
COPY . .
# Build the Go app (optimized for production)
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o gamestone-service ./cmd/app
# Stage 2: Final Stage (Minimal, Production-Ready Image)
FROM alpine:latest
# Install SSL certificates to avoid certificate errors
RUN apk add --no-cache ca-certificates
# Add a non-root user for better security
RUN adduser -D -g '' gamestone
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy the pre-built binary from the builder stage
COPY --from=builder /app/gamestone-service .
# Use the non-root user to run the app
USER gamestone
# Command to run the Go application
CMD ["./gamestone-service"]