| 1 | ARG GOLANG_VERSION=1.23
|
| 2 | ARG ALPINE_VERSION=3.21
|
| 3 | ARG PROJECT=helmwave
|
| 4 |
|
| 5 | # Bulder
|
| 6 | FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS builder
|
| 7 | ENV GO111MODULE=on
|
| 8 | ENV CGO_ENABLED=0
|
| 9 | WORKDIR ${PROJECT}
|
| 10 | COPY go.mod go.sum ./
|
| 11 | RUN go mod download
|
| 12 |
|
| 13 | # Copy src code from the host and compile it
|
| 14 | COPY cmd cmd
|
| 15 | COPY pkg pkg
|
| 16 |
|
| 17 | RUN go build -a -o "/${PROJECT}" "./cmd/${PROJECT}"
|
| 18 |
|
| 19 | ## Base image with shell
|
| 20 | FROM alpine:${ALPINE_VERSION} as base-release
|
| 21 | RUN apk --update --no-cache add ca-certificates && update-ca-certificates
|
| 22 | ENTRYPOINT ["/bin/${PROJECT}"]
|
| 23 |
|
| 24 |
|
| 25 | ### Base image with shell and debugging tools
|
| 26 | FROM base-release as base-debug-release
|
| 27 | RUN apk --update --no-cache add jq bash
|
| 28 | COPY --chown=root:root --chmod=0775 --from=bitnami/kubectl:latest /opt/bitnami/kubectl/bin/kubectl /bin/kubectl
|
| 29 |
|
| 30 |
|
| 31 | ### Build with goreleaser
|
| 32 | FROM base-release as goreleaser
|
| 33 | COPY ${PROJECT} /bin/
|
| 34 |
|
| 35 | ### Debug tag, just manually
|
| 36 | FROM base-debug-release as debug-goreleaser
|
| 37 | COPY ${PROJECT} /bin/
|
| 38 |
|
| 39 | ### Build in docker
|
| 40 | FROM base-release as release
|
| 41 | COPY --from=builder /${PROJECT} /bin/
|
| 42 |
|
| 43 | ### Scratch with build in docker
|
| 44 | FROM scratch as scratch-release
|
| 45 | COPY --from=base-release /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
| 46 | COPY --from=builder /${PROJECT} /bin/
|
| 47 | ENTRYPOINT ["/bin/${PROJECT}"]
|
| 48 | USER 65534
|
| 49 |
|
| 50 | ### Scratch with goreleaser
|
| 51 | FROM scratch as scratch-goreleaser
|
| 52 | COPY --from=base-release /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
| 53 | COPY ${PROJECT} /bin/
|
| 54 | ENTRYPOINT ["/bin/${PROJECT}"]
|
| 55 | USER 65534
|