Added Dockerfile & .dockerignore
This commit is contained in:
parent
92ee82fc0e
commit
74587d8c32
{{cookiecutter.project_name}}
1
{{cookiecutter.project_name}}/.dockerignore
Normal file
1
{{cookiecutter.project_name}}/.dockerignore
Normal file
@ -0,0 +1 @@
|
||||
*_test.go
|
31
{{cookiecutter.project_name}}/Dockerfile
Normal file
31
{{cookiecutter.project_name}}/Dockerfile
Normal file
@ -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", "--"]
|
Loading…
x
Reference in New Issue
Block a user