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 |
David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame^] | 16 | FROM golang:$GOLANG_VERSION-alpine3.13 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 |
| 21 | ARG PROTOC_GEN_GRPC_GATEWAY_VERSION |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 22 | |
David K. Bainbridge | e33a5bc | 2021-04-06 20:30:58 +0000 | [diff] [blame] | 23 | RUN apk add --no-cache libatomic=10.2.1_pre1-r3 musl=1.2.2-r0 |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 24 | |
| 25 | # download & compile this specific version of protoc-gen-go |
David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame^] | 26 | RUN GO111MODULE=on CGO_ENABLED=0 go get -a -u \ |
Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 27 | github.com/golang/protobuf/protoc-gen-go@v$PROTOC_GEN_GO_VERSION \ |
| 28 | github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v$PROTOC_GEN_GRPC_GATEWAY_VERSION \ |
| 29 | github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger@v$PROTOC_GEN_GRPC_GATEWAY_VERSION |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 30 | |
| 31 | RUN mkdir -p /tmp/protoc3 && \ |
| 32 | wget -O /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip && \ |
| 33 | [ "$(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] | 34 | unzip /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /tmp/protoc3 && \ |
| 35 | chmod -R a+rx /tmp/protoc3/ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 36 | |
David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame^] | 37 | FROM alpine:3.13 as cpp-build |
| 38 | |
| 39 | # Install required packages |
| 40 | RUN apk add --no-cache \ |
| 41 | build-base=0.5-r2 \ |
| 42 | git=2.30.2-r0 \ |
| 43 | cmake=3.18.4-r1 \ |
| 44 | linux-headers=5.7.8-r0 |
| 45 | |
| 46 | WORKDIR /src |
| 47 | |
| 48 | # Clone grpc and submodules |
| 49 | RUN git clone --recurse-submodules -b v1.31.0 \ |
| 50 | --depth=1 --shallow-submodules https://github.com/grpc/grpc |
| 51 | |
| 52 | # Create and configure make environment |
| 53 | RUN mkdir -p /src/grpc/cmake/build |
| 54 | WORKDIR /src/grpc/cmake/build |
| 55 | RUN cmake \ |
| 56 | -DgRPC_INSTALL=ON \ |
| 57 | -DCMAKE_INSTALL_PREFIX=/install \ |
| 58 | -DCMAKE_BUILD_TYPE=Release \ |
| 59 | -DgRPC_ABSL_PROVIDER=module \ |
| 60 | -DgRPC_CARES_PROVIDER=module \ |
| 61 | -DgRPC_PROTOBUF_PROVIDER=module \ |
| 62 | -DgRPC_RE2_PROVIDER=module \ |
| 63 | -DgRPC_SSL_PROVIDER=module \ |
| 64 | -DgRPC_ZLIB_PROVIDER=module \ |
| 65 | ../.. |
| 66 | |
| 67 | # Build the cpp plugin |
| 68 | RUN make grpc_cpp_plugin |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 69 | |
| 70 | FROM busybox:1.31.1-glibc |
| 71 | |
| 72 | # dynamic libs for protoc |
David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame^] | 73 | COPY --from=go-build /usr/lib/libatomic.so.1 /usr/lib/ |
| 74 | COPY --from=go-build /lib/libc.musl-x86_64.so.1 /usr/lib/ |
| 75 | COPY --from=cpp-build /usr/lib/libstdc++.so.6 /usr/lib/ |
| 76 | COPY --from=cpp-build /usr/lib/libgcc_s.so.1 /usr/lib/ |
| 77 | COPY --from=cpp-build /lib/ld-musl-x86_64.so.1 /usr/lib/ |
| 78 | COPY --from=cpp-build /lib/ld-musl-x86_64.so.1 /lib/ |
| 79 | |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 80 | ENV LD_LIBRARY_PATH=/usr/lib |
| 81 | |
| 82 | # protoc & well-known-type definitions |
David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame^] | 83 | COPY --from=go-build /tmp/protoc3/bin/* /usr/local/bin/ |
| 84 | COPY --from=go-build /tmp/protoc3/include/ /usr/local/include/ |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 85 | |
David K. Bainbridge | 278fc16 | 2021-04-21 16:35:56 +0000 | [diff] [blame^] | 86 | # copy protoc-gen-go, protoc-gen-grpc-gateway, protoc-gen-swagger, |
| 87 | # and grpc_cpp_plugin |
| 88 | COPY --from=go-build /go/bin/* /usr/local/bin/ |
| 89 | 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] | 90 | |
| 91 | WORKDIR /app |
| 92 | |
| 93 | # Label image |
| 94 | ARG org_label_schema_version=unknown |
| 95 | ARG org_label_schema_vcs_url=unknown |
| 96 | ARG org_label_schema_vcs_ref=unknown |
| 97 | ARG org_label_schema_build_date=unknown |
| 98 | ARG org_opencord_vcs_commit_date=unknown |
| 99 | ARG org_opencord_vcs_dirty=unknown |
| 100 | ARG PROTOC_VERSION=unknown |
| 101 | ARG PROTOC_GEN_GO_VERSION=unknown |
Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 102 | ARG PROTOC_GEN_GRPC_GATEWAY_VERSION=unknown |
Kent Hagerman | da41d74 | 2020-01-07 14:55:56 -0500 | [diff] [blame] | 103 | |
| 104 | LABEL org.label-schema.schema-version=1.0 \ |
| 105 | org.label-schema.name=voltha-protoc \ |
| 106 | org.label-schema.version=$org_label_schema_version \ |
| 107 | org.label-schema.vcs-url=$org_label_schema_vcs_url \ |
| 108 | org.label-schema.vcs-ref=$org_label_schema_vcs_ref \ |
| 109 | org.label-schema.build-date=$org_label_schema_build_date \ |
| 110 | org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \ |
| 111 | org.opencord.vcs-dirty=$org_opencord_vcs_dirty \ |
| 112 | org.opencord.protoc-version=$PROTOC_VERSION \ |
Kent Hagerman | 1f99b66 | 2020-03-10 17:22:11 -0400 | [diff] [blame] | 113 | org.opencord.protoc-gen-go-version=$PROTOC_GEN_GO_VERSION \ |
| 114 | org.opencord.protoc-gen-grpc-gateway-version=$PROTOC_GEN_GRPC_GATEWAY_VERSION |