# 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. ARG DISTRO_VERSION=7 FROM centos:${DISTRO_VERSION} AS devtools ARG NCPU=4 ## [START packaging.md] # First install the development tools and OpenSSL. The development tools # distributed with CentOS 7 are too old to build the project. In these # instructions, we use `cmake3` and `gcc-7` obtained from # [Software Collections](https://www.softwarecollections.org/). # ```bash RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm RUN yum install -y centos-release-scl yum-utils RUN yum-config-manager --enable rhel-server-rhscl-7-rpms RUN yum makecache && \ yum install -y automake ccache cmake3 curl-devel devtoolset-7 gcc gcc-c++ \ git libtool make openssl-devel pkgconfig tar wget which zlib-devel RUN ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest # ``` ## [START IGNORED] # In order to use the `devtoolset-7` Software Collection we're supposed to run # `scl enable devtoolset-7 bash`, which starts a new shell with the environment # configured correctly. However, we can't do that in this Dockerfile, AND we # want the instructions that we generate for the user to say the right thing. # So this block is ignored, and we manually set some environment variables to # make the devtoolset-7 available. After this ignored block, we'll include the # correct instructions for the user. NOTE: These env values were obtained by # manually running the `scl ...` command (above) then copying the values set in # its environment. ENV PATH /opt/rh/devtoolset-7/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin ENV LD_LIBRARY_PATH /opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib:/opt/rh/devtoolset-7/root/usr/lib64/dyninst:/opt/rh/devtoolset-7/root/usr/lib/dyninst:/opt/rh/devtoolset-7/root/usr/lib64:/opt/rh/devtoolset-7/root/usr/lib ## [END IGNORED] # Start a bash shell with its environment configured to use the tools installed # by `devtoolset-7`. # **IMPORTANT**: All the following commands should be run from this new shell. # ```bash # scl enable devtoolset-7 bash # ``` # The following steps will install libraries and tools in `/usr/local`. By # default CentOS-7 does not search for shared libraries in these directories, # there are multiple ways to solve this problem, the following steps are one # solution: # ```bash RUN (echo "/usr/local/lib" ; echo "/usr/local/lib64") | \ tee /etc/ld.so.conf.d/usrlocal.conf ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig ENV PATH=/usr/local/bin:${PATH} # ``` # #### Abseil # We need a recent version of Abseil. # ```bash WORKDIR /var/tmp/build RUN wget -q https://github.com/abseil/abseil-cpp/archive/20200225.2.tar.gz && \ tar -xf 20200225.2.tar.gz && \ cd abseil-cpp-20200225.2 && \ sed -i 's/^#define ABSL_OPTION_USE_\(.*\) 2/#define ABSL_OPTION_USE_\1 0/' "absl/base/options.h" && \ cmake \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_TESTING=OFF \ -DBUILD_SHARED_LIBS=yes \ -DCMAKE_CXX_STANDARD=11 \ -H. -Bcmake-out && \ cmake --build cmake-out -- -j ${NCPU:-4} && \ cmake --build cmake-out --target install -- -j ${NCPU:-4} && \ ldconfig # ``` # #### Protobuf # We need to install a version of Protobuf that is recent enough to support the # Google Cloud Platform proto files: # ```bash WORKDIR /var/tmp/build RUN wget -q https://github.com/google/protobuf/archive/v3.11.3.tar.gz && \ tar -xf v3.11.3.tar.gz && \ cd protobuf-3.11.3/cmake && \ cmake \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=yes \ -Dprotobuf_BUILD_TESTS=OFF \ -H. -Bcmake-out && \ cmake --build cmake-out -- -j ${NCPU:-4} && \ cmake --build cmake-out --target install -- -j ${NCPU:-4} && \ ldconfig # ``` # #### c-ares # Recent versions of gRPC require c-ares >= 1.11, while CentOS-7 # distributes c-ares-1.10. Manually install a newer version: # ```bash WORKDIR /var/tmp/build RUN wget -q https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz && \ tar -xf cares-1_14_0.tar.gz && \ cd c-ares-cares-1_14_0 && \ ./buildconf && ./configure && make -j ${NCPU:-4} && \ make install && \ ldconfig # ``` # #### gRPC # We also need a version of gRPC that is recent enough to support the Google # Cloud Platform proto files. We manually install it using: # ```bash WORKDIR /var/tmp/build RUN wget -q https://github.com/grpc/grpc/archive/v1.29.1.tar.gz && \ tar -xf v1.29.1.tar.gz && \ cd grpc-1.29.1 && \ cmake \ -DCMAKE_BUILD_TYPE=Release \ -DgRPC_INSTALL=ON \ -DgRPC_BUILD_TESTS=OFF \ -DgRPC_ABSL_PROVIDER=package \ -DgRPC_CARES_PROVIDER=package \ -DgRPC_PROTOBUF_PROVIDER=package \ -DgRPC_SSL_PROVIDER=package \ -DgRPC_ZLIB_PROVIDER=package \ -H. -Bcmake-out && \ cmake --build cmake-out -- -j ${NCPU:-4} && \ cmake --build cmake-out --target install -- -j ${NCPU:-4} && \ ldconfig # ``` # #### crc32c # The project depends on the Crc32c library, we need to compile this from # source: # ```bash WORKDIR /var/tmp/build RUN wget -q https://github.com/google/crc32c/archive/1.1.0.tar.gz && \ tar -xf 1.1.0.tar.gz && \ cd crc32c-1.1.0 && \ cmake \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=yes \ -DCRC32C_BUILD_TESTS=OFF \ -DCRC32C_BUILD_BENCHMARKS=OFF \ -DCRC32C_USE_GLOG=OFF \ -H. -Bcmake-out && \ cmake --build cmake-out -- -j ${NCPU:-4} && \ cmake --build cmake-out --target install -- -j ${NCPU:-4} && \ ldconfig # ``` # #### nlohmann_json library # The project depends on the nlohmann_json library. We use CMake to # install it as this installs the necessary CMake configuration files. # Note that this is a header-only library, and often installed manually. # This leaves your environment without support for CMake pkg-config. # ```bash WORKDIR /var/tmp/build RUN wget -q https://github.com/nlohmann/json/archive/v3.9.0.tar.gz && \ tar -xzf v3.9.0.tar.gz && \ cd json-3.9.0 && \ cmake \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_SHARED_LIBS=yes \ -DBUILD_TESTING=OFF \ -H. -Bcmake-out/nlohmann/json && \ cmake --build cmake-out/nlohmann/json --target install -- -j ${NCPU} && \ ldconfig # ``` FROM devtools AS install ARG NCPU=4 ARG DISTRO="distro-name" # #### Compile and install the main project # We can now compile, test, and install `google-cloud-cpp`. # ```bash WORKDIR /home/build/project COPY . /home/build/project ## [START IGNORED] # This is just here to speed up the pre-submit builds and should not be part # of the instructions on how to compile the code. ENV CCACHE_DIR=/h/.ccache RUN mkdir -p /h/.ccache; \ echo "max_size = 4.0G" >"/h/.ccache/ccache.conf"; \ if [ -r "ci/kokoro/install/ccache-contents/${DISTRO}.tar.gz" ]; then \ tar -xf "ci/kokoro/install/ccache-contents/${DISTRO}.tar.gz" -C /h; \ ccache --show-stats; \ ccache --zero-stats; \ fi; \ true # Ignore all errors, failures in caching should not break the build ## [END IGNORED] RUN cmake -DBUILD_TESTING=OFF -H. -Bcmake-out RUN cmake --build cmake-out -- -j "${NCPU:-4}" RUN cmake --build cmake-out --target install # ``` ## [END packaging.md] ENV PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig # Verify that the installed files are actually usable WORKDIR /home/build/pubsub-make COPY google/cloud/pubsub/quickstart /home/build/pubsub-make RUN make WORKDIR /home/build/quickstart-cmake/pubsub COPY google/cloud/pubsub/quickstart /home/build/quickstart-cmake/pubsub RUN env -u PKG_CONFIG_PATH cmake -H. -B/i/pubsub RUN cmake --build /i/pubsub WORKDIR /home/build/bigtable-make COPY google/cloud/bigtable/quickstart /home/build/bigtable-make RUN make WORKDIR /home/build/quickstart-cmake/bigtable COPY google/cloud/bigtable/quickstart /home/build/quickstart-cmake/bigtable RUN env -u PKG_CONFIG_PATH cmake -H. -B/i/bigtable RUN cmake --build /i/bigtable WORKDIR /home/build/storage-make COPY google/cloud/storage/quickstart /home/build/storage-make RUN make WORKDIR /home/build/quickstart-cmake/storage COPY google/cloud/storage/quickstart /home/build/quickstart-cmake/storage RUN env -u PKG_CONFIG_PATH cmake -H. -B/i/storage RUN cmake --build /i/storage WORKDIR /home/build/spanner-make COPY google/cloud/spanner/quickstart /home/build/spanner-make RUN make WORKDIR /home/build/quickstart-cmake/spanner COPY google/cloud/spanner/quickstart /home/build/quickstart-cmake/spanner RUN env -u PKG_CONFIG_PATH cmake -H. -B/i/spanner RUN cmake --build /i/spanner # This is just here to speed up the pre-submit builds and should not be part # of the instructions on how to compile the code. RUN ccache --show-stats --zero-stats || true