blob: 71a794ff1469752c5a78c562f1d274663064a317 [file] [log] [blame]
Kent Hagermanda41d742020-01-07 14:55:56 -05001# 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. Bainbridgee33a5bc2021-04-06 20:30:58 +000015ARG GOLANG_VERSION
madhumatigoudaf8af3e82026-03-06 17:28:16 +053016FROM golang:$GOLANG_VERSION-alpine AS go-build
Kent Hagermanda41d742020-01-07 14:55:56 -050017
18ARG PROTOC_VERSION
Kent Hagermanda41d742020-01-07 14:55:56 -050019ARG PROTOC_SHA256SUM
Kent Hagerman1f99b662020-03-10 17:22:11 -040020ARG PROTOC_GEN_GO_VERSION
Abhay Kumar133403d2025-12-19 04:56:06 +000021ARG PROTOC_GEN_GO_GRPC_VERSION
Kent Hagerman1f99b662020-03-10 17:22:11 -040022ARG PROTOC_GEN_GRPC_GATEWAY_VERSION
Kent Hagermanda41d742020-01-07 14:55:56 -050023
madhumatigoudaf8af3e82026-03-06 17:28:16 +053024RUN apk add --no-cache libatomic=15.2.0-r2 musl=1.2.5-r21 git=2.52.0-r0 && \
abhaye3366572024-09-26 11:19:18 +053025 mkdir -m 777 /.cache /go/pkg
Kent Hagermanda41d742020-01-07 14:55:56 -050026
27# download & compile this specific version of protoc-gen-go
Abhay Kumar133403d2025-12-19 04:56:06 +000028RUN 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 && \
madhumatigoudaf8af3e82026-03-06 17:28:16 +053030 GO111MODULE=on CGO_ENABLED=0 go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway@v$PROTOC_GEN_GRPC_GATEWAY_VERSION && \
abhaye3366572024-09-26 11:19:18 +053031 mkdir -p /tmp/protoc3 && \
Abhay Kumar133403d2025-12-19 04:56:06 +000032 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 Hagermanda41d742020-01-07 14:55:56 -050033 [ "$(sha256sum /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip)" = "${PROTOC_SHA256SUM} /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip" ] && \
Kent Hagermand84cc442020-01-29 17:09:14 -050034 unzip /tmp/protoc-${PROTOC_VERSION}-linux-x86_64.zip -d /tmp/protoc3 && \
35 chmod -R a+rx /tmp/protoc3/
Kent Hagermanda41d742020-01-07 14:55:56 -050036
Andrea Campanellaa13b2c52021-04-26 11:38:51 +000037ARG GOLANG_VERSION
madhumatigoudaf8af3e82026-03-06 17:28:16 +053038FROM golang:$GOLANG_VERSION-alpine AS cpp-build
Andrea Campanellaa13b2c52021-04-26 11:38:51 +000039
40ARG PROTOC_GEN_CPP_VERSION
David K. Bainbridge278fc162021-04-21 16:35:56 +000041
42# Install required packages
43RUN apk add --no-cache \
abhaye3366572024-09-26 11:19:18 +053044 build-base=0.5-r3 \
madhumatigoudaf8af3e82026-03-06 17:28:16 +053045 git=2.52.0-r0 \
46 cmake=4.1.3-r0 \
47 linux-headers=6.16.12-r0 \
48 perl=5.42.0-r0
David K. Bainbridge278fc162021-04-21 16:35:56 +000049
50WORKDIR /src
51
52# Clone grpc and submodules
abhaye3366572024-09-26 11:19:18 +053053# RUN git clone --recurse-submodules -b v${PROTOC_GEN_CPP_VERSION} --depth=1 --shallow-submodules https://github.com/grpc/grpc
54# WORKDIR /src/grpc
55# Clone the main repository without submodules
56RUN git clone -b v${PROTOC_GEN_CPP_VERSION} --depth=1 https://github.com/grpc/grpc /src/grpc
57WORKDIR /src/grpc
58RUN git config --file .gitmodules submodule.third_party/re2.url https://github.com/google/re2.git && \
59 git submodule sync && \
60 git submodule update --init --recursive --depth=1 && \
61 mkdir -p /src/grpc/cmake/build
David K. Bainbridge278fc162021-04-21 16:35:56 +000062
David K. Bainbridge278fc162021-04-21 16:35:56 +000063WORKDIR /src/grpc/cmake/build
64RUN cmake \
65 -DgRPC_INSTALL=ON \
66 -DCMAKE_INSTALL_PREFIX=/install \
67 -DCMAKE_BUILD_TYPE=Release \
68 -DgRPC_ABSL_PROVIDER=module \
69 -DgRPC_CARES_PROVIDER=module \
70 -DgRPC_PROTOBUF_PROVIDER=module \
71 -DgRPC_RE2_PROVIDER=module \
72 -DgRPC_SSL_PROVIDER=module \
73 -DgRPC_ZLIB_PROVIDER=module \
abhaye3366572024-09-26 11:19:18 +053074 ../.. && \
75 make grpc_cpp_plugin
Kent Hagermanda41d742020-01-07 14:55:56 -050076
77FROM busybox:1.31.1-glibc
78
79# dynamic libs for protoc
David K. Bainbridge278fc162021-04-21 16:35:56 +000080COPY --from=go-build /usr/lib/libatomic.so.1 /usr/lib/
81COPY --from=go-build /lib/libc.musl-x86_64.so.1 /usr/lib/
82COPY --from=cpp-build /usr/lib/libstdc++.so.6 /usr/lib/
83COPY --from=cpp-build /usr/lib/libgcc_s.so.1 /usr/lib/
84COPY --from=cpp-build /lib/ld-musl-x86_64.so.1 /usr/lib/
85COPY --from=cpp-build /lib/ld-musl-x86_64.so.1 /lib/
86
Kent Hagermanda41d742020-01-07 14:55:56 -050087ENV LD_LIBRARY_PATH=/usr/lib
88
89# protoc & well-known-type definitions
David K. Bainbridge278fc162021-04-21 16:35:56 +000090COPY --from=go-build /tmp/protoc3/bin/* /usr/local/bin/
91COPY --from=go-build /tmp/protoc3/include/ /usr/local/include/
Kent Hagermanda41d742020-01-07 14:55:56 -050092
Abhay Kumar133403d2025-12-19 04:56:06 +000093# copy protoc-gen-go, protoc-gen-go-grpc, protoc-gen-grpc-gateway, protoc-gen-swagger,
David K. Bainbridge278fc162021-04-21 16:35:56 +000094# and grpc_cpp_plugin
95COPY --from=go-build /go/bin/* /usr/local/bin/
96COPY --from=cpp-build /src/grpc/cmake/build/grpc_cpp_plugin /usr/local/bin
Kent Hagermanda41d742020-01-07 14:55:56 -050097
98WORKDIR /app
99
100# Label image
101ARG org_label_schema_version=unknown
102ARG org_label_schema_vcs_url=unknown
103ARG org_label_schema_vcs_ref=unknown
104ARG org_label_schema_build_date=unknown
105ARG org_opencord_vcs_commit_date=unknown
106ARG org_opencord_vcs_dirty=unknown
107ARG PROTOC_VERSION=unknown
108ARG PROTOC_GEN_GO_VERSION=unknown
Abhay Kumar133403d2025-12-19 04:56:06 +0000109ARG PROTOC_GEN_GO_GRPC_VERSION=unknown
Kent Hagerman1f99b662020-03-10 17:22:11 -0400110ARG PROTOC_GEN_GRPC_GATEWAY_VERSION=unknown
Kent Hagermanda41d742020-01-07 14:55:56 -0500111
112LABEL org.label-schema.schema-version=1.0 \
113 org.label-schema.name=voltha-protoc \
114 org.label-schema.version=$org_label_schema_version \
115 org.label-schema.vcs-url=$org_label_schema_vcs_url \
116 org.label-schema.vcs-ref=$org_label_schema_vcs_ref \
117 org.label-schema.build-date=$org_label_schema_build_date \
118 org.opencord.vcs-commit-date=$org_opencord_vcs_commit_date \
119 org.opencord.vcs-dirty=$org_opencord_vcs_dirty \
120 org.opencord.protoc-version=$PROTOC_VERSION \
Kent Hagerman1f99b662020-03-10 17:22:11 -0400121 org.opencord.protoc-gen-go-version=$PROTOC_GEN_GO_VERSION \
Abhay Kumar133403d2025-12-19 04:56:06 +0000122 org.opencord.protoc-gen-go-grpc-version=$PROTOC_GEN_GO_GRPC_VERSION \
Kent Hagerman1f99b662020-03-10 17:22:11 -0400123 org.opencord.protoc-gen-grpc-gateway-version=$PROTOC_GEN_GRPC_GATEWAY_VERSION