Skip to content

Commit 2d80501

Browse files
authored
New staged build system based on DESIGN.md (#4)
1 parent 57af7cc commit 2d80501

9 files changed

+131
-0
lines changed

.travis.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: minimal
2+
3+
script:
4+
# Run all stages in one stage at the moment. Docker images are not shared
5+
# between stages.
6+
- ./stage1.sh
7+
- ./stage2.sh

Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Specify the base image to build from as a --build-arg.
2+
ARG BASE_IMAGE
3+
FROM $BASE_IMAGE
4+
5+
# The docker build process is noninteractive
6+
ARG DEBIAN_FRONTEND=noninteractive
7+
8+
# Run the install process using the provided script (chosen using --build-arg)
9+
ARG DOCKER_SCRIPT
10+
COPY docker_scripts/ /scripts/
11+
RUN /scripts/${DOCKER_SCRIPT}

VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.0

common.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
# Get the version from the version file.
4+
export VERSION=$(cat VERSION)
5+
6+
# Use this repository
7+
export DOCKER_REPO=curlbuildimages
8+
9+
10+
# Simple function which uses docker to build images.
11+
build_image()
12+
{
13+
TAG=$1
14+
BASE_IMAGE=$2
15+
DOCKER_SCRIPT=$3
16+
17+
echo "Building ${TAG}:${VERSION} from ${BASE_IMAGE}"
18+
19+
docker build --build-arg BASE_IMAGE=${BASE_IMAGE} \
20+
--build-arg DOCKER_SCRIPT=${DOCKER_SCRIPT} \
21+
-t ${DOCKER_REPO}/${TAG}:${VERSION} \
22+
.
23+
}
24+
25+
# Simple wrapper function which adds the REPOSITORY and VERSION to the given
26+
# BASE_IMAGE, then builds.
27+
build_image_versioned()
28+
{
29+
TAG=$1
30+
BASE_IMAGE=$2
31+
DOCKER_SCRIPT=$3
32+
33+
build_image ${TAG} ${DOCKER_REPO}/${BASE_IMAGE}:${VERSION} ${DOCKER_SCRIPT}
34+
}

docker_scripts/install_base_tools.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
# Print out debug info and fail if a sub-step fails
4+
set -exuo pipefail
5+
6+
# Install the tool needed for `add-apt-repository`.
7+
apt-get -y update
8+
apt-get -y install software-properties-common

docker_scripts/install_clang7.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
3+
# Print out debug info and fail if a sub-step fails
4+
set -exuo pipefail
5+
6+
# Install the necessary repositories for clang:
7+
# - llvm-toolchain-xenial-7
8+
9+
# Use wget to download the key as we're building curl...
10+
apt-get install -y wget
11+
wget http://apt.llvm.org/llvm-snapshot.gpg.key
12+
apt-key add llvm-snapshot.gpg.key
13+
add-apt-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main"
14+
15+
# Install clang7
16+
apt-get -y update
17+
apt-get -y install clang-7
18+
19+
# Install clang-7 as the standard cc and clang++-7 as the standard c++
20+
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-7 10
21+
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-7 10
22+
update-alternatives --install /usr/bin/cc cc /usr/bin/clang 30
23+
update-alternatives --set cc /usr/bin/clang
24+
update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 30
25+
update-alternatives --set c++ /usr/bin/clang++

docker_scripts/install_gcc8.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
# Print out debug info and fail if a sub-step fails
4+
set -exuo pipefail
5+
6+
# Install the necessary repositories for newer gccs:
7+
# - ubuntu-toolchain-r-test
8+
add-apt-repository ppa:ubuntu-toolchain-r/test
9+
10+
# Install gcc-8
11+
apt-get -y update
12+
apt-get -y install gcc-8 g++-8
13+
14+
# Install gcc-8 as the standard cc and g++-8 as the standard c++
15+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 10
16+
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 10
17+
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
18+
update-alternatives --set cc /usr/bin/gcc
19+
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
20+
update-alternatives --set c++ /usr/bin/g++

stage1.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
. common.sh
6+
7+
# Build stage 1. Stage 1 consists of the root base image with some common tools installed.
8+
echo "Building stage 1 (version ${VERSION})"
9+
10+
# Build the root base image from Xenial
11+
build_image base_image ubuntu:xenial-20190515 install_base_tools.sh

stage2.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
. common.sh
6+
7+
# Build stage 2. Stage 2 produces images with gcc-8 and clang-7 installed.
8+
echo "Building stage 2 (version ${VERSION})"
9+
10+
# Build gcc-8. Depends on `base_image` from stage1
11+
build_image_versioned base_gcc8 base_image install_gcc8.sh
12+
13+
# Build clang-7. Depends on `base_image` from stage1
14+
build_image_versioned base_clang7 base_image install_clang7.sh

0 commit comments

Comments
 (0)