-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74a22e5
commit b9c2d5c
Showing
1 changed file
with
16 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
FROM golang:1.22.2 | ||
FROM golang:1.22.2-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
COPY go.mod ./ | ||
COPY go.sum ./ | ||
RUN go mod download | ||
|
||
|
||
COPY . . | ||
|
||
RUN go build -o main . | ||
# Build the Go app as a statically linked binary | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o main . | ||
|
||
# Second stage: Create a minimal image | ||
FROM alpine:latest | ||
|
||
# Set working directory for the final image | ||
WORKDIR /root/ | ||
|
||
# Copy only the binary from the builder stage | ||
COPY --from=builder /app/main . | ||
|
||
|
||
EXPOSE 8081 | ||
|
||
CMD ["./main"] | ||
|
||
CMD ["./main"] |