2021-03-11 01:59:21 +00:00
|
|
|
FROM --platform=$BUILDPLATFORM golang:1.16.0-alpine3.13 AS builder
|
|
|
|
# ex. amd64
|
|
|
|
ARG TARGETARCH
|
|
|
|
# ex. linux/amd64
|
|
|
|
ARG BUILDPLATFORM
|
|
|
|
|
|
|
|
RUN apk update && \
|
|
|
|
apk add --no-cache git ca-certificates make tzdata gcc libc-dev && \
|
|
|
|
apk add --no-cache -X http://dl-cdn.alpinelinux.org/alpine/edge/testing cfssl && \
|
|
|
|
update-ca-certificates
|
|
|
|
|
|
|
|
ENV USER=appuser
|
|
|
|
ENV UID=10001
|
|
|
|
ENV GID=10001
|
|
|
|
WORKDIR /data
|
|
|
|
|
|
|
|
RUN addgroup \
|
|
|
|
--gid "${GID}" \
|
|
|
|
"${USER}" && \
|
|
|
|
adduser \
|
|
|
|
--disabled-password \
|
|
|
|
--gecos "" \
|
|
|
|
--home "/nonexistent" \
|
|
|
|
--shell "/sbin/nologin" \
|
|
|
|
--no-create-home \
|
|
|
|
--uid "${UID}" \
|
|
|
|
-G "${USER}" \
|
|
|
|
"${USER}"
|
|
|
|
|
|
|
|
COPY Makefile .
|
|
|
|
COPY certs/ certs/
|
|
|
|
RUN make gen-cert
|
|
|
|
|
|
|
|
COPY go.mod .
|
|
|
|
COPY go.sum .
|
|
|
|
RUN make dependencies
|
|
|
|
|
|
|
|
COPY . .
|
|
|
|
# RUN make build-$BINARYNAME GOARCH=$TARGETARCH GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) LDFLAGS='-extldflags="-static"'
|
2021-03-12 23:57:41 +00:00
|
|
|
RUN make build-weather \
|
2021-03-12 01:04:54 +00:00
|
|
|
GOARCH=$TARGETARCH \
|
|
|
|
GOOS=$(echo $BUILDPLATFORM | cut -d'/' -f1) \
|
|
|
|
GOBUILDFLAGS="-a -tags netgo -installsuffix netgo" \
|
|
|
|
LDFLAGS="-w -s -d"
|
2021-03-11 01:59:21 +00:00
|
|
|
|
2021-03-13 03:02:00 +00:00
|
|
|
FROM alpine
|
2021-03-11 01:59:21 +00:00
|
|
|
|
|
|
|
USER appuser:appuser
|
|
|
|
|
|
|
|
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
|
|
|
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
|
|
COPY --from=builder /etc/passwd /etc/passwd
|
|
|
|
COPY --from=builder /etc/group /etc/group
|
2021-03-12 23:57:41 +00:00
|
|
|
COPY --from=builder --chown=appuser:appuser /data/bin/* /go/bin/weather
|
2021-03-13 03:02:00 +00:00
|
|
|
COPY --from=builder --chown=appuser:appuser /data/certs/out/weather* /go/certs/out/
|
2021-03-11 01:59:21 +00:00
|
|
|
|
|
|
|
WORKDIR /go
|
2021-03-12 23:57:41 +00:00
|
|
|
ENTRYPOINT ["/go/bin/weather"]
|