diff --git a/{{cookiecutter.project_name}}/.dockerignore b/{{cookiecutter.project_name}}/.dockerignore new file mode 100644 index 0000000..a48d947 --- /dev/null +++ b/{{cookiecutter.project_name}}/.dockerignore @@ -0,0 +1 @@ +*_test.go diff --git a/{{cookiecutter.project_name}}/Dockerfile b/{{cookiecutter.project_name}}/Dockerfile new file mode 100644 index 0000000..82d574b --- /dev/null +++ b/{{cookiecutter.project_name}}/Dockerfile @@ -0,0 +1,31 @@ +# Building the binary of the App +FROM docker.io/golang:1.19 AS build + +WORKDIR /go/src/{{cookiecutter.project_name}} + +# Copy all the Code and stuff to compile everything +COPY . . + +# Downloads all the dependencies in advance (could be left out, but it's more clear this way) +RUN go mod download + +# Builds the application as a staticly linked one, to allow it to run on alpine +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o app cmd/{{cookiecutter.project_name}}.go + + +# Moving the binary to the 'final Image' to make it smaller +FROM docker.io/alpine:latest AS release + +WORKDIR /app + +COPY --from=build /go/src/{{cookiecutter.project_name}}/app . + +# Add packages +RUN apk -U upgrade \ + && apk add --no-cache dumb-init ca-certificates \ + && chmod +x /app/app + +# Exposes port 3000 because our program listens on that port +EXPOSE 3000 + +ENTRYPOINT ["/usr/bin/dumb-init", "--"]