Skip to content

Commit 1d7d828

Browse files
authored
ci(gcb): add demo-centos-7 install build (#6239)
* ci(gcb): add demo-centos-7 install build Part of #6163 This is the first example of how I plan to move what we currently call "install" builds (defined in `ci/kokoro/install`) over to GCB where I plan to call them "demo" builds. The idea is that we'll have a single script called `demo-install.sh` (in this PR) that installs `google-cloud-cpp`, and then tests the install by running the quickstarts. We'll then have a number of `demo-<os>.Dockerfile` files (`demo-centos-7.Dockerfile` is included in this PR), and a number of trigger files, which associate a `demo-<os>` distro with the one `demo-install.sh` script. In subsequent PRs, I'll add more `demo-<os>.Dockerfile`s, and more triggers for the other platforms. Separately, I'll also update the packaging scripts to use these new files for generating the `packaging.md` file. Note about naming: I thought that "install" was a slightly ambiguous term for these builds, and thought "demo" was a little more descriptive since we use these builds to demonstrate how to install the deps and install our library on various platforms. Happy to change the naming back to "install" if others dislike the new naming. * removed unneeded export
1 parent 86f8b9e commit 1d7d828

File tree

4 files changed

+286
-0
lines changed

4 files changed

+286
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
#
3+
# Copyright 2021 Google LLC
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# This build script serves two main purposes:
18+
#
19+
# 1. It demonstrates to users how to install `google-cloud-cpp`. We will
20+
# extract part of this script into user-facing markdown documentation.
21+
# 2. It verifies that the installed artifacts work by compiling and running the
22+
# quickstart programs against the installed artifacts.
23+
24+
set -eu
25+
26+
source "$(dirname "$0")/../../lib/init.sh"
27+
source module ci/cloudbuild/builds/lib/cmake.sh
28+
source module ci/etc/quickstart-config.sh
29+
source module ci/lib/io.sh
30+
31+
## [START packaging.md]
32+
33+
# Pick a location to install the artifacts, e.g., `/usr/local` or `/opt`
34+
PREFIX="${HOME}/google-cloud-cpp-installed"
35+
cmake -DBUILD_TESTING=OFF -DCMAKE_INSTALL_PREFIX="${PREFIX}" -H. -Bcmake-out
36+
cmake --build cmake-out -- -j "$(nproc)"
37+
cmake --build cmake-out --target install
38+
39+
## [END packaging.md]
40+
41+
# Tells pkg-config where the artifacts are, so the Makefile builds work.
42+
export PKG_CONFIG_PATH="${PREFIX}/lib64/pkgconfig:${PKG_CONFIG_PATH:-}"
43+
44+
# Verify that the installed artifacts are usable by running the quickstarts.
45+
for lib in $(quickstart::libraries); do
46+
mapfile -t run_args < <(quickstart::arguments "${lib}")
47+
io::log_h2 "Building quickstart: ${lib}"
48+
if [[ "${PROJECT_ID:-}" != "cloud-cpp-testing-resources" ]]; then
49+
run_args=() # Empties these args so we don't execute quickstarts below
50+
io::log_yellow "Not executing quickstarts," \
51+
"which can only run in GCB project 'cloud-cpp-testing-resources'"
52+
fi
53+
54+
io::log "[ CMake ]"
55+
src_dir="${PROJECT_ROOT}/google/cloud/${lib}/quickstart"
56+
bin_dir="${PROJECT_ROOT}/cmake-out/quickstart-${lib}"
57+
cmake -H"${src_dir}" -B"${bin_dir}" "-DCMAKE_PREFIX_PATH=${PREFIX}"
58+
cmake --build "${bin_dir}"
59+
test "${#run_args[@]}" -eq 0 || "${bin_dir}/quickstart" "${run_args[@]}"
60+
61+
echo
62+
io::log "[ Make ]"
63+
make -C "${src_dir}"
64+
test "${#run_args[@]}" -eq 0 || "${src_dir}/quickstart" "${run_args[@]}"
65+
done
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Copyright 2021 Google LLC
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+
15+
ARG DISTRO_VERSION=7
16+
FROM centos:${DISTRO_VERSION} AS devtools
17+
ARG NCPU=4
18+
19+
## [START packaging.md]
20+
21+
# First install the development tools and OpenSSL. The development tools
22+
# distributed with CentOS 7 are too old to build the project. In these
23+
# instructions, we use `cmake3` and `gcc-7` obtained from
24+
# [Software Collections](https://www.softwarecollections.org/).
25+
26+
# ```bash
27+
RUN rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
28+
RUN yum install -y centos-release-scl yum-utils
29+
RUN yum-config-manager --enable rhel-server-rhscl-7-rpms
30+
RUN yum makecache && \
31+
yum install -y automake ccache cmake3 curl-devel devtoolset-7 gcc gcc-c++ \
32+
git libtool make openssl-devel pkgconfig re2-devel tar wget which \
33+
zlib-devel
34+
RUN ln -sf /usr/bin/cmake3 /usr/bin/cmake && ln -sf /usr/bin/ctest3 /usr/bin/ctest
35+
# ```
36+
37+
## [START IGNORED]
38+
# In order to use the `devtoolset-7` Software Collection we're supposed to run
39+
# `scl enable devtoolset-7 bash`, which starts a new shell with the environment
40+
# configured correctly. However, we can't do that in this Dockerfile, AND we
41+
# want the instructions that we generate for the user to say the right thing.
42+
# So this block is ignored, and we manually set some environment variables to
43+
# make the devtoolset-7 available. After this ignored block, we'll include the
44+
# correct instructions for the user. NOTE: These env values were obtained by
45+
# manually running the `scl ...` command (above) then copying the values set in
46+
# its environment.
47+
ENV PATH /opt/rh/devtoolset-7/root/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
48+
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
49+
## [END IGNORED]
50+
# Start a bash shell with its environment configured to use the tools installed
51+
# by `devtoolset-7`.
52+
# **IMPORTANT**: All the following commands should be run from this new shell.
53+
# ```bash
54+
# scl enable devtoolset-7 bash
55+
# ```
56+
57+
# The following steps will install libraries and tools in `/usr/local`. By
58+
# default CentOS-7 does not search for shared libraries in these directories,
59+
# there are multiple ways to solve this problem, the following steps are one
60+
# solution:
61+
62+
# ```bash
63+
RUN (echo "/usr/local/lib" ; echo "/usr/local/lib64") | \
64+
tee /etc/ld.so.conf.d/usrlocal.conf
65+
ENV PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig
66+
ENV PATH=/usr/local/bin:${PATH}
67+
# ```
68+
69+
# #### Abseil
70+
71+
# We need a recent version of Abseil.
72+
73+
# ```bash
74+
WORKDIR /var/tmp/build
75+
RUN wget -q https://github.com/abseil/abseil-cpp/archive/20200923.3.tar.gz && \
76+
tar -xf 20200923.3.tar.gz && \
77+
cd abseil-cpp-20200923.3 && \
78+
sed -i 's/^#define ABSL_OPTION_USE_\(.*\) 2/#define ABSL_OPTION_USE_\1 0/' "absl/base/options.h" && \
79+
cmake \
80+
-DCMAKE_BUILD_TYPE=Release \
81+
-DBUILD_TESTING=OFF \
82+
-DBUILD_SHARED_LIBS=yes \
83+
-DCMAKE_CXX_STANDARD=11 \
84+
-H. -Bcmake-out && \
85+
cmake --build cmake-out -- -j ${NCPU:-4} && \
86+
cmake --build cmake-out --target install -- -j ${NCPU:-4} && \
87+
ldconfig
88+
# ```
89+
90+
# #### Protobuf
91+
92+
# We need to install a version of Protobuf that is recent enough to support the
93+
# Google Cloud Platform proto files:
94+
95+
# ```bash
96+
WORKDIR /var/tmp/build
97+
RUN wget -q https://github.com/google/protobuf/archive/v3.14.0.tar.gz && \
98+
tar -xf v3.14.0.tar.gz && \
99+
cd protobuf-3.14.0/cmake && \
100+
cmake \
101+
-DCMAKE_BUILD_TYPE=Release \
102+
-DBUILD_SHARED_LIBS=yes \
103+
-Dprotobuf_BUILD_TESTS=OFF \
104+
-H. -Bcmake-out && \
105+
cmake --build cmake-out -- -j ${NCPU:-4} && \
106+
cmake --build cmake-out --target install -- -j ${NCPU:-4} && \
107+
ldconfig
108+
# ```
109+
110+
# #### c-ares
111+
112+
# Recent versions of gRPC require c-ares >= 1.11, while CentOS-7
113+
# distributes c-ares-1.10. Manually install a newer version:
114+
115+
# ```bash
116+
WORKDIR /var/tmp/build
117+
RUN wget -q https://github.com/c-ares/c-ares/archive/cares-1_14_0.tar.gz && \
118+
tar -xf cares-1_14_0.tar.gz && \
119+
cd c-ares-cares-1_14_0 && \
120+
./buildconf && ./configure && make -j ${NCPU:-4} && \
121+
make install && \
122+
ldconfig
123+
# ```
124+
125+
# #### gRPC
126+
127+
# We also need a version of gRPC that is recent enough to support the Google
128+
# Cloud Platform proto files. We manually install it using:
129+
130+
# ```bash
131+
WORKDIR /var/tmp/build
132+
RUN wget -q https://github.com/grpc/grpc/archive/v1.35.0.tar.gz && \
133+
tar -xf v1.35.0.tar.gz && \
134+
cd grpc-1.35.0 && \
135+
cmake \
136+
-DCMAKE_BUILD_TYPE=Release \
137+
-DgRPC_INSTALL=ON \
138+
-DgRPC_BUILD_TESTS=OFF \
139+
-DgRPC_ABSL_PROVIDER=package \
140+
-DgRPC_CARES_PROVIDER=package \
141+
-DgRPC_PROTOBUF_PROVIDER=package \
142+
-DgRPC_RE2_PROVIDER=package \
143+
-DgRPC_SSL_PROVIDER=package \
144+
-DgRPC_ZLIB_PROVIDER=package \
145+
-H. -Bcmake-out && \
146+
cmake --build cmake-out -- -j ${NCPU:-4} && \
147+
cmake --build cmake-out --target install -- -j ${NCPU:-4} && \
148+
ldconfig
149+
# ```
150+
151+
# #### crc32c
152+
153+
# The project depends on the Crc32c library, we need to compile this from
154+
# source:
155+
156+
# ```bash
157+
WORKDIR /var/tmp/build
158+
RUN wget -q https://github.com/google/crc32c/archive/1.1.0.tar.gz && \
159+
tar -xf 1.1.0.tar.gz && \
160+
cd crc32c-1.1.0 && \
161+
cmake \
162+
-DCMAKE_BUILD_TYPE=Release \
163+
-DBUILD_SHARED_LIBS=yes \
164+
-DCRC32C_BUILD_TESTS=OFF \
165+
-DCRC32C_BUILD_BENCHMARKS=OFF \
166+
-DCRC32C_USE_GLOG=OFF \
167+
-H. -Bcmake-out && \
168+
cmake --build cmake-out -- -j ${NCPU:-4} && \
169+
cmake --build cmake-out --target install -- -j ${NCPU:-4} && \
170+
ldconfig
171+
# ```
172+
173+
# #### nlohmann_json library
174+
175+
# The project depends on the nlohmann_json library. We use CMake to
176+
# install it as this installs the necessary CMake configuration files.
177+
# Note that this is a header-only library, and often installed manually.
178+
# This leaves your environment without support for CMake pkg-config.
179+
180+
# ```bash
181+
WORKDIR /var/tmp/build
182+
RUN wget -q https://github.com/nlohmann/json/archive/v3.9.0.tar.gz && \
183+
tar -xzf v3.9.0.tar.gz && \
184+
cd json-3.9.0 && \
185+
cmake \
186+
-DCMAKE_BUILD_TYPE=Release \
187+
-DBUILD_SHARED_LIBS=yes \
188+
-DBUILD_TESTING=OFF \
189+
-H. -Bcmake-out/nlohmann/json && \
190+
cmake --build cmake-out/nlohmann/json --target install -- -j ${NCPU} && \
191+
ldconfig
192+
# ```
193+
194+
## [END packaging.md]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
filename: ci/cloudbuild/cloudbuild.yaml
2+
github:
3+
name: google-cloud-cpp
4+
owner: googleapis
5+
push:
6+
branch: ^master$
7+
name: demo-centos-7-ci
8+
substitutions:
9+
_BUILD_NAME: demo-install
10+
_DISTRO: demo-centos-7
11+
_TRIGGER_TYPE: ci
12+
tags:
13+
- ci
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
filename: ci/cloudbuild/cloudbuild.yaml
2+
github:
3+
name: google-cloud-cpp
4+
owner: googleapis
5+
pullRequest:
6+
branch: ^master$
7+
commentControl: COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY
8+
name: demo-centos-7-pr
9+
substitutions:
10+
_BUILD_NAME: demo-install
11+
_DISTRO: demo-centos-7
12+
_TRIGGER_TYPE: pr
13+
tags:
14+
- pr

0 commit comments

Comments
 (0)