Docker Multistage Build

FROM widnyana/go-builder:1.17-alpine as builder
WORKDIR /app
COPY . /app

ENV GO111MODULE=on \
    CGO_ENABLED=0 \
    GOOS=linux

RUN set -ex \
    && cd /app \
    && go mod download \
        && GIT_TAG=$(git describe --abbrev=0 2> /dev/null || echo "no tag") \
            COMMIT=$(git log -1 --pretty=format:"%at-%h" 2> /dev/null || echo "no commit") \
            COMMIT_MSG=$(git log -1 --pretty=format:"%s"2> /dev/null || echo "no msg") \
            go build -a -i \
                -ldflags "-w \
                    -X 'package/config.CommitMsg=${COMMIT_MSG}' \
                    -X 'package/config.CommitHash=${COMMIT}' \
                    -X 'package/config.AppVersion=${GIT_TAG}'" \
                    -o whatever \
FROM alpine:latest

ARG WHATEVER_HTTP_PORT=2525
WORKDIR /root/
COPY --from=builder /app/whatever .

# Do as you want ...

This site uses Akismet to reduce spam. Learn how your comment data is processed.