-
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
2bd6a7d
commit d119172
Showing
1 changed file
with
36 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# ----------------------------- | ||
# Stage 1: Build the Go application | ||
# ----------------------------- | ||
FROM golang:1.21.3-alpine AS builder | ||
|
||
|
||
WORKDIR $GOPATH/src | ||
|
||
# Copy all files from the current directory to the working directory in the container | ||
COPY . . | ||
|
||
# Bypass the default Go proxy and fetch directly from the source | ||
ENV GOPROXY=direct | ||
|
||
# Install 'git' and other dependencies necessary for building the application | ||
RUN apk add --no-cache git | ||
|
||
# Fetch and tidy up the Go module dependencies | ||
RUN go mod tidy -x | ||
|
||
# Compile the Go application with specific settings | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o /go/bin/grender main.go | ||
|
||
# ----------------------------- | ||
# Stage 2: Create the final image | ||
# ----------------------------- | ||
FROM scratch | ||
|
||
# Copy the compiled binary from the builder stage to the final container | ||
COPY --from=builder /go/bin/grender /go/bin/grender | ||
|
||
# Expose port 8080 for the application | ||
EXPOSE 8080 | ||
|
||
# Set the command to run when the container starts | ||
ENTRYPOINT [ "/go/bin/grender" ] |