From 79da382832e5146700fbda820e10d3412bdc63aa Mon Sep 17 00:00:00 2001 From: Nicolas Oliver Date: Tue, 23 May 2017 16:23:56 -0300 Subject: [PATCH] travis: migrate travis plans to run in a Docker container Add Dockerfile to create build environment for mraa Add docker-compose.yaml file to easily execute build tasks Add .dockerignore file Modify .travis.yaml file to use docker and docker-compose for building Modify package.json.cmake to run a simple load test for node.js Signed-off-by: Nicolas Oliver Signed-off-by: Brendan Le Foll --- .dockerignore | 2 + .travis.yml | 93 ++++++++++++++------------- Dockerfile | 100 ++++++++++++++++++++++++++++++ docker-compose.yaml | 83 +++++++++++++++++++++++++ src/javascript/package.json.cmake | 5 +- 5 files changed, 239 insertions(+), 44 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0274e0a --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +docker-compose.yaml diff --git a/.travis.yml b/.travis.yml index 1f26c21..9ae5bfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,49 +1,56 @@ -language: cpp sudo: required -dist: trusty -env: - - NODE4=true - - NODE5=true - - JSONPLAT=true NODE4=true - - JSONPLAT=true NODE5=true - - MOCK=true NODE4=true - - MOCK=true NODE5=true - - NPM=true NODE4=true - - NPM=true NODE5=true + +language: cpp + compiler: - clang - gcc -before_install: - # Via https://github.com/travis-ci/travis-ci/issues/5326 - - export PATH="$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g")" -install: - - if [ "${NODE4}" ]; then export CC=gcc-4.8 CXX=g++-4.8; fi + +env: + - TARGET=doc + - TARGET=python2 + - TARGET=python3 + - TARGET=java + - TARGET=node4 + - TARGET=node5 + - TARGET=python2 JSONPLAT=ON + - TARGET=python3 JSONPLAT=ON + - TARGET=java JSONPLAT=ON + - TARGET=node4 JSONPLAT=ON + - TARGET=node5 JSONPLAT=ON + - TARGET=python2 BUILDARCH=MOCK + - TARGET=python3 BUILDARCH=MOCK + - TARGET=java BUILDARCH=MOCK + - TARGET=node4 BUILDARCH=MOCK + - TARGET=node5 BUILDARCH=MOCK + +matrix: + exclude: + - compiler: clang + env: TARGET=java + - compiler: clang + env: TARGET=java JSONPLAT=ON + - compiler: clang + env: TARGET=java BUILDARCH=MOCK + allow_failures: + - compiler: gcc + env: TARGET=node4 JSONPLAT=ON + - compiler: clang + env: TARGET=node4 JSONPLAT=ON + - compiler: gcc + env: TARGET=node5 JSONPLAT=ON + - compiler: clang + env: TARGET=node5 JSONPLAT=ON + +services: + - docker + before_script: - # Turn off JAVA SWIG for clang++, use 4.8 for all g++ builds - - if [ "$CC" == "gcc" ]; then export BUILDJAVA=ON; export CC=gcc-4.8; export CXX=g++-4.8; else export BUILDJAVA=OFF; fi - - if [ "${JSONPLAT}" ]; then export JSONPLAT=ON; else export JSONPLAT=OFF; fi - - if [ "${MOCK}" ]; then export BUILDARCH="MOCK"; else export BUILDARCH=""; fi - - if [ "${NODE4}" ]; then nvm install 4.1; fi - - if [ "${NODE5}" ]; then nvm install 5; fi - - npm install node-gyp && export NODE_GYP="$TRAVIS_BUILD_DIR/node_modules/node-gyp/bin/node-gyp.js" - - wget http://iotdk.intel.com/misc/tr/swig-3.0.10.tar.gz && tar xf swig-3.0.10.tar.gz && cd swig-3.0.10 && ./configure --prefix=/home/travis/ && make && make install && cd .. + - if [ "$CC" == "gcc" ]; then export CC=gcc-4.8; fi + - if [ "$CXX" == "g++" ]; then export CXX=g++-4.8; fi + - if [ "$CC" == "clang" ]; then export CC=clang-3.8; fi + - if [ "$CXX" == "clang++" ]; then export CXX=clang++-3.8; fi + - docker-compose build ${TARGET} + script: - - echo "CC=$CC BUILDJAVA=$BUILDJAVA BUILDARCH=$BUILDARCH JSONPLAT=$JSONPLAT NODE4=$NODE4 NODE5=$NODE5 NODE_ROOT_DIR=$NODE_ROOT_DIR" - - if [ -z ${NPM} ]; then mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DBUILDARCH="$BUILDARCH" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make install && make test; else mkdir build && cd build && cmake -DBUILDSWIGJAVA="$BUILDJAVA" -DJSONPLAT=$JSONPLAT -DNODE_ROOT_DIR:PATH="${NVM_BIN}/.." -DCMAKE_INSTALL_PREFIX:PATH=../install -DSWIG_EXECUTABLE=/home/travis/bin/swig -DSWIG_DIR:PATH=/home/travis/share/swig/3.0.10/ .. && make npmpkg && cd .. && ${NODE_GYP} configure && ${NODE_GYP} build; fi - # simple test to see if we can load our node module - - if [ ${NPM} ]; then cd build/Release/obj.target/ && node -e "var m = require('./mraa.node'); m.getVersion()";fi -addons: - apt: - sources: - - ubuntu-toolchain-r-test - - kalakris-cmake - packages: - - g++-4.8 - - cmake - - python - - python-dev - - python3 - - python3-dev - - git - - libjson0 - - libjson0-dev + - docker-compose run ${TARGET} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..bea5cb3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,100 @@ +FROM ubuntu:16.04 + +ENV DEBIAN_FRONTEND noninteractive + +# Update apt-get +RUN apt-get -y update && \ + # Install apt-utils + apt-get -y --no-install-recommends install apt-utils && \ + # Main Build Dependencies + apt-get -y --no-install-recommends install git build-essential cmake clang-3.8 g++-4.8 wget libpcre3 libpcre3-dev \ + # Docs Build Dependencies + python-sphinx doxygen graphviz \ + # Python Build Dependencies + python python-dev python3 python3-dev \ + # Java Build Dependencies + default-jre default-jdk \ + # Json Platform Build Dependencies + pkg-config libjson0 libjson0-dev + +# Swig Build Dependencies +RUN wget http://iotdk.intel.com/misc/tr/swig-3.0.10.tar.gz && \ + tar xf swig-3.0.10.tar.gz && cd swig-3.0.10 && \ + ./configure --prefix=/usr/ && make && make install && cd .. + +# Node.js Build Dependencies +RUN wget -q -O - https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash + +# Set Workdir +WORKDIR /usr/src/app + +# Configure Build Arguments +ARG BUILDARCH +ARG BUILDDOC +ARG BUILDSWIG +ARG BUILDSWIGPYTHON +ARG BUILDSWIGNODE +ARG BUILDSWIGJAVA +ARG USBPLAT=OFF +ARG FIRMATA=OFF +ARG ONEWIRE=OFF +ARG JSONPLAT +ARG IMRAA=OFF +ARG FTDI4222=OFF +ARG IPK=OFF +ARG RPM=OFF +ARG ENABLEEXAMPLES +ARG INSTALLGPIOTOOL=OFF +ARG INSTALLTOOLS=OFF +ARG BUILDTESTS +ARG CC +ARG CXX +ARG NODE_VERSION + +# Configure Build Environment +ENV NVM_DIR /root/.nvm +ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/ +ENV CC $CC +ENV CXX $CXX +RUN . $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use $NODE_VERSION && \ + npm install -g node-gyp && node-gyp install + +# Copy sources +COPY . . + +# Update Submodule +RUN git submodule update --init --recursive + +# Fix line ending issue in src/doxy2swig.py and do it executable +RUN tr -d "\r" < src/doxy2swig.py > src/_doxy2swig.py && \ + mv src/_doxy2swig.py src/doxy2swig.py && \ + chmod u+x src/doxy2swig.py + +# Change Workdir to build directory +WORKDIR /usr/src/app/build + +# Run cmake +RUN . $NVM_DIR/nvm.sh && cmake \ + -DSWIG_EXECUTABLE=/usr/bin/swig \ + -DSWIG_DIR:PATH=/usr/share/swig/3.0.10/ \ + -DBUILDARCH=$BUILDARCH \ + -DBUILDDOC=$BUILDDOC \ + -DBUILDSWIG=$BUILDSWIG \ + -DBUILDSWIGPYTHON=$BUILDSWIGPYTHON \ + -DBUILDSWIGNODE=$BUILDSWIGNODE \ + -DBUILDSWIGJAVA=$BUILDSWIGJAVA \ + -DUSBPLAT=$USBPLAT \ + -DFIRMATA=$FIRMATA \ + -DONEWIRE=$ONEWIRE \ + -DJSONPLAT=$JSONPLAT \ + -DIMRAA=$IMRAA \ + -DFTDI4222=$FTDI4222 \ + -DIPK=$IPK \ + -DRPM=$RPM \ + -DENABLEEXAMPLES=$ENABLEEXAMPLES \ + -DINSTALLGPIOTOOL=$INSTALLGPIOTOOL \ + -DINSTALLTOOLS=$INSTALLTOOLS \ + -DBUILDTESTS=$BUILDTESTS \ + .. + +CMD make diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..0775370 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,83 @@ +version: '2' + +services: + + main: + build: + context: . + dockerfile: Dockerfile + args: + - http_proxy + - https_proxy + - no_proxy + - BUILDDOC=OFF + - BUILDSWIG=OFF + - BUILDSWIGPYTHON=OFF + - BUILDSWIGJAVA=OFF + - BUILDSWIGNODE=OFF + - USBPLAT=OFF + - FIRMATA=OFF + - ONEWIRE=OFF + - JSONPLAT + - IMRAA=OFF + - FTDI4222=OFF + - IPK=OFF + - RPM=OFF + - ENABLEEXAMPLES=ON + - INSTALLGPIOTOOL=OFF + - INSTALLTOOLS=OFF + - BUILDTESTS=ON + - CC=clang-3.8 + - CXX=clang++-3.8 + - NODE_VERSION=v4.4.7 + - BUILDARCH + environment: + - http_proxy + - https_proxy + - no_proxy + + doc: + extends: main + build: + args: + - BUILDDOC=ON + command: bash -c "make doc" + volumes: + - ./build/html:/usr/src/app/build/html + + python2: + extends: main + build: + args: + - BUILDSWIG=ON + - BUILDSWIGPYTHON=ON + command: bash -c "make _python2-mraa && ctest --output-on-failure" + + python3: + extends: python2 + command: bash -c "make _python3-mraa && ctest --output-on-failure" + + java: + extends: main + build: + args: + - BUILDSWIG=ON + - BUILDSWIGJAVA=ON + - CC=gcc-4.8 + - CXX=g++-4.8 + command: bash -c "make mraajava && ctest --output-on-failure" + + node4: + extends: main + build: + args: + - BUILDSWIG=ON + - BUILDSWIGNODE=ON + - NODE_VERSION=v4.4.7 + command: bash -c "source /root/.nvm/nvm.sh && make npmpkg && cd .. && node-gyp configure && node-gyp build && npm test" + + node5: + extends: node4 + build: + args: + - NODE_VERSION=v5.12.0 diff --git a/src/javascript/package.json.cmake b/src/javascript/package.json.cmake index 8dee7a7..dd65a3d 100644 --- a/src/javascript/package.json.cmake +++ b/src/javascript/package.json.cmake @@ -12,5 +12,8 @@ }, "license": "MIT", "version": "@VERSION@", - "authors": "See github.com/intel-iot-devkit/mraa/graphs/contributors" + "authors": "See github.com/intel-iot-devkit/mraa/graphs/contributors", + "scripts": { + "test": "node -p -e 'require(\".\").getVersion()'" + } }