Created
September 5, 2022 14:32
-
-
Save jxsl13/847fd696bc21b78835906e169434023f to your computer and use it in GitHub Desktop.
Go(lang) alpine Dockerfile template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:latest AS builder | |
##### Only for PRIVATE git repositories ##### | |
# required credentials for go package repositories | |
# bitbucket user and token MUST be either URL encoded or only contain alphanumeric characters. | |
# Kaniko --build-arg ${item.key}=${item.value} " | |
#ARG BITBUCKET_USER | |
#ARG BITBUCKET_TOKEN | |
#ARG BITBUCKET_DOMAIN | |
#RUN git config --global url."https://$BITBUCKET_USER:$BITBUCKET_TOKEN@$BITBUCKET_DOMAIN".insteadOf "https://$BITBUCKET_DOMAIN" \ | |
# && go env -w GOPRIVATE=$BITBUCKET_DOMAIN | |
################################################## | |
COPY . /build/ | |
WORKDIR /build/ | |
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -v -o application . | |
FROM alpine:latest | |
RUN apk update && apk --no-cache add \ | |
ca-certificates \ | |
tzdata | |
# change timezone to Europe/Berlin - Jnekins location | |
# https://wiki.alpinelinux.org/wiki/Setting_the_timezone | |
RUN cp /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \ | |
echo "Europe/Berlin" > /etc/timezone && \ | |
apk del tzdata | |
# Create a group and user | |
RUN addgroup -S gruser && adduser -u 1001 -G gruser -S gguser | |
COPY --from=builder --chown=1001:0 /build/application /. | |
# read the README for environment variables | |
USER gguser | |
WORKDIR / | |
CMD ["./application"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment