-
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
5aab6da
commit 07dc7fd
Showing
1 changed file
with
17 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,29 @@ | ||
FROM golang:1.22.2 | ||
# First stage: Build the Go binary | ||
FROM golang:1.22.2-alpine AS builder | ||
|
||
WORKDIR /app | ||
|
||
# Copy go.mod and go.sum to cache dependencies | ||
COPY go.mod ./ | ||
COPY go.sum ./ | ||
RUN go mod download | ||
|
||
# Copy the rest of the application files | ||
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: Minimal runtime image | ||
FROM alpine:latest | ||
|
||
WORKDIR /root/ | ||
|
||
# Copy the Go binary from the builder stage | ||
COPY --from=builder /app/main . | ||
|
||
# Expose port 8083 | ||
EXPOSE 8083 | ||
|
||
CMD ["./main"] | ||
# Run the Go binary | ||
CMD ["./main"] |