-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
37 lines (26 loc) · 868 Bytes
/
Copy pathDockerfile
File metadata and controls
37 lines (26 loc) · 868 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
# Stage 1: Build the Go application
FROM golang:1.24.11-alpine AS builder
# Set working directory
WORKDIR /app
# Copy go.mod and go.sum to download dependencies
COPY go.mod go.sum ./
# Download dependencies
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
# Copy the source code
COPY . .
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
CGO_ENABLED=0 GOOS=linux go build -o router ./cmd/router/main.go
# Stage 2: Create a lightweight runtime image
FROM alpine:3.20
# Install ca-certificates for HTTPS for potential external api calls
RUN apk add --no-cache ca-certificates
# Set working directory
WORKDIR /app
# Copy the binary from the builder stage
COPY --from=builder /app/router .
# Expose default ports
EXPOSE 24454 8080
# Entrypoint so users can append flags
ENTRYPOINT ["./router"]