Skip to content

Commit 93c4408

Browse files
authored
[ML] Add a dev-tools/ci script to automate the Linux/macOS portion of the CI (#29)
To facilitate migration from ML team CI to Infra CI we need to make the steps triggered by Jenkins as simple as possible. This change adds a ci script that can be used for Linux/macOS.
1 parent ceda200 commit 93c4408

File tree

7 files changed

+199
-0
lines changed

7 files changed

+199
-0
lines changed

dev-tools/ci

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
#
3+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
# or more contributor license agreements. Licensed under the Elastic License;
5+
# you may not use this file except in compliance with the Elastic License.
6+
#
7+
8+
# The non-Windows part of ML C++ CI:
9+
#
10+
# 1. Build and unit test the Linux version of the C++
11+
# 2. Build the macOS version of the C++
12+
# 3. Upload the builds to the artifacts directory on S3 that
13+
# subsequent Java builds will download the C++ components from
14+
#
15+
# The builds run in Docker containers that ensure OS dependencies
16+
# are appropriate given the support matrix.
17+
#
18+
# The macOS build cannot be unit tested as it is cross-compiled.
19+
20+
set -e
21+
22+
# Change directory to the directory containing this script
23+
cd `dirname $0`
24+
25+
# Default to a snapshot build
26+
if [ -z "$SNAPSHOT" ] ; then
27+
SNAPSHOT=yes
28+
fi
29+
30+
# Remove any old builds
31+
rm -rf ../builds
32+
33+
# Build and test Linux
34+
./docker_test.sh linux
35+
36+
# Build macOS
37+
./docker_build.sh macosx
38+
39+
# Upload
40+
cd ..
41+
./gradlew --info -b upload.gradle upload
42+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
#
3+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
# or more contributor license agreements. Licensed under the Elastic License;
5+
# you may not use this file except in compliance with the Elastic License.
6+
#
7+
8+
# Builds the Docker image that can be used to unit test the machine learning
9+
# C++ code for Linux.
10+
#
11+
# This script is not intended to be run regularly. When changing the tools
12+
# or 3rd party components required to build the machine learning C++ code
13+
# increment the version, change the Dockerfile and build a new image to be
14+
# used for subsequent builds on this branch. Then update the version to be
15+
# used for builds in docker/linux_builder/Dockerfile.
16+
17+
ACCOUNT=droberts195
18+
REPOSITORY=ml-linux-test
19+
VERSION=2
20+
21+
set -e
22+
23+
cd `dirname $0`
24+
25+
docker build --no-cache -t $ACCOUNT/$REPOSITORY:$VERSION linux_test_image
26+
docker login
27+
docker push $ACCOUNT/$REPOSITORY:$VERSION
28+

dev-tools/docker/docker_entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ mkdir ../distributions
4545
zip -9 ../distributions/$ARTIFACT_NAME-$PRODUCT_VERSION-$BUNDLE_PLATFORM.zip `find * | egrep -v '\.lib$|libMlTest|\.dSYM|-debug$|\.pdb$|/core'`
4646
# Include only debug files
4747
zip -9 ../distributions/$ARTIFACT_NAME-debug-$PRODUCT_VERSION-$BUNDLE_PLATFORM.zip `find * | egrep '\.dSYM|-debug$|\.pdb$'`
48+
cd ../..
49+
50+
if [ "x$1" = "x--test" ] ; then
51+
make -j`grep -c '^processor' /proc/cpuinfo` ML_KEEP_GOING=1 test
52+
fi
4853

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
# or more contributor license agreements. Licensed under the Elastic License;
4+
# you may not use this file except in compliance with the Elastic License.
5+
#
6+
7+
# Increment the version here when a new tools/3rd party components image is built
8+
FROM droberts195/ml-linux-build:3
9+
10+
MAINTAINER David Roberts <dave.roberts@elastic.co>
11+
12+
# Build cppunit
13+
RUN \
14+
wget --quiet -O - http://dev-www.libreoffice.org/src/cppunit-1.13.2.tar.gz | tar zxf - && \
15+
cd cppunit-1.13.2 && \
16+
./configure --prefix=/usr/local/gcc73 && \
17+
make -j`grep -c '^processor' /proc/cpuinfo` && \
18+
make install && \
19+
cd .. && \
20+
rm -rf cppunit-1.13.2
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
# or more contributor license agreements. Licensed under the Elastic License;
4+
# you may not use this file except in compliance with the Elastic License.
5+
#
6+
7+
# Increment the version here when a new unit test image is built
8+
FROM droberts195/ml-linux-test:2
9+
10+
MAINTAINER David Roberts <dave.roberts@elastic.co>
11+
12+
# Copy the current Git repository into the container
13+
COPY . /ml-cpp/
14+
15+
# Pass through whether this is a snapshot build (default yes if not specified)
16+
ARG SNAPSHOT=yes
17+
18+
# Run the build and unit tests
19+
RUN \
20+
/ml-cpp/dev-tools/docker/docker_entrypoint.sh --test
21+

dev-tools/docker_build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ cd "$TOOLS_DIR/.."
6060
for PLATFORM in `echo $PLATFORMS | tr ' ' '\n' | sort -u`
6161
do
6262

63+
# This Dockerfile is for the temporary image that is used to do the build.
64+
# It is based on a pre-built build image stored on Docker Hub, but will have
65+
# the local repository contents copied into it before the entrypoint script
66+
# is run. This temporary image is discarded after the build is complete.
6367
DOCKERFILE="$TOOLS_DIR/docker/${PLATFORM}_builder/Dockerfile"
6468
TEMP_TAG=`git rev-parse --short=14 HEAD`-$PLATFORM-$$
6569

dev-tools/docker_test.sh

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
#
3+
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4+
# or more contributor license agreements. Licensed under the Elastic License;
5+
# you may not use this file except in compliance with the Elastic License.
6+
#
7+
8+
# Builds the machine learning C++ code for Linux in a Docker container,
9+
# then runs the unit tests.
10+
#
11+
# The output .zip files are then copied out of the container to the
12+
# location in the current repository that they'd be in had they been
13+
# built outside of Docker.
14+
#
15+
# Finally, the Docker container used for the build/test is deleted.
16+
17+
usage()
18+
{
19+
echo "Usage: $0 linux ..."
20+
exit 1
21+
}
22+
23+
PLATFORMS=
24+
25+
while [ -n "$1" ]
26+
do
27+
28+
case "$1" in
29+
linux)
30+
PLATFORMS="$1 $PLATFORMS"
31+
;;
32+
*)
33+
usage
34+
;;
35+
esac
36+
37+
shift
38+
39+
done
40+
41+
if [ -z "$PLATFORMS" ] ; then
42+
usage
43+
fi
44+
45+
# Default to a snapshot build
46+
if [ -z "$SNAPSHOT" ] ; then
47+
SNAPSHOT=yes
48+
fi
49+
50+
set -e
51+
52+
# The build needs to be done with the Docker context set to the root of the
53+
# repository so that we can copy it into the container.
54+
MY_DIR=`dirname "$BASH_SOURCE"`
55+
TOOLS_DIR=`cd "$MY_DIR" && pwd`
56+
57+
# The Docker context here is the root directory of the outer repository.
58+
cd "$TOOLS_DIR/.."
59+
60+
for PLATFORM in `echo $PLATFORMS | tr ' ' '\n' | sort -u`
61+
do
62+
63+
# This Dockerfile is for the temporary image that is used to do the build
64+
# and unit tests. It is based on a pre-built test image stored on Docker
65+
# Hub, but will have the local repository contents copied into it before
66+
# the entrypoint script is run. This temporary image is discarded after
67+
# the build and unit tests are complete.
68+
DOCKERFILE="$TOOLS_DIR/docker/${PLATFORM}_tester/Dockerfile"
69+
TEMP_TAG=`git rev-parse --short=14 HEAD`-$PLATFORM-$$
70+
71+
docker build -t $TEMP_TAG --build-arg SNAPSHOT=$SNAPSHOT -f "$DOCKERFILE" .
72+
# Using tar to copy the build and test artifacts out of the container seems
73+
# more reliable than docker cp, and also means the files end up with the
74+
# correct uid/gid
75+
docker run --workdir=/ml-cpp $TEMP_TAG bash -c 'find . -name cppunit_results.xml | xargs tar cf - build/distributions' | tar xvf -
76+
docker rmi --force $TEMP_TAG
77+
78+
done
79+

0 commit comments

Comments
 (0)