From d1191727abb04d35197f782ba5d4421590c42924 Mon Sep 17 00:00:00 2001 From: Krishan Thisera Date: Fri, 10 Nov 2023 20:16:36 +1030 Subject: [PATCH] include the Dockerfile --- Dockerfile | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..35d913d --- /dev/null +++ b/Dockerfile @@ -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" ] \ No newline at end of file