-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
41 lines (28 loc) · 1.03 KB
/
Copy pathDockerfile
File metadata and controls
41 lines (28 loc) · 1.03 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
# Dockerfile for building and running the Go server application
# Stage 1: Build
FROM golang:1.22-alpine AS builder
WORKDIR /app
# Copy go.mod and go.sum files to the container
COPY go.mod go.sum ./
# Download Go modules
RUN go mod download
# Copy the source code into the container
COPY . .
# Build the Go application
RUN CGO_ENABLED=0 GOOS=linux go build -o /app/server ./cmd/server
# Stage 2: Run
FROM alpine:3.19
WORKDIR /app
# Install necessary packages
RUN apk --no-cache add ca-certificates
# Copy the built binary and resources files from the builder stage
COPY --from=builder /app/server /app/server
COPY --from=builder /app/resources /app/resources
# Expose the port the application will run on
EXPOSE 8000
# Healthcheck for Docker/K8s
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8000/health || exit 1
# Set the entrypoint and default command
ENTRYPOINT ["/app/server"]
CMD ["--host", "0.0.0.0", "--port", "8000", "--resources", "/app/resources"]