-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
31 lines (21 loc) · 772 Bytes
/
Dockerfile
File metadata and controls
31 lines (21 loc) · 772 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
# Start with the official Golang image as the build stage
FROM golang:1.24 AS build
# Set the working directory inside the container
WORKDIR /app
RUN apt update -y && apt install -y \
upx
# Copy the Go module files first and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Copy the rest of the application source code
COPY . .
# Build the application
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o app ./cmd/app/main.go && upx --ultra-brute --lzma /app/app
# Use a minimal base image for the final container
FROM scratch
# Copy the compiled binary from the build stage
COPY --from=build /app/app /
# Expose the application's port (change according to your app)
EXPOSE 8080
# Command to run the application
CMD ["/app"]