docker: build binary in Docker

Signed-off-by: Nicolas Froger <nicolas@kektus.xyz>
This commit is contained in:
Nicolas Froger 2022-08-15 23:57:10 +02:00
parent d252f53a6f
commit a23642af34
Signed by: nicolas
GPG Key ID: 461D87623FDF1E47
2 changed files with 20 additions and 7 deletions

View File

@ -1,7 +1,4 @@
.vscode
.git
go.mod
go.sum
*.go
helm
.*ignore

View File

@ -1,19 +1,35 @@
FROM alpine:3.11.6
FROM golang:1.18.5 as builder
ARG GOOS="linux"
ARG GOARCH="amd64"
WORKDIR /workspace
COPY go.mod go.sum /workspace/
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -a -o hugo-mx-gateway
FROM alpine:3.16.2
ARG RUNTIME_USER="mxgateway"
ARG RUNTIME_USER_UID=4583
RUN apk update && apk add --no-cache ca-certificates
RUN addgroup -g $RUNTIME_USER_UID $RUNTIME_USER && \
adduser --disabled-password --no-create-home --gecos "" \
adduser --disabled-password --no-create-home --gecos "" \
--home /app --ingroup $RUNTIME_USER --uid $RUNTIME_USER_UID $RUNTIME_USER
COPY entrypoint.sh bin/hugo-mx-gateway LICENSE /app/
WORKDIR /app
COPY --from=builder /workspace/hugo-mx-gateway .
COPY entrypoint.sh LICENSE /app/
COPY templates /app/templates
RUN chown -R $RUNTIME_USER:$RUNTIME_USER /app
WORKDIR /app
ENTRYPOINT ["sh", "./entrypoint.sh"]