Skip to content

Commit bd7e471

Browse files
coryanmbrukman
authored andcommitted
Create initial build matrix. (#8)
Build on Mac OS, Ubuntu 17.04, Ubuntu 14.04 and Fedora 27.
1 parent 7041760 commit bd7e471

10 files changed

Lines changed: 323 additions & 15 deletions

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# We do not need the git repository in docker images.
2+
.git/
3+
4+
# We do not need the typical build directories in docker images.
5+
.idea/
6+
.build/
7+
_build/
8+
build-output/
9+
cmake-build-*/

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
build
1+
# Common build output directory names
2+
.build/
3+
_build/
4+
build-output/
5+
6+
# Backup files for Emacs
27
*~
8+
9+
# Ignore IDEA / IntelliJ files
10+
.idea/
11+
cmake-build-*/

.travis.yml

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,49 @@
1414

1515
dist: trusty
1616
sudo: required
17-
lang: cpp
17+
language: cpp
1818

19-
compiler:
20-
- clang
21-
- gcc
19+
# TODO(#19) - this is a skeleton matrix, needs to be designed and completed.
20+
matrix:
21+
include:
22+
- os: linux
23+
compiler: gcc
24+
env: DISTRO=ubuntu DISTRO_VERSION=17.04
25+
- os: linux
26+
compiler: clang
27+
env: DISTRO=ubuntu DISTRO_VERSION=16.04
28+
- os: linux
29+
compiler: gcc
30+
env: DISTRO=ubuntu DISTRO_VERSION=14.04
31+
- os: linux
32+
compiler: gcc
33+
env: DISTRO=fedora DISTRO_VERSION=27
34+
- os: osx
35+
compiler: clang
36+
37+
script:
38+
- ci/build-linux.sh
39+
- ci/build-macosx.sh
40+
41+
# Cache the (saved) Docker images. With recent version of Docker, one can
42+
# reuse a prior image as a source cache, that can speed up the builds, as
43+
# the dependencies and images can be reused.
44+
cache:
45+
directories:
46+
- docker-images/ubuntu/17.04
47+
- docker-images/ubuntu/16.04
48+
- docker-images/ubuntu/14.04
49+
- docker-images/fedora/27
50+
- docker-images/centos/7
2251

2352
install:
24-
- sudo apt-get install -y cmake3
25-
- cmake --version
26-
- git submodule init
27-
- git submodule update --init --recursive
53+
# Restore the Docker image from the cached directory. That way we
54+
# can reuse the steps in the Docker image that install
55+
# pre-requisites and build dependencies.
56+
- ci/install-linux.sh
2857

29-
script:
30-
- mkdir build && cd build && cmake ..
31-
- make all
32-
- make test
58+
before_cache:
59+
- ci/cache-linux.sh
60+
61+
notifications:
62+
email: false

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ after cloning this repo:
1919
```sh
2020
git submodule init
2121
git submodule update --init --recursive
22-
mkdir build
23-
cd build
22+
mkdir build-output
23+
cd build-output
2424
cmake ..
2525
make all
2626
make test

ci/Dockerfile.fedora

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2017 Google Inc.
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=27
16+
FROM fedora:${DISTRO_VERSION}
17+
MAINTAINER "Carlos O'Ryan <coryan@google.com>"
18+
19+
RUN dnf makecache
20+
RUN dnf install -y \
21+
autoconf \
22+
automake \
23+
c-ares-devel \
24+
clang \
25+
cmake \
26+
curl \
27+
doxygen \
28+
gcc-c++ \
29+
git \
30+
golang \
31+
lcov \
32+
libtool \
33+
make \
34+
openssl-devel \
35+
pkgconfig \
36+
python \
37+
shtool \
38+
unzip \
39+
wget \
40+
zlib-devel
41+
42+
ARG NCPU=2
43+
ARG CXX=g++
44+
ARG CC=gcc
45+
46+
# Capture the Travis job number, effectively this busts the cache
47+
# in each build, which we want anyway.
48+
ARG TRAVIS_JOB_NUMBER=""
49+
RUN echo Running build=${TRAVIS_JOB_NUMBER}
50+
51+
# We assume that this is running on a (clean-ish) checkout of
52+
# google-cloud-cpp, including submodules, and copy the files to a
53+
# directory where we will build.
54+
COPY . /var/tmp/build/gccpp
55+
56+
WORKDIR /var/tmp/build/gccpp/build-output
57+
RUN cmake ..
58+
RUN make -j ${NCPU} all
59+
RUN make -j ${NCPU} test || ( cat Testing/Temporary/LastTest.log; exit 1 )

ci/Dockerfile.ubuntu

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Copyright 2017 Google Inc.
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=17.04
16+
FROM ubuntu:${DISTRO_VERSION}
17+
MAINTAINER "Carlos O'Ryan <coryan@google.com>"
18+
19+
RUN apt-get update
20+
RUN apt-get install -y \
21+
build-essential \
22+
git \
23+
gcc \
24+
g++ \
25+
golang \
26+
clang \
27+
cmake \
28+
make \
29+
tar \
30+
wget
31+
32+
# Install packages that are required for 14.04, but do not exist in later
33+
# versions.
34+
RUN if grep -q 14.04 /etc/lsb-release; then apt-get install -y cmake3; fi
35+
36+
# Install optional packages. Their installation fails in 14.04, the matrix
37+
# is (or will be) setup to only use them for other Ubuntu versions.
38+
RUN apt-get install -y \
39+
clang-4.0 \
40+
clang-format \
41+
clang-tidy \
42+
gcc-4.8 \
43+
g++-4.8 \
44+
|| /bin/true
45+
46+
ARG NCPU=2
47+
ARG CXX=g++
48+
ARG CC=gcc
49+
50+
# Capture the Travis job number, effectively this busts the cache
51+
# in each build, which we want anyway.
52+
ARG TRAVIS_JOB_NUMBER=""
53+
RUN echo Running build=${TRAVIS_JOB_NUMBER}
54+
55+
# We assume that this is running on a (clean-ish) checkout of
56+
# google-cloud-cpp, including submodules, and copy the files to a
57+
# directory where we will build.
58+
COPY . /var/tmp/build/gccpp
59+
60+
WORKDIR /var/tmp/build/gccpp/build-output
61+
RUN cmake ..
62+
RUN make -j ${NCPU} all
63+
RUN make -j ${NCPU} test || ( cat Testing/Temporary/LastTest.log; exit 1 )

ci/build-linux.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/sh
2+
# Copyright 2017 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
if [ "${TRAVIS_OS_NAME}" != "linux" ]; then
19+
echo "Not a Linux-based build, exit successfully."
20+
exit 0
21+
fi
22+
23+
readonly IMAGE="cached-${DISTRO?}-${DISTRO_VERSION?}"
24+
readonly LATEST_ID=$(sudo docker inspect -f '{{ .Id }}' ${IMAGE?}:latest 2>/dev/null || echo "")
25+
26+
echo IMAGE = ${IMAGE}
27+
echo IMAGE LATEST ID = ${LATEST_ID}
28+
29+
# TODO() - on cron buiids, we would want to disable the cache
30+
# altogether, to make sure we can still build against recent versions
31+
# of grpc, protobug, the compilers, etc.
32+
cacheargs=""
33+
if [ -z "${LATEST_ID}" ]; then
34+
cacheargs="--cache-from ${IMAGE?}:latest"
35+
fi
36+
37+
echo cache args = ${cacheargs}
38+
39+
sudo docker build -t ${IMAGE?}:tip ${cacheargs?} \
40+
--build-arg DISTRO_VERSION=${DISTRO_VERSION?} \
41+
--build-arg CXX=${CXX?} \
42+
--build-arg CC=${CC?} \
43+
--build-arg TRAVIS_JOB_NUMBER=${TRAVIS_JOB_NUMBER} \
44+
-f ci/Dockerfile.${DISTRO?} .

ci/build-macosx.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
# Copyright 2017 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
if [ "${TRAVIS_OS_NAME}" != "osx" ]; then
19+
echo "Not a Mac OS X build, exit successfully"
20+
exit 0
21+
fi
22+
23+
# On my local workstation I prefer to keep all the build artifacts in
24+
# a sub-directory, not so important for Travis builds, but that makes
25+
# this script easier to test.
26+
test -d .build || mkdir .build
27+
28+
cd .build
29+
cmake ..
30+
make -j ${NCPU:-2}
31+
make -j ${NCPU:-2} test || ( cat Testing/Temporary/LastTest.log; exit 1 )

ci/cache-linux.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# Copyright 2017 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
if [ "${TRAVIS_OS_NAME}" != "linux" ]; then
19+
echo "Not a Linux-based build, exit successfully."
20+
exit 0
21+
fi
22+
23+
readonly IMAGE=cached-${DISTRO?}-${DISTRO_VERSION?}
24+
readonly TARBALL=docker-images/${DISTRO?}/${DISTRO_VERSION?}/saved.tar.gz
25+
26+
# The build creates a new "*:tip" image, we want to save it as
27+
# "*:latest" so it can be used as a cache source in the next build.
28+
sudo docker image tag ${IMAGE?}:tip ${IMAGE?}:latest
29+
30+
sudo docker save ${IMAGE?}:latest | gzip - > ${TARBALL?}

ci/install-linux.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/sh
2+
# Copyright 2017 Google Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -e
17+
18+
if [ "x${TRAVIS_OS_NAME}" != "xlinux" ]; then
19+
echo "Not a Linux-based build, exit successfully."
20+
exit 0
21+
fi
22+
23+
sudo apt-get update
24+
sudo apt-get install -y docker-ce
25+
sudo docker --version
26+
27+
readonly TARBALL=docker-images/${DISTRO?}/${DISTRO_VERSION?}/saved.tar.gz
28+
if [ -f ${TARBALL?} ]; then
29+
gunzip <${TARBALL?} | sudo docker load \
30+
|| echo "Could not load saved image, continuing without cache"
31+
fi
32+
33+
sudo docker image ls

0 commit comments

Comments
 (0)