Parallelizing Builds In Travis CI
A little background: over the last few months, I have been contributing in open source organization FOSSASIA, where I’m working on a project called BadgeYaY. It is a badge generator with a simple web UI to add data and generate printable badges in PDF.
Badgeyay project is now divided into two parts i.e front-end of Ember JS and back-end with REST-API programmed in Python. Now, one of the challenging job is that, it should support the uncoupled architecture. It should therefore run tests for the front-end and backend i.e, of two different languages on isolated instances by making use of the isolated parallel builds.
First let’s understand what is Parallel Travis CI build and why we need it. Then we will move onto configuring the travis.yml file to run tests parallely. Let’s get started and understand it step by step.
Why Parallel Travis CI Build?
The integration test suites tend to test more complex situations through the whole stack which incorporates front-end and back-end, they likewise have a tendency to be the slowest part, requiring various minutes to run, here and there even up to 30 minutes. To accelerate a test suite like that, we can split it up into a few sections utilizing Travis build matrix feature. Travis will decide the build matrix based on environment variables and schedule two builds to run.
Now our objective is clear that we have to configure travis.yml to build parallel-y. Our project requires two buildpacks, Python and node_js, running the build jobs for both them would speed up things by a considerable amount.It seems be possible now to run several languages in one .travis.yml file using the matrix:include feature.
dist: trusty# check different combinations of build flags which is able to divide builds into “jobs”.
matrix:# Helps to run different languages in one .travis.yml file
include:# First Job in Python language.
— language: python3apt:
— sudo apt-get -qq update
— sudo apt-get -y install python3-pip
— sudo apt-get install python-virtualenvinstall:
— virtualenv -p python3 ../flask_env
— source ../flask_env/bin/activate
— pip3 install -r backend/requirements/test.txt — cache-dirbefore_script:
— export DISPLAY=:99.0
— sh -e /etc/init.d/xvfb start
— sleep 3script:
— python backend/app/main.py >> log.txt 2>&1 &
— python backend/app/main.py > /dev/null &
— py.test — cov ../ ./backend/app/tests/test_api.pyafter_success:
— bash <(curl -s https://codecov.io/bash)# Second Job in node js language.
— language: node_js
# See https://git.io/vdao3 for details.
— cd frontend
— npm install
— npm install -g ember-cli
— npm i eslint-plugin-ember@latest — save-dev
— npm config set spin falsescript:
— npm run lint:js
— npm test
Now, as we have added travis.yml and pushed it to the project repository. Here is the screen-shot of passing Travis CI after parallel build jobs.
The related Pull Request of this work is https://github.com/fossasia/badgeyay/pull/512
With that, I have reached the end of our discussion on Parallelizing Builds In Travis CI. I wrote this post as a solution to this issue in BadgeYaY project. If you liked this post, consider having a look at my other work on GitHub 🙂.
Source: Travis CI documentation
PS: Constructive criticism is very much wanted. 🙂