-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
84 lines (77 loc) · 4 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# syntax=docker/dockerfile:1.3
ARG GOLANG_VERSION
ARG ALPINE_VERSION
FROM debian:bullseye-slim AS protoc-builder
ENV DEBIAN_FRONTEND=noninteractive
ARG PROTOC_VERSION
RUN set -eux && \
apt-get -qy update && \
apt-get -qy --no-install-recommends install \
ca-certificates \
unzip \
wget
RUN set -eux && \
wget -q https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \
unzip protoc-${PROTOC_VERSION}-linux-x86_64.zip -d protoc && \
rm protoc-${PROTOC_VERSION}-linux-x86_64.zip
FROM gcr.io/distroless/base:nonroot AS protoc
COPY --from=protoc-builder --chown=nonroot:nonroot /protoc/bin/protoc /
COPY --from=protoc-builder --chown=nonroot:nonroot /protoc/include/google/ /usr/local/include/google
USER nonroot:nonroot
LABEL maintainer="The containerz Authors" \
org.opencontainers.image.title="gcr.io/containerz/protoc/protoc" \
org.opencontainers.image.description="protoc container image" \
org.opencontainers.image.url="https://github.com/containerz-dev/protoc" \
org.opencontainers.image.source="git@github.com:containerz-dev/protoc"
ENTRYPOINT ["/protoc"]
FROM gcr.io/distroless/base:debug-nonroot AS protoc-debug
COPY --from=protoc-builder --chown=nonroot:nonroot /protoc/bin/protoc /
COPY --from=protoc-builder --chown=nonroot:nonroot /protoc/include/google/ /usr/local/include/google
USER nonroot:nonroot
LABEL maintainer="The containerz Authors" \
org.opencontainers.image.title="gcr.io/containerz/protoc/protoc:debug" \
org.opencontainers.image.description="protoc container image" \
org.opencontainers.image.url="https://github.com/containerz-dev/protoc" \
org.opencontainers.image.source="git@github.com:containerz-dev/protoc"
ENTRYPOINT ["/protoc"]
FROM golang:${GOLANG_VERSION}-alpine${ALPINE_VERSION} AS golang-builder
ENV \
OUTDIR=/out \
CGO_ENABLED=0 \
GO111MODULE=on
RUN set -eux && \
apk add --no-cache \
build-base \
git
ARG PROTOC_GEN_GO_VERSION
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache \
set -eux && \
GOBIN="${OUTDIR}/usr/local/bin" go install -v -tags='osusergo,netgo,static,static_build' -buildmode=pie -ldflags='-s -w -d -linkmode external "-extldflags=-static-pie"' -installsuffix='netgo' \
google.golang.org/protobuf/cmd/protoc-gen-go@${PROTOC_GEN_GO_VERSION}
ARG PROTOC_GEN_GO_GRPC_VERSION
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache \
set -eux && \
GOBIN="${OUTDIR}/usr/local/bin" go install -v -tags='osusergo,netgo,static,static_build' -buildmode=pie -ldflags='-s -w -d -linkmode external "-extldflags=-static-pie"' -installsuffix='netgo' \
google.golang.org/grpc/cmd/protoc-gen-go-grpc@${PROTOC_GEN_GO_GRPC_VERSION}
FROM gcr.io/distroless/base:nonroot AS golang
USER nonroot:nonroot
COPY --from=golang-builder --chown=nonroot:nonroot /out/ /
COPY --from=protoc --chown=nonroot:nonroot /protoc /usr/local/bin/protoc
COPY --from=protoc --chown=nonroot:nonroot /usr/local/include /usr/local/include/
LABEL maintainer="The containerz Authors" \
org.opencontainers.image.title="gcr.io/containerz/protoc/golang" \
org.opencontainers.image.description="protoc and protoc-gen-go related binaries container image" \
org.opencontainers.image.url="https://github.com/containerz-dev/protoc" \
org.opencontainers.image.source="git@github.com:containerz-dev/protoc"
ENTRYPOINT ["protoc"]
FROM gcr.io/distroless/base:debug-nonroot AS golang-debug
USER nonroot:nonroot
COPY --from=golang-builder --chown=nonroot:nonroot /out/ /
COPY --from=protoc-debug --chown=nonroot:nonroot /protoc /usr/local/bin/protoc
COPY --from=protoc-debug --chown=nonroot:nonroot /usr/local/include /usr/local/include/
LABEL maintainer="The containerz Authors" \
org.opencontainers.image.title="gcr.io/containerz/protoc/golang:debug" \
org.opencontainers.image.description="protoc and protoc-gen-go related binaries container image" \
org.opencontainers.image.url="https://github.com/containerz-dev/protoc" \
org.opencontainers.image.source="git@github.com:containerz-dev/protoc"
ENTRYPOINT ["protoc"]