| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 1 | # Copyright 2020-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 15 | ARG GOLANG_VERSION |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 16 | FROM golang:$GOLANG_VERSION-alpine as go-build |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 17 | |
| 18 | ARG PROTOC_VERSION |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 19 | ARG PROTOC_SHA256SUM |
| Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 20 | ARG PROTOC_GEN_GO_VERSION |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 21 | ARG PROTOC_GEN_GO_GRPC_VERSION |
| Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 22 | ARG PROTOC_GEN_GRPC_GATEWAY_VERSION |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 23 | |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 24 | RUN apk add --no-cache libatomic=14.2.0-r6 musl=1.2.5-r10 git=2.49.1-r0 && \ |
| abhay | e336657 | 2024-09-26 11:19:18 +0530 | [diff] [blame] | 25 | mkdir -m 777 /.cache /go/pkg |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 26 | |
| 27 | # download & compile this specific version of protoc-gen-go |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 28 | RUN GO111MODULE=on CGO_ENABLED=0 go install google.golang.org/protobuf/cmd/protoc-gen-go@v$PROTOC_GEN_GO_VERSION && \ |
| 29 | GO111MODULE=on CGO_ENABLED=0 go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v$PROTOC_GEN_GO_GRPC_VERSION && \ |
| abhay | e336657 | 2024-09-26 11:19:18 +0530 | [diff] [blame] | 30 | GO111MODULE=on CGO_ENABLED=0 go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v$PROTOC_GEN_GRPC_GATEWAY_VERSION && \ |
| 31 | GO111MODULE=on CGO_ENABLED=0 go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v$PROTOC_GEN_GRPC_GATEWAY_VERSION && \ |
| 32 | mkdir -p /tmp/protoc3 && \ |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 33 | wget -nv -O /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 34 | [ "$(sha256sum /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip)" = "${PROTOC_SHA256SUM} /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip" ] && \ |
| Kent Hagerman | d84cc44 | 2020-01-29 17:09:14 -0500 | [diff] [blame] | 35 | unzip /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /tmp/protoc3 && \ |
| 36 | chmod -R a+rx /tmp/protoc3/ |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 37 | |
| Andrea Campanella | a13b2c5 | 2021-04-26 11:38:51 +0000 | [diff] [blame] | 38 | ARG GOLANG_VERSION |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 39 | FROM golang:$GOLANG_VERSION-alpine as cpp-build |
| Andrea Campanella | a13b2c5 | 2021-04-26 11:38:51 +0000 | [diff] [blame] | 40 | |
| 41 | ARG PROTOC_GEN_CPP_VERSION |
| David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame] | 42 | |
| 43 | # Install required packages |
| 44 | RUN apk add --no-cache \ |
| abhay | e336657 | 2024-09-26 11:19:18 +0530 | [diff] [blame] | 45 | build-base=0.5-r3 \ |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 46 | git=2.49.1-r0 \ |
| 47 | cmake=3.31.7-r1 \ |
| 48 | linux-headers=6.14.2-r0 \ |
| 49 | perl=5.40.3-r0 |
| David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame] | 50 | |
| 51 | WORKDIR /src |
| 52 | |
| 53 | # Clone grpc and submodules |
| abhay | e336657 | 2024-09-26 11:19:18 +0530 | [diff] [blame] | 54 | # RUN git clone --recurse-submodules -b v${PROTOC_GEN_CPP_VERSION} --depth=1 --shallow-submodules https://github.com/grpc/grpc |
| 55 | # WORKDIR /src/grpc |
| 56 | # Clone the main repository without submodules |
| 57 | RUN git clone -b v${PROTOC_GEN_CPP_VERSION} --depth=1 https://github.com/grpc/grpc /src/grpc |
| 58 | WORKDIR /src/grpc |
| 59 | RUN git config --file .gitmodules submodule.third_party/re2.url https://github.com/google/re2.git && \ |
| 60 | git submodule sync && \ |
| 61 | git submodule update --init --recursive --depth=1 && \ |
| 62 | mkdir -p /src/grpc/cmake/build |
| David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame] | 63 | |
| David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame] | 64 | WORKDIR /src/grpc/cmake/build |
| 65 | RUN cmake \ |
| 66 | -DgRPC_INSTALL=ON \ |
| 67 | -DCMAKE_INSTALL_PREFIX=/install \ |
| 68 | -DCMAKE_BUILD_TYPE=Release \ |
| 69 | -DgRPC_ABSL_PROVIDER=module \ |
| 70 | -DgRPC_CARES_PROVIDER=module \ |
| 71 | -DgRPC_PROTOBUF_PROVIDER=module \ |
| 72 | -DgRPC_RE2_PROVIDER=module \ |
| 73 | -DgRPC_SSL_PROVIDER=module \ |
| 74 | -DgRPC_ZLIB_PROVIDER=module \ |
| abhay | e336657 | 2024-09-26 11:19:18 +0530 | [diff] [blame] | 75 | ../.. && \ |
| 76 | make grpc_cpp_plugin |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 77 | |
| 78 | FROM busybox:1.31.1-glibc |
| 79 | |
| 80 | # dynamic libs for protoc |
| David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame] | 81 | COPY --from=go-build /usr/lib/libatomic.so.1 /usr/lib/ |
| 82 | COPY --from=go-build /lib/libc.musl-x86_64.so.1 /usr/lib/ |
| 83 | COPY --from=cpp-build /usr/lib/libstdc++.so.6 /usr/lib/ |
| 84 | COPY --from=cpp-build /usr/lib/libgcc_s.so.1 /usr/lib/ |
| 85 | COPY --from=cpp-build /lib/ld-musl-x86_64.so.1 /usr/lib/ |
| 86 | COPY --from=cpp-build /lib/ld-musl-x86_64.so.1 /lib/ |
| 87 | |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 88 | ENV LD_LIBRARY_PATH=/usr/lib |
| 89 | |
| 90 | # protoc & well-known-type definitions |
| David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame] | 91 | COPY --from=go-build /tmp/protoc3/bin/* /usr/local/bin/ |
| 92 | COPY --from=go-build /tmp/protoc3/include/ /usr/local/include/ |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 93 | |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 94 | # copy protoc-gen-go, protoc-gen-go-grpc, protoc-gen-grpc-gateway, protoc-gen-swagger, |
| David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame] | 95 | # and grpc_cpp_plugin |
| 96 | COPY --from=go-build /go/bin/* /usr/local/bin/ |
| 97 | COPY --from=cpp-build /src/grpc/cmake/build/grpc_cpp_plugin /usr/local/bin |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 98 | |
| 99 | WORKDIR /app |
| 100 | |
| 101 | # Label image |
| 102 | ARG org_label_schema_version=unknown |
| 103 | ARG org_label_schema_vcs_url=unknown |
| 104 | ARG org_label_schema_vcs_ref=unknown |
| 105 | ARG org_label_schema_build_date=unknown |
| 106 | ARG org_opencord_vcs_commit_date=unknown |
| 107 | ARG org_opencord_vcs_dirty=unknown |
| 108 | ARG PROTOC_VERSION=unknown |
| 109 | ARG PROTOC_GEN_GO_VERSION=unknown |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 110 | ARG PROTOC_GEN_GO_GRPC_VERSION=unknown |
| Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 111 | ARG PROTOC_GEN_GRPC_GATEWAY_VERSION=unknown |
| Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 112 | |
| 113 | LABEL org.label-schema.schema-version=1.0 \ |
| 114 | org.label-schema.name=voltha-protoc \ |
| 115 | org.label-schema.version=$org_label_schema_version \ |
| 116 | org.label-schema.vcs-url=$org_label_schema_vcs_url \ |
| 117 | org.label-schema.vcs-ref=$org_label_schema_vcs_ref \ |
| 118 | org.label-schema.build-date=$org_label_schema_build_date \ |
| 119 | org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \ |
| 120 | org.opencord.vcs-dirty=$org_opencord_vcs_dirty \ |
| 121 | org.opencord.protoc-version=$PROTOC_VERSION \ |
| Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 122 | org.opencord.protoc-gen-go-version=$PROTOC_GEN_GO_VERSION \ |
| Abhay Kumar | 133403d | 2025-12-19 04:56:06 +0000 | [diff] [blame^] | 123 | org.opencord.protoc-gen-go-grpc-version=$PROTOC_GEN_GO_GRPC_VERSION \ |
| Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 124 | org.opencord.protoc-gen-grpc-gateway-version=$PROTOC_GEN_GRPC_GATEWAY_VERSION |