Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
154 lines (143 loc) · 7.19 KB
/
Copy pathDockerfile
File metadata and controls
154 lines (143 loc) · 7.19 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Base image
#
FROM ubuntu:focal
#
# Dependencies
#
# Install JDK 11 as sampling heap profiler depends on the new JVMTI APIs
# Install Kitware apt repository. This repository contains newer version of
# CMake. CMake > 3.13 is required to use "module" mode for gRPC dependencies.
# See https://github.com/grpc/grpc/blob/master/BUILDING.md#install-after-build.
# Kitware installs CMake v3.20.5
RUN apt-get update && apt-get install -y software-properties-common apt-transport-https ca-certificates gnupg wget && \
test -f /usr/share/doc/kitware-archive-keyring/copyright || \
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null \
| gpg --dearmor - \
| tee /usr/share/keyrings/kitware-archive-keyring.gpg >/dev/null && \
echo 'deb [signed-by=/usr/share/keyrings/kitware-archive-keyring.gpg] https://apt.kitware.com/ubuntu/ focal main' \
| tee /etc/apt/sources.list.d/kitware.list >/dev/null && \
apt-get update && \
apt-get install kitware-archive-keyring
# Installing openjdk-11-jdk-headless can be very slow due to repo download
# speed.
# Everything we can get through apt-get
RUN apt-get update && apt-get -y -q install \
apt-utils \
autoconf \
automake \
cmake \
curl \
g++ \
git \
libtool \
make \
openjdk-11-jdk-headless \
pkg-config \
unzip \
zlib1g-dev
# openssl
# This openssl (compiled with -fPIC) is used to statically link into the agent
# shared library.
ENV PKG_CONFIG_PATH=/usr/local/ssl/lib/pkgconfig
RUN mkdir /tmp/openssl && cd /tmp/openssl && \
curl -sL https://github.com/openssl/openssl/archive/OpenSSL_1_1_1t.tar.gz | \
tar xzv --strip=1 && \
./config no-shared -fPIC --openssldir=/usr/local/ssl --prefix=/usr/local/ssl && \
make && make install_sw && \
cd ~ && rm -rf /tmp/openssl
# curl
RUN git clone --depth=1 -b curl-8_10_1 https://github.com/curl/curl.git /tmp/curl && \
cd /tmp/curl && \
./buildconf && \
./configure --disable-ldap --disable-shared --without-libssh2 \
--without-librtmp --without-libidn --enable-static \
--without-libidn2 --without-libpsl \
--with-pic --with-ssl=/usr/local/ssl/ && \
make -j && make install && \
cd ~ && rm -rf /tmp/curl
# gflags
RUN git clone --depth=1 -b v2.1.2 https://github.com/gflags/gflags.git /tmp/gflags && \
cd /tmp/gflags && \
mkdir build && cd build && \
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_CXX_FLAGS=-fpic -DGFLAGS_NAMESPACE=google .. && \
make -j && make install && \
cd ~ && rm -rf /tmp/gflags
# google-glog
RUN mkdir /tmp/glog && cd /tmp/glog && \
curl -sL https://github.com/google/glog/archive/v0.4.0.tar.gz | \
tar xzv --strip=1 && ./autogen.sh && ./configure --with-pic && \
make -j && make install && \
cd ~ && rm -rf /tmp/glog
# gRPC & protobuf - build using CMake
# Disable OpenSSL embedding: when it's on, the build
# process of gRPC puts the OpenSSL static object files into the gRPC archive
# which causes link errors later when the agent is linked with the static
# OpenSSL library itself.
# Limit the number of threads used by make, as unlimited threads causes
# memory exhausted error on the Kokoro VM.
# -DCMAKE_CXX_STANDARD=17 is necessary since it is the minimum version supported
# by gRPC dependencies.
#
# See https://github.com/grpc/grpc/blob/v1.66.0/test/distrib/cpp/run_distrib_test_cmake_pkgconfig.sh
RUN git clone --depth=1 --recursive -b v1.66.0 https://github.com/grpc/grpc.git /tmp/grpc && \
cd /tmp/grpc/ && \
# Modern Protobuf (v22+) depends on Abseil. To prevent symbol conflicts and undefined references
# when gRPC links against Protobuf, Abseil must be built and installed as a shared system package
# first from gRPC's submodule. Then both Protobuf and gRPC consume it via package (-D..._ABSL_PROVIDER=package).
# Protobuf CMakeLists.txt moved to repo root in newer releases, so we build in third_party/protobuf/build.
# Step 1: Install Abseil as a shared package first
mkdir -p third_party/abseil-cpp/build && \
(cd third_party/abseil-cpp/build && \
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DABSL_BUILD_TESTING=OFF -DABSL_ENABLE_INSTALL=ON -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib .. && \
make -j8 install) && \
# Step 2: Install Protobuf (using shared Abseil package)
mkdir -p third_party/protobuf/build && \
(cd third_party/protobuf/build && \
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_ABSL_PROVIDER=package -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib .. && \
make -j8 install) && \
# Step 3: Install RE2 and generate re2.pc using RE2's official Makefile target (bundled version in gRPC v1.66.0 lacks CMake .pc generation)
mkdir -p third_party/re2/build && \
(cd third_party/re2/build && \
cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DRE2_BUILD_TESTING=OFF -DCMAKE_CXX_STANDARD=17 -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_LIBDIR=lib .. && \
make -j8 install && \
make -C .. common-install prefix=/usr/local) && \
# Step 4: Install gRPC (using shared Abseil, Protobuf, and RE2 packages)
mkdir -p cmake/build && \
(cd cmake/build && \
cmake \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DOPENSSL_ROOT_DIR=/usr/local/ssl \
-DOPENSSL_INCLUDE_DIR=/usr/local/ssl/include \
-DOPENSSL_CRYPTO_LIB=/usr/local/ssl/lib \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_INSTALL_PREFIX=/usr/local/grpc \
-DCMAKE_INSTALL_LIBDIR=lib \
-DgRPC_INSTALL=ON \
-DgRPC_BUILD_TESTS=OFF \
-DgRPC_ABSL_PROVIDER=package \
-DgRPC_CARES_PROVIDER=module \
-DgRPC_RE2_PROVIDER=package \
-DgRPC_ZLIB_PROVIDER=module \
-DgRPC_PROTOBUF_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
../.. && \
make -j8 install) && \
cd ~ && rm -rf /tmp/grpc
# Add /usr/local/grpc/lib64/pkgconfig and /usr/local/lib/pkgconfig as 64-bit builds on Focal may install .pc files there.
ENV PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/ssl/lib/pkgconfig:/usr/local/grpc/lib/pkgconfig:/usr/local/grpc/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/share/pkgconfig"
ENV PATH="${PATH}:/usr/local/grpc/bin"