|
1 | | -# Builder image to build go program. |
2 | | -FROM golang:1.25.2 AS builder |
| 1 | +# Builder stage |
| 2 | +FROM golang:1.25.5-bookworm AS builder |
3 | 3 |
|
4 | 4 | COPY protoc-gen-auth /protoc-gen-auth |
5 | 5 | RUN cd /protoc-gen-auth \ |
6 | 6 | && go build -o /usr/local/bin/protoc-gen-auth . \ |
7 | 7 | && chmod +x /usr/local/bin/protoc-gen-auth |
8 | 8 |
|
9 | | -# Codegen image which is actually being used. |
10 | | -FROM golang:1.25.2 |
11 | | - |
12 | | -# This is version of protobuf installed in the image. |
13 | | -# See https://pkgs.alpinelinux.org/packages?name=protobuf&branch=v3.16 |
14 | | -# NOTE: Start from protobuf v3.20.1, the protoc-gen-js is not included in protobuf package. |
15 | | -ENV PROTOC_GEN_JS_VER=3.21.2 |
16 | 9 | ENV PROTOC_GEN_GO_VER=1.27.1 |
17 | | -ENV PROTOC_GEN_GRPC_WEB_VER=1.3.1 |
18 | 10 | ENV PROTOC_GEN_GO_GRPC_VER=1.2.0 |
19 | 11 | ENV PROTOC_GEN_VALIDATE_VER=0.6.6 |
20 | 12 | ENV GOMOCK_VER=0.6.0 |
21 | 13 |
|
22 | | -# dependecies and protoc |
23 | | -RUN apt update && apt install -y protobuf-compiler |
24 | | - |
25 | | -# protoc-gen-go |
26 | 14 | RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@v${PROTOC_GEN_GO_VER} |
27 | | - |
28 | | -# protoc-gen-go-grpc |
29 | 15 | RUN go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v${PROTOC_GEN_GO_GRPC_VER} |
| 16 | +RUN go install github.com/envoyproxy/protoc-gen-validate@v${PROTOC_GEN_VALIDATE_VER} |
| 17 | +RUN go install go.uber.org/mock/mockgen@v${GOMOCK_VER} |
| 18 | + |
| 19 | +RUN wget -q https://github.com/envoyproxy/protoc-gen-validate/archive/refs/tags/v${PROTOC_GEN_VALIDATE_VER}.tar.gz -O protoc-gen-validate.tar.gz \ |
| 20 | + && mkdir -p /proto-validate \ |
| 21 | + && tar xzf protoc-gen-validate.tar.gz -C /proto-validate --strip-components=1 \ |
| 22 | + && rm protoc-gen-validate.tar.gz |
| 23 | + |
| 24 | +# Runtime stage |
| 25 | +FROM debian:bookworm-slim |
| 26 | + |
| 27 | +ENV PROTOC_GEN_JS_VER=3.21.2 |
| 28 | +ENV PROTOC_GEN_GRPC_WEB_VER=1.3.1 |
| 29 | + |
| 30 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 31 | + protobuf-compiler \ |
| 32 | + wget \ |
| 33 | + ca-certificates \ |
| 34 | + && rm -rf /var/lib/apt/lists/* |
| 35 | + |
| 36 | +COPY --from=builder /go/bin/protoc-gen-go /usr/local/bin/ |
| 37 | +COPY --from=builder /go/bin/protoc-gen-go-grpc /usr/local/bin/ |
| 38 | +COPY --from=builder /go/bin/protoc-gen-validate /usr/local/bin/ |
| 39 | +COPY --from=builder /go/bin/mockgen /usr/local/bin/ |
| 40 | +COPY --from=builder /usr/local/bin/protoc-gen-auth /usr/local/bin/ |
| 41 | +COPY --from=builder /proto-validate /go/src/github.com/envoyproxy/protoc-gen-validate |
30 | 42 |
|
31 | | -# protoc-gen-grpc-web |
32 | | -RUN wget https://github.com/grpc/grpc-web/releases/download/${PROTOC_GEN_GRPC_WEB_VER}/protoc-gen-grpc-web-${PROTOC_GEN_GRPC_WEB_VER}-linux-x86_64 \ |
| 43 | +RUN wget -q https://github.com/grpc/grpc-web/releases/download/${PROTOC_GEN_GRPC_WEB_VER}/protoc-gen-grpc-web-${PROTOC_GEN_GRPC_WEB_VER}-linux-x86_64 \ |
33 | 44 | && mv protoc-gen-grpc-web-${PROTOC_GEN_GRPC_WEB_VER}-linux-x86_64 /usr/local/bin/protoc-gen-grpc-web \ |
34 | 45 | && chmod +x /usr/local/bin/protoc-gen-grpc-web |
35 | 46 |
|
36 | | -# protoc-gen-validate |
37 | | -RUN go install github.com/envoyproxy/protoc-gen-validate@v${PROTOC_GEN_VALIDATE_VER} \ |
38 | | - && wget -q https://github.com/envoyproxy/protoc-gen-validate/archive/refs/tags/v${PROTOC_GEN_VALIDATE_VER}.tar.gz -O protoc-gen-validate.tar.gz \ |
39 | | - && mkdir -p /go/src/github.com/envoyproxy \ |
40 | | - && tar xvfz protoc-gen-validate.tar.gz -C /go/src/github.com/envoyproxy \ |
41 | | - && rm protoc-gen-validate.tar.gz \ |
42 | | - && mv /go/src/github.com/envoyproxy/protoc-gen-validate-${PROTOC_GEN_VALIDATE_VER} /go/src/github.com/envoyproxy/protoc-gen-validate |
43 | | - |
44 | | -# protoc-gen-js |
45 | | -# This is a workaround to use it https://github.com/protocolbuffers/protobuf-javascript/issues/127#issuecomment-1361047597 |
| 47 | +# See: https://github.com/protocolbuffers/protobuf-javascript/issues/127#issuecomment-1361047597 |
46 | 48 | RUN for target in x86_64 aarch_64; do \ |
47 | 49 | mkdir /protoc-gen-js-${target} && cd /protoc-gen-js-${target} \ |
48 | | - && wget https://github.com/protocolbuffers/protobuf-javascript/releases/download/v${PROTOC_GEN_JS_VER}/protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz \ |
49 | | - && tar xvfz protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz \ |
| 50 | + && wget -q https://github.com/protocolbuffers/protobuf-javascript/releases/download/v${PROTOC_GEN_JS_VER}/protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz \ |
| 51 | + && tar xzf protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz \ |
50 | 52 | && chmod +x bin/protoc-gen-js \ |
51 | | - && rm -rf protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz; \ |
| 53 | + && rm -f protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz; \ |
52 | 54 | done && \ |
53 | 55 | mv /protoc-gen-js-aarch_64/ /protoc-gen-js-aarch64/ |
54 | 56 |
|
55 | | -# protoc-gen-auth |
56 | | -COPY --from=builder /usr/local/bin/protoc-gen-auth /usr/local/bin/ |
57 | | - |
58 | | -# gomock |
59 | | -RUN go install go.uber.org/mock/mockgen@v${GOMOCK_VER} |
| 57 | +RUN apt-get purge -y wget ca-certificates && apt-get autoremove -y && rm -rf /var/lib/apt/lists/* |
60 | 58 |
|
61 | 59 | VOLUME /repo |
62 | 60 | WORKDIR /repo |
0 commit comments