diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7975ec5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,23 @@ +# Exclude "build-time" ignore files. +.dockerignore + +# Exclude git history and configuration. +.gitignore + +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +out/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b9fa1e7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,31 @@ +FROM golang:1.21-bookworm as builder + +WORKDIR /app + +# Retrieve application dependencies. +# This allows the container build to reuse cached dependencies. +# Expecting to copy go.mod and if present go.sum. +COPY go.* ./ +RUN go mod download + +ENV APP_ENV production + +# Copy local code to the container image. +COPY . ./ + +# Build the binary. +RUN go build -v -o server + +# Use the official Debian slim image for a lean production container. +# https://hub.docker.com/_/debian +# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds +FROM debian:bookworm-slim +RUN set -x && apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ + ca-certificates && \ + rm -rf /var/lib/apt/lists/* + +# Copy the binary to the production image from the builder stage. +COPY --from=builder /app/server /app/server + +# Run the web service on container startup. +CMD ["/app/server"] \ No newline at end of file