Skip to content

Commit fa19f43

Browse files
authored
[ML-5672] simplify docker/travis setup
Similar to databricks/spark-deep-learning@846bfc0 we use docker/docker-compose to describe the test env and hence simplify the content in .travis.yml. A major difference between this PR and databricks/spark-deep-learning@846bfc0 is that we use conda to activate the env instead of updating env variables directly. This provides better compatibility. But we need to use interactive shell to load the profile (bash -i). We also mount "~/.ivy2" to avoid unnecessary download in sbt build.
1 parent e46c088 commit fa19f43

File tree

4 files changed

+94
-80
lines changed

4 files changed

+94
-80
lines changed

.travis.yml

Lines changed: 18 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,35 @@
1-
dist: trusty
2-
3-
language: java
1+
sudo: required
42

5-
jdk: oraclejdk8
3+
dist: trusty
64

7-
sudo: required
5+
language: minimal
86

97
services:
108
- docker
119

1210
cache:
1311
directories:
1412
- $HOME/.ivy2/
15-
- $HOME/.sbt/launchers/
16-
- $HOME/.cache/spark-versions/
17-
- $HOME/.sbt/boot/scala-2.11.8/
1813

1914
env:
15+
global:
16+
- DOCKER_COMPOSE_VERSION=1.22.0
2017
matrix:
21-
- SCALA_BINARY_VERSION=2.11.8 SPARK_VERSION=2.4.0 SPARK_BUILD="spark-2.4.0-bin-hadoop2.7"
22-
SPARK_BUILD_URL="https://dist.apache.org/repos/dist/release/spark/spark-2.4.0/spark-2.4.0-bin-hadoop2.7.tgz"
23-
PYTHON_VERSION=2.7.13
24-
- SCALA_BINARY_VERSION=2.11.8 SPARK_VERSION=2.4.0 SPARK_BUILD="spark-2.4.0-bin-hadoop2.7"
25-
SPARK_BUILD_URL="https://dist.apache.org/repos/dist/release/spark/spark-2.4.0/spark-2.4.0-bin-hadoop2.7.tgz"
26-
PYTHON_VERSION=3.6.2
18+
- PYTHON_VERSION=3.6
19+
- PYTHON_VERSION=2.7
2720

2821
before_install:
29-
- ./bin/download_travis_dependencies.sh
30-
- if [[ "$PYTHON_VERSION" == 2.* ]]; then
31-
export CONDA_URL="repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh"
32-
export PYSPARK_PYTHON=python2;
33-
else
34-
export CONDA_URL="repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh";
35-
export PYSPARK_PYTHON=python3;
36-
fi
37-
- docker run -e "JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64"
38-
-e SPARK_VERSION
39-
-e SPARK_BUILD
40-
-e SCALA_BINARY_VERSION
41-
-e PYTHON_VERSION
42-
-e PYSPARK_PYTHON
43-
-e CONDA_URL
44-
-d --name ubuntu-test -v $HOME ubuntu:16.04 tail -f /dev/null
45-
- docker cp `pwd` ubuntu-test:$HOME/
46-
- docker cp $HOME/.cache ubuntu-test:$HOME/
47-
- docker ps
48-
49-
# See this page: http://conda.pydata.org/docs/travis.html
50-
install:
51-
# install needed ubuntu packages
52-
- docker exec -t ubuntu-test bash -c "apt-get update && apt-get upgrade -y"
53-
- docker exec -t ubuntu-test bash -c "apt-get install -y curl bzip2 openjdk-8-jdk unzip"
54-
# download and set up protoc
55-
- docker exec -t ubuntu-test bash -c "
56-
curl -OL https://github.com/google/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip;
57-
unzip protoc-3.6.1-linux-x86_64.zip -d /usr/local;"
58-
# download and set up miniconda
59-
- docker exec -t ubuntu-test bash -c "
60-
curl https://$CONDA_URL >> $HOME/miniconda.sh;
61-
bash $HOME/miniconda.sh -b -p $HOME/miniconda;
62-
bash $HOME/miniconda.sh -b -p $HOME/miniconda;
63-
$HOME/miniconda/bin/conda config --set always_yes yes --set changeps1 no;
64-
$HOME/miniconda/bin/conda update -q conda;
65-
$HOME/miniconda/bin/conda info -a;
66-
$HOME/miniconda/bin/conda create -q -n test-environment python=$PYTHON_VERSION"
22+
# update docker compose to the specified version, https://docs.travis-ci.com/user/docker/#using-docker-compose
23+
- sudo rm /usr/local/bin/docker-compose
24+
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
25+
- chmod +x docker-compose
26+
- sudo mv docker-compose /usr/local/bin
6727

68-
# Activate conda environment ad install required packages
69-
- docker exec -t ubuntu-test bash -c "
70-
source $HOME/miniconda/bin/activate test-environment;
71-
python --version;
72-
pip --version;
73-
pip install --user -r $HOME/tensorframes/python/requirements.txt;"
28+
install :
29+
- docker-compose build --build-arg PYTHON_VERSION=$PYTHON_VERSION
30+
- docker-compose up -d
31+
- docker-compose exec master bash -i -c "build/sbt tfs_testing/assembly"
7432

7533
script:
76-
# Run the scala unit tests first
77-
- docker exec -t ubuntu-test bash -c "
78-
source $HOME/miniconda/bin/activate test-environment;
79-
cd $HOME/tensorframes;
80-
./build/sbt -Dspark.version=$SPARK_VERSION
81-
-Dpython.version=$PYSPARK_PYTHON
82-
-Dscala.version=$SCALA_BINARY_VERSION
83-
tfs_testing/test"
84-
85-
# Build the assembly
86-
- docker exec -t ubuntu-test bash -c "
87-
source $HOME/miniconda/bin/activate test-environment;
88-
cd $HOME/tensorframes;
89-
./build/sbt -Dspark.version=$SPARK_VERSION
90-
-Dscala.version=$SCALA_BINARY_VERSION
91-
tfs_testing/assembly"
92-
93-
# Run python tests
94-
- docker exec -t ubuntu-test bash -c "
95-
source $HOME/miniconda/bin/activate test-environment;
96-
cd $HOME/tensorframes;
97-
SPARK_HOME=$HOME/.cache/spark-versions/$SPARK_BUILD ./python/run-tests.sh"
34+
- docker-compose exec master bash -i -c "build/sbt tfs_testing/test"
35+
- docker-compose exec master bash -i -c "python/run-tests.sh"

Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Use docker-compose to build and run this container.
2+
# $ docker-compose build [--build-arg PYTHON_VERSION=2.7]
3+
# $ docker-compose up -d
4+
# $ docker-compose exec master bash -i -c "..."
5+
# $ docker-compose down
6+
7+
FROM ubuntu:16.04
8+
9+
ARG PYTHON_VERSION=3.6
10+
11+
RUN apt-get update && \
12+
apt-get install -y wget bzip2 openjdk-8-jdk unzip && \
13+
apt-get clean
14+
15+
# Install protoc.
16+
RUN wget --quiet https://github.com/google/protobuf/releases/download/v3.6.1/protoc-3.6.1-linux-x86_64.zip -O /tmp/protoc.zip && \
17+
unzip /tmp/protoc.zip -d /usr/local && \
18+
rm /tmp/protoc.zip
19+
20+
# Install Miniconda.
21+
# Reference: https://hub.docker.com/r/continuumio/miniconda/~/dockerfile/
22+
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh -O ~/miniconda.sh && \
23+
/bin/bash ~/miniconda.sh -b -p /opt/conda && \
24+
rm ~/miniconda.sh && \
25+
ln -s /opt/conda/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
26+
echo ". /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc
27+
28+
# Create tensorframes conda env.
29+
ENV PYTHON_VERSION $PYTHON_VERSION
30+
COPY ./environment.yml /tmp/environment.yml
31+
RUN /opt/conda/bin/conda create -n tensorframes python=$PYTHON_VERSION && \
32+
/opt/conda/bin/conda env update -n tensorframes -f /tmp/environment.yml && \
33+
echo "conda activate tensorframes" >> ~/.bashrc
34+
35+
# Install Spark and update env variables.
36+
ENV SCALA_BINARY_VERSION 2.11.8
37+
ENV SPARK_VERSION 2.4.0
38+
ENV SPARK_BUILD "spark-${SPARK_VERSION}-bin-hadoop2.7"
39+
ENV SPARK_BUILD_URL "https://dist.apache.org/repos/dist/release/spark/spark-2.4.0/${SPARK_BUILD}.tgz"
40+
RUN wget --quiet $SPARK_BUILD_URL -O /tmp/spark.tgz && \
41+
tar -C /opt -xf /tmp/spark.tgz && \
42+
mv /opt/$SPARK_BUILD /opt/spark && \
43+
rm /tmp/spark.tgz
44+
ENV SPARK_HOME /opt/spark
45+
ENV PATH $SPARK_HOME/bin:$PATH
46+
ENV PYTHONPATH /opt/spark/python/lib/py4j-0.10.7-src.zip:/opt/spark/python/lib/pyspark.zip:$PYTHONPATH
47+
ENV PYSPARK_PYTHON python
48+
49+
# The tensorframes dir will be mounted here.
50+
VOLUME /mnt/tensorframes
51+
WORKDIR /mnt/tensorframes
52+
53+
CMD /bin/bash

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: '3'
2+
services:
3+
master:
4+
build: .
5+
hostname: master
6+
entrypoint: tail -f /dev/null
7+
ports:
8+
- "4040:4040" # driver UI
9+
volumes:
10+
- .:/mnt/tensorframes
11+
- ~/.ivy2:/root/.ivy2

environment.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# To choose a Python version, first create the env with:
2+
# conda create -n tensorframes python=3.6
3+
# and then update it
4+
name: tensorframes
5+
channels:
6+
- https://repo.anaconda.com/pkgs/main/linux-64/
7+
dependencies:
8+
- pandas=0.23.4
9+
- nomkl
10+
- tensorflow=1.12.0
11+
# test
12+
- nose=1.3.7

0 commit comments

Comments
 (0)