SlideShare a Scribd company logo
images/logo
Developing, maintaining, and sharing software tools for research
Continuous integration
Danilo Pianini
danilo.pianini@unibo.it
Alma Mater Studiorum—Universit`a di Bologna
Ph.D. course in Data Science and Computation
June 7, 2018 - Bologna (Italy)
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 1 / 40
images/logo
Outline
1 Introduction
2 Travis CI
3 Configuration
Basics
Security
Deployment
Complete builds
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 2 / 40
images/logo
Introduction
Why continuous? I
Avoid the integration hell
Work in parallel
Don’t waste developers’ time with repetitive tasks
Don’t break stuff
Time is money
Software development used to take several months for “integrating” a
couple of years of development [Fow]
Historically introduced by the extreme programming (XP) community
Today used by companies that do not adopt XP
IMVU [teab] delivers its software up to 50 times per day
Google and Mozilla release at least once a day
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 3 / 40
images/logo
Introduction
Why continuous? II
Higher frequency, lower risk [Fab]
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 4 / 40
images/logo
Introduction
Improve over classic development I
Protoduction [teaa]
When prototype code ends up in production
Classically used with a negative meaning
It’s time to rehabilitate it
Make it easy to access and use the latest prototype
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 5 / 40
images/logo
Introduction
Improve over classic development II
It’s compiling [Mun]
Make the building process fast!
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 6 / 40
images/logo
Introduction
Continuous Integration software
Software that promotes the practice of continuous integration
Runs a build for every change in the project
Prepares fresh environments where the builds are hosted
Notifies the results, e.g. if a failure occurs
Provides tools for deploying the produced artifacts
Hosted CI with free plans for open source projects are blossoming:
Circle CI
Codefresh
Codeship
drone.io
Pipelines
Travis CI
Wercker
...
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 7 / 40
images/logo
Travis CI
Travis CI
Web based
Well integrated with GitHub
Build results are displayed in the repo without intervention
Automatic build of any pull request
Free for open source projects
Cronjobs
Build instances based on Docker
Project-local configuration via YAML (in the .travis.yml file)
Out of the box support for Gradle
Dozens of deployment targets
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 8 / 40
images/logo
Travis CI
How it works
A web-hook can be registered to your GitHub repository that triggers
Travis CI at each new commit
Travis CI starts a pristine appropriate environment
Can be a container or a full virtual machine, depending on whether
sudo is required [CI]
The project gets cloned
The configured commands are executed
The configured deployments are performed
If necessary, project managers are informed of the build status
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 9 / 40
images/logo
Configuration Basics
Outline
1 Introduction
2 Travis CI
3 Configuration
Basics
Security
Deployment
Complete builds
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 10 / 40
images/logo
Configuration Basics
.travis.yml
Travis uses a project-local configuration
A .travis.yml file must be in your repository root
of course, it must be tracked in git
It is a YAML file, very human-readable and easy to learn 1
Also it is a superset of JSON, so any valid JSON is a valid YAML
Supports basically any language that can get built on Linux or
MacOS
No support for Windows builds
Support for build matrix
When your project can get built using different versions of different
tools, you may want to test all of them
It’s a cartesian product of configurations
Commit once, build on every supported environment
1
https://learnxinyminutes.com/docs/yaml/
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 10 / 40
images/logo
Configuration Basics
.travis.yml: the language section
Travis provides a number of default environments for the most
common languages
They differ by software installed by default
e.g. the C# compiler is not included if you run a Python build)
They behave differently
e.g. if Java is specified as language, the system automatically searches
for a build.gradle, a pom.xml (Maven), or an Ant build script
The first configuration required is a specification on which
environment to work in
Defaults to Ruby
For very simple projects, this might be enough of configuration
Example
language: python
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 11 / 40
images/logo
Configuration Basics
.travis.yml: custom behavior using the script section
The default configuration may be not suitable for you
Either because you want to customize it
Or because you are using something that is not in the spectrum of
supported features
Bash commands can be configured to be executed in place of the
default behavior
Example
language: java
script:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash build.sh; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash build_pull_req.sh; fi'
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 12 / 40
images/logo
Configuration Basics
.travis.yml: distribution selection in the dist section
By default, Travis CI builds in a Ubuntu Linux environment
Ubuntu LTS is generally used
The version of Ubuntu can be selected in a dist section
At the time of writing, trusty and precise are available
Mac OS X can be used by specifying os: osx in place of dist
Example
language: python
dist: trusty
script:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash build.sh; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash build_pull_req.sh; fi'
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 13 / 40
images/logo
Configuration Basics
.travis.yml: enabling super user access
By default, Travis CI builds in a docker container
It’s way faster than a VM, especially in terms of start up time
Docker does not allow for super-user access though
Sometimes it is required
e.g. for customizing the OS by installing packages
In such case, sudo: required switches the build to a full fledged
VM with super user access
Example
language: python
dist: trusty
sudo: required
script:
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash build.sh; fi'
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash build_pull_req.sh; fi'
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 14 / 40
images/logo
Configuration Basics
The build lifecycle in Travis
1 Install — Install any dependency required
1 apt addons — Optional
2 cache components — Optional
3 before install — Install additional dependencies in form of Ubuntu
packages using apt
4 install
2 Script — Run the build script
1 before script — Preparation for the build
2 script — Actual build
3 before cache — Optional
4 after success or after failure — Execute additional scripts
depending on the outcome of the build
5 before deploy — Optional, used to prepare resources to be uploaded
6 deploy — Optional, used to actually deploy the produced artifacts
7 after deploy — Optional, additional operations to be executed after
deployment
8 after script
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 15 / 40
images/logo
Configuration Basics
.travis.yml: Example with several phases
Example
language: java
dist: trusty
sudo: required
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y graphviz
before_install: echo Begin actual build
script:
- ./gradlew clean build
- ./gradlew buildDashboard
after_success: echo Build successful
after failure: sudo mail -s "Build failure" admin@company.org < /dev/null
before_deploy: echo Preparing for deploy
after_deploy: echo Deployment phase concluded.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 16 / 40
images/logo
Configuration Basics
Build variables I
Travis offers a number of environment variables that allow for fine tuning
the build process.
CI, TRAVIS, CONTINUOUS INTEGRATION, and
HAS JOSH K SEAL OF APPROVALa
a
Josh K. is a co-founder of Travis CI: https://twitter.com/j2h
Always set to true. Used for detecting if the build is running on the
Continuous integration environment
DEBIAN FRONTEND
Always set to noninteractive. Some scripts use it to determine whether
or not ask for user input.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 17 / 40
images/logo
Configuration Basics
Build variables II
USER
Always set to travis. Do not depend on this value; do not override this
value.
HOME
Always set to /home/travis. Do not depend on this value; do not
override this value.
LANG and LC ALL
Always set to en US.UTF-8.
RAILS ENV, RACK ENV, MERB ENV
Always set to test
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 18 / 40
images/logo
Configuration Basics
Build variables III
JRUBY OPTS
Always set to "--server -Dcext.enabled=false
-Xcompile.invokedynamic=false"
JAVA HOME
Set to the appropriate value, depends on the selected JDK
TRAVIS ALLOW FAILURE
Set to true if the job is allowed to fail. Set to false if the job is not
allowed to fail.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 19 / 40
images/logo
Configuration Basics
Build variables IV
TRAVIS BRANCH
For push builds, or builds not triggered by a pull request, this is the name
of the branch. For builds triggered by a pull request this is the name of the
branch targeted by the pull request. For builds triggered by a tag, this is
the same as the name of the tag (TRAVIS TAG). Note that for tags, git
does not store the branch from which a commit was tagged.
TRAVIS BUILD DIR
The absolute path to the directory where the repository being built has
been copied on the worker.
TRAVIS BUILD ID
The id of the current build that Travis CI uses internally.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 20 / 40
images/logo
Configuration Basics
Build variables V
TRAVIS BUILD NUMBER
The number of the current build (for example, 4).
TRAVIS COMMIT
The commit that the current build is testing.
TRAVIS COMMIT MESSAGE
The commit subject and body, unwrapped.
TRAVIS COMMIT RANGE
The range of commits that were included in the push or pull request. Note
that this is empty for builds triggered by the initial commit of a new
branch.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 21 / 40
images/logo
Configuration Basics
Build variables VI
TRAVIS EVENT TYPE
Indicates how the build was triggered. One of push, pull request, api,
cron.
TRAVIS JOB ID
The id of the current job that Travis CI uses internally.
TRAVIS JOB NUMBER
The number of the current job (for example, 4.1).
TRAVIS OS NAME
On multi-OS builds, this value indicates the platform the job is running
on. Values are linux and osx currently, to be extended in the future.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 22 / 40
images/logo
Configuration Basics
Build variables VII
TRAVIS OSX IMAGE
The osx image value configured in .travis.yml. If this is not set in
.travis.yml, it is empty.
TRAVIS PULL REQUEST
The pull request number if the current job is a pull request, false if it’s
not a pull request.
TRAVIS PULL REQUEST BRANCH
If the current job is a pull request, the name of the branch from which the
PR originated. If the current job is a push build, this variable is empty.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 23 / 40
images/logo
Configuration Basics
Build variables VIII
TRAVIS PULL REQUEST SHA
If the current job is a pull request, the commit SHA of the HEAD commit
of the PR. If the current job is a push build, this variable is empty.
TRAVIS PULL REQUEST SLUG
If the current job is a pull request, the slug (in the form
owner name/repo name) of the repository from which the PR originated.
If the current job is a push build, this variable is empty.
TRAVIS REPO SLUG
The slug (in form: owner name/repo name) of the repository currently
being built.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 24 / 40
images/logo
Configuration Basics
Build variables IX
TRAVIS SECURE ENV VARS
Set to true if there are any encrypted environment variables. Set to
false if no encrypted environment variables are available.
TRAVIS SUDO
true or false based on whether sudo is enabled.
TRAVIS TEST RESULT
0 if all commands in the script section (up to the point this environment
variable is referenced) have exited with zero; 1 otherwise.
TRAVIS TAG
If the current build is for a git tag, this variable is set to the tag’s name.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 25 / 40
images/logo
Configuration Basics
Build variables X
TRAVIS BUILD STAGE NAME
The build stage in capitalzed form, e.g. Test or Deploy. If a build does
not use build stages, this variable is empty.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 26 / 40
images/logo
Configuration Security
Outline
1 Introduction
2 Travis CI
3 Configuration
Basics
Security
Deployment
Complete builds
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 27 / 40
images/logo
Configuration Security
Sensible data in builds
It could be useful to access private data from within a build
Downloading a password-protected file
Decrypt a password-encrypted file
Open a keystore for signing a file
Store an API key for a service used e.g. for testing
Store a OAuth token for accessing a remote service
These data cannot be tracked on the repository (with the exception of
encrypted files, but the problem is simply moved to passing the decrypt
password to the build system).
These data must be provided in form of enviroment variables
Travis allows for inserting secure variables in the web interface
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 27 / 40
images/logo
Configuration Security
Pull request attack
Usually, you want the integrator to build pull requests
You want to test the integration before committing it
What if the pull request changes the .travis.yml, printing all the
environment variables?
The developer of an open source project is defenseless
Travis CI does not allow access to secure variables when a pull request is
executed
As such, typically, the Travis build must be configured to detect
whether a pull request is being bult, and in case don’t perform tasks
that depend on secure variables
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 28 / 40
images/logo
Configuration Security
Local Travis installation
Travis CI provides an installable module to help with several tasks
otherwise tedious:
Secure encryption of files
You may need your private key for automatic signing, but you want it
to be secret and only readable by builds you create
Secure encryption of global variables
You may need your password or username or other sensible data to
complete the deployment process, but you want it encrypted
In case of OAuth tokens, you also don’t want to waste time dealing
with it manually.
Install Travis CI locally:
1 Install RubyGems
On Arch Linux: pacman -Syu rubygems ruby-rdoc
2 Issue: gem install travis
3 Make sure your PATH includes the path where gems are installed
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 29 / 40
images/logo
Configuration Security
Creating a secure variable
From the web interface:
Go to the settings page
Insert name and value
Select if it should be displayed on the build
Disable if the variable is meant to be secure
Use the environment variable in your build
From the local Travis CI application:
travis encrypt MY SECRET ENV=super secret
The secured variable will be printed on terminal
copy the secure="..." inside your .travis.yml
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 30 / 40
images/logo
Configuration Security
Ecrypting a file
From the local Travis CI application:
travis encrypt-file my-super-secret-file
A new my-super-secret-file.enc file will be created
It must be added to track
The originating file must not be in track, and must never have been
(or it could be recovered): delete it immediately
copy the secure="..." inside your .travis.yml
Add the generated openssl command that appears on the terminal
to the correct phase of your build
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 31 / 40
images/logo
Configuration Security
Don’t screw up: non-exhaustive list of advices
DO generate passwords, never use words related to the repository or
project name
DON’T use settings which duplicate commands to standard output,
such as set -x or set -v in your bash scripts
DON’T run env or printenv
DON’T echo "$SECRET_KEY"
DON’T use tools that print secrets on error output, such as php -i
DOUBLE CHECK before using git fetch or git push, as they might
expose tokens or other secure variables
DUOBLE CHECK for mistakes in string escaping
DUOBLE CHECK before using settings that increase verbosity
PREFER redirecting output to /dev/null when possible
e.g. git push url-with-secret >/dev/null 2>&1
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 32 / 40
images/logo
Configuration Deployment
Outline
1 Introduction
2 Travis CI
3 Configuration
Basics
Security
Deployment
Complete builds
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 33 / 40
images/logo
Configuration Deployment
GitHub Releases
Travis CI can automate deployment of artifacts on GitHub releases
Example .travis.yml configuration
deploy:
provider: releases
api_key:
secure: YOUR_API_KEY_ENCRYPTED
file: "FILE TO UPLOAD"
skip_cleanup: true
on:
tags: true
The authentication token for GitHub can be generated locally with:
travis setup releases
Remember to backup your travis file before running the command
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 33 / 40
images/logo
Configuration Deployment
surge.sh
A free host for static websites (HTML + Javascript)
Install surge locally
Create an account (with email and password)
Create a new secret variable SURGE LOGIN
Create a new secret variable SURGE TOKEN
Obtain the value by using surge token
Example .travis.yml configuration
deploy:
provider: surge
project: ./build/docs/javadoc/
domain: myjavadoc.surge.sh
skip_cleanup: true
on:
all_branches: true
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 34 / 40
images/logo
Configuration Deployment
Deploy to PyPI
The best place where to put your Python software modules!
Sign up to PyPI
Example .travis.yml configuration
deploy:
provider: pypi
user: "Your (possibly encrypted) username"
password:
secure: "Your encrypted password"
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 35 / 40
images/logo
Configuration Deployment
Other targets
anynines – Appfog – Atlas – AWS CodeDeploy – AWS Elastic Beanstalk –
AWS Lambda – AWS OpsWorks – AWS S3 – Azure Web Apps – bintray –
BitBalloon – Bluemix CloudFoundry – Boxfuse – Catalyze – Chef
Supermarket – Cloud 66 – CloudFoundry – Deis – Engine Yard – GitHub
Pages – Google App Engine – Google Cloud Storage – Google Firebase –
Hackage – Heroku – Launchpad – Modulus – npm – OpenShift –
packagecloud.io – Puppet – Forge – PyPI – Rackspace Cloud Files –
RubyGems – Scalingo – Script – TestFairy – Ubuntu Snap Store –
Uploading Build Artifacts
Plus any target your build system can directly deal with (e.g. Maven
Central)
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 36 / 40
images/logo
Configuration Complete builds
Outline
1 Introduction
2 Travis CI
3 Configuration
Basics
Security
Deployment
Complete builds
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 37 / 40
images/logo
Configuration Complete builds
Example with Python
The default Python environment uses isolated virtualenvs
PyPy is supported out of the box
The script entry is mandatory
dependencies can be listed in a requirements.txt file
Travis automatically runs
pip install -r requirements.txt
during the install phase of the build
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 37 / 40
images/logo
Configuration Complete builds
Java examples
Examples of rich, multi-project, multi-language, multi-target deployments
are available at:
https://github.com/AlchemistSimulator/Alchemist
https://github.com/Protelis/Protelis
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 38 / 40
images/logo
References
References I
Travis CI.
The build environment.
https://docs.travis-ci.com/user/ci-environment/.
Accessed: 2017-05-08.
Darko Fabijan.
Why we need continuous integration.
https://semaphoreci.com/community/tutorials/continuous-integration.
Accessed: 2017-05-03.
Martin Fowler.
Continuous integration.
https://www.martinfowler.com/articles/continuousIntegration.html.
Accessed: 2017-05-02.
Randall Munroe.
xkcd: Compiling.
https://xkcd.com/303/.
Accessed: 2017-05-03.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 39 / 40
images/logo
References
References II
The CodingHorror team.
New programming jargon.
https://blog.codinghorror.com/new-programming-jargon/.
Accessed: 2017-05-02.
The IMVU team.
Imvu: 3d avatar free chat, make new friends, dress up, shop.
https://www.imvu.com/.
Accessed: 2017-05-02.
D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 40 / 40

More Related Content

PDF
Software development made serious
KEY
Tycho - Building plug-ins with Maven
PDF
Maven 3 / Tycho
PPTX
Tycho Tutorial (EclipseCon 2012)
PPTX
Tycho Tutorial EclipseCon 2013
PPTX
Discovery the p2 API (updated to Indigo)
PDF
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
PDF
Symfony Day 2009 - Symfony vs Integrating products
Software development made serious
Tycho - Building plug-ins with Maven
Maven 3 / Tycho
Tycho Tutorial (EclipseCon 2012)
Tycho Tutorial EclipseCon 2013
Discovery the p2 API (updated to Indigo)
Android on Windows 11 - A Developer's Perspective (Windows Subsystem For Andr...
Symfony Day 2009 - Symfony vs Integrating products

Similar to Continuous Integration (20)

PDF
Enforce reproducibility: dependency management and build automation
PDF
Continuous integration - CI
PPTX
Apigee deploy grunt plugin.1.0
PPTX
Custom Buildpacks and Data Services
PDF
Run Your Java Code on Cloud Foundry - Andy Piper (Pivotal)
PDF
Run your Java apps on Cloud Foundry
PPTX
Hudson@java one2010
PDF
8 Principles for Enabling Build/Measure/Learn: Lean Engineering in Action
PPT
Flash Camp Chennai - Build automation of Flex and AIR applications
PPTX
FISL 2010: CruiseControl: the open source that changed the way we develop sof...
PPT
What's new in p2 (2009)?
PPTX
2017 03 25 Microsoft Hacks, How to code efficiently
PDF
Flutter vs Java Graphical User Interface Frameworks - text
PDF
Continuous Delivery for Python Developers – PyCon Otto
PPTX
Agile Network India | Continuous Integration & Continuous Deployment & Automa...
PDF
silver gemstone sun pendant silver pendant gemstones
ODP
Jbossworld Presentation
PPTX
Industrialization of Android Development (Concept)
PDF
Container Security Scanning by Timo Pagel
PDF
Container Security Scanning by Timo Pagel
Enforce reproducibility: dependency management and build automation
Continuous integration - CI
Apigee deploy grunt plugin.1.0
Custom Buildpacks and Data Services
Run Your Java Code on Cloud Foundry - Andy Piper (Pivotal)
Run your Java apps on Cloud Foundry
Hudson@java one2010
8 Principles for Enabling Build/Measure/Learn: Lean Engineering in Action
Flash Camp Chennai - Build automation of Flex and AIR applications
FISL 2010: CruiseControl: the open source that changed the way we develop sof...
What's new in p2 (2009)?
2017 03 25 Microsoft Hacks, How to code efficiently
Flutter vs Java Graphical User Interface Frameworks - text
Continuous Delivery for Python Developers – PyCon Otto
Agile Network India | Continuous Integration & Continuous Deployment & Automa...
silver gemstone sun pendant silver pendant gemstones
Jbossworld Presentation
Industrialization of Android Development (Concept)
Container Security Scanning by Timo Pagel
Container Security Scanning by Timo Pagel
Ad

More from Danilo Pianini (20)

PDF
Towards adaptive trajectories for mixed autonomous and human-operated ships
PDF
Time fluid field-based Coordination
PDF
Engineering the Aggregate - Talk at Software Engineering for Intelligent and ...
PDF
Versioning and License selection
PDF
Productive parallel teamwork: Decentralized Version Control Systems
PDF
Computational Fields meet Augmented Reality: Perspectives and Challenges
PDF
Practical Aggregate Programming with Protelis @ SASO2017
PDF
Towards a Foundational API for Resilient Distributed Systems Design
PDF
Continuous integration and delivery
PDF
Democratic process and electronic platforms: concerns of an engineer
PDF
Simulating Large-scale Aggregate MASs with Alchemist and Scala
PDF
Extending the Gillespie's Stochastic Simulation Algorithm for Integrating Dis...
PDF
Protelis: Practical Aggregate Programming - Symposium on Applied Computing (S...
PDF
Engineering Complex Computational Ecosystems (PhD defense)
PDF
SAPERE Analysis tools
PDF
Engineering computational ecosystems (2nd year PhD seminar)
PDF
From Engineer to Alchemist, There and Back Again: An Alchemist Tale
PDF
SAPERE WP1 Alchemist status at 02/2013
PDF
Engineering Computational Ecosystems
PDF
Recipes for Sabayon: cook your own Linux distro within two hours
Towards adaptive trajectories for mixed autonomous and human-operated ships
Time fluid field-based Coordination
Engineering the Aggregate - Talk at Software Engineering for Intelligent and ...
Versioning and License selection
Productive parallel teamwork: Decentralized Version Control Systems
Computational Fields meet Augmented Reality: Perspectives and Challenges
Practical Aggregate Programming with Protelis @ SASO2017
Towards a Foundational API for Resilient Distributed Systems Design
Continuous integration and delivery
Democratic process and electronic platforms: concerns of an engineer
Simulating Large-scale Aggregate MASs with Alchemist and Scala
Extending the Gillespie's Stochastic Simulation Algorithm for Integrating Dis...
Protelis: Practical Aggregate Programming - Symposium on Applied Computing (S...
Engineering Complex Computational Ecosystems (PhD defense)
SAPERE Analysis tools
Engineering computational ecosystems (2nd year PhD seminar)
From Engineer to Alchemist, There and Back Again: An Alchemist Tale
SAPERE WP1 Alchemist status at 02/2013
Engineering Computational Ecosystems
Recipes for Sabayon: cook your own Linux distro within two hours
Ad

Recently uploaded (20)

PPTX
1. Introduction to Computer Programming.pptx
PPT
Teaching material agriculture food technology
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
August Patch Tuesday
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Machine Learning_overview_presentation.pptx
PDF
Encapsulation theory and applications.pdf
PDF
Mushroom cultivation and it's methods.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
A Presentation on Artificial Intelligence
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
1. Introduction to Computer Programming.pptx
Teaching material agriculture food technology
A comparative analysis of optical character recognition models for extracting...
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Advanced methodologies resolving dimensionality complications for autism neur...
A comparative study of natural language inference in Swahili using monolingua...
Getting Started with Data Integration: FME Form 101
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Univ-Connecticut-ChatGPT-Presentaion.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
August Patch Tuesday
Encapsulation_ Review paper, used for researhc scholars
Machine Learning_overview_presentation.pptx
Encapsulation theory and applications.pdf
Mushroom cultivation and it's methods.pdf
OMC Textile Division Presentation 2021.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
MIND Revenue Release Quarter 2 2025 Press Release
A Presentation on Artificial Intelligence
Diabetes mellitus diagnosis method based random forest with bat algorithm

Continuous Integration

  • 1. images/logo Developing, maintaining, and sharing software tools for research Continuous integration Danilo Pianini [email protected] Alma Mater Studiorum—Universit`a di Bologna Ph.D. course in Data Science and Computation June 7, 2018 - Bologna (Italy) D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 1 / 40
  • 2. images/logo Outline 1 Introduction 2 Travis CI 3 Configuration Basics Security Deployment Complete builds D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 2 / 40
  • 3. images/logo Introduction Why continuous? I Avoid the integration hell Work in parallel Don’t waste developers’ time with repetitive tasks Don’t break stuff Time is money Software development used to take several months for “integrating” a couple of years of development [Fow] Historically introduced by the extreme programming (XP) community Today used by companies that do not adopt XP IMVU [teab] delivers its software up to 50 times per day Google and Mozilla release at least once a day D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 3 / 40
  • 4. images/logo Introduction Why continuous? II Higher frequency, lower risk [Fab] D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 4 / 40
  • 5. images/logo Introduction Improve over classic development I Protoduction [teaa] When prototype code ends up in production Classically used with a negative meaning It’s time to rehabilitate it Make it easy to access and use the latest prototype D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 5 / 40
  • 6. images/logo Introduction Improve over classic development II It’s compiling [Mun] Make the building process fast! D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 6 / 40
  • 7. images/logo Introduction Continuous Integration software Software that promotes the practice of continuous integration Runs a build for every change in the project Prepares fresh environments where the builds are hosted Notifies the results, e.g. if a failure occurs Provides tools for deploying the produced artifacts Hosted CI with free plans for open source projects are blossoming: Circle CI Codefresh Codeship drone.io Pipelines Travis CI Wercker ... D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 7 / 40
  • 8. images/logo Travis CI Travis CI Web based Well integrated with GitHub Build results are displayed in the repo without intervention Automatic build of any pull request Free for open source projects Cronjobs Build instances based on Docker Project-local configuration via YAML (in the .travis.yml file) Out of the box support for Gradle Dozens of deployment targets D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 8 / 40
  • 9. images/logo Travis CI How it works A web-hook can be registered to your GitHub repository that triggers Travis CI at each new commit Travis CI starts a pristine appropriate environment Can be a container or a full virtual machine, depending on whether sudo is required [CI] The project gets cloned The configured commands are executed The configured deployments are performed If necessary, project managers are informed of the build status D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 9 / 40
  • 10. images/logo Configuration Basics Outline 1 Introduction 2 Travis CI 3 Configuration Basics Security Deployment Complete builds D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 10 / 40
  • 11. images/logo Configuration Basics .travis.yml Travis uses a project-local configuration A .travis.yml file must be in your repository root of course, it must be tracked in git It is a YAML file, very human-readable and easy to learn 1 Also it is a superset of JSON, so any valid JSON is a valid YAML Supports basically any language that can get built on Linux or MacOS No support for Windows builds Support for build matrix When your project can get built using different versions of different tools, you may want to test all of them It’s a cartesian product of configurations Commit once, build on every supported environment 1 https://learnxinyminutes.com/docs/yaml/ D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 10 / 40
  • 12. images/logo Configuration Basics .travis.yml: the language section Travis provides a number of default environments for the most common languages They differ by software installed by default e.g. the C# compiler is not included if you run a Python build) They behave differently e.g. if Java is specified as language, the system automatically searches for a build.gradle, a pom.xml (Maven), or an Ant build script The first configuration required is a specification on which environment to work in Defaults to Ruby For very simple projects, this might be enough of configuration Example language: python D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 11 / 40
  • 13. images/logo Configuration Basics .travis.yml: custom behavior using the script section The default configuration may be not suitable for you Either because you want to customize it Or because you are using something that is not in the spectrum of supported features Bash commands can be configured to be executed in place of the default behavior Example language: java script: - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash build.sh; fi' - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash build_pull_req.sh; fi' D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 12 / 40
  • 14. images/logo Configuration Basics .travis.yml: distribution selection in the dist section By default, Travis CI builds in a Ubuntu Linux environment Ubuntu LTS is generally used The version of Ubuntu can be selected in a dist section At the time of writing, trusty and precise are available Mac OS X can be used by specifying os: osx in place of dist Example language: python dist: trusty script: - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash build.sh; fi' - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash build_pull_req.sh; fi' D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 13 / 40
  • 15. images/logo Configuration Basics .travis.yml: enabling super user access By default, Travis CI builds in a docker container It’s way faster than a VM, especially in terms of start up time Docker does not allow for super-user access though Sometimes it is required e.g. for customizing the OS by installing packages In such case, sudo: required switches the build to a full fledged VM with super user access Example language: python dist: trusty sudo: required script: - 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash build.sh; fi' - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash build_pull_req.sh; fi' D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 14 / 40
  • 16. images/logo Configuration Basics The build lifecycle in Travis 1 Install — Install any dependency required 1 apt addons — Optional 2 cache components — Optional 3 before install — Install additional dependencies in form of Ubuntu packages using apt 4 install 2 Script — Run the build script 1 before script — Preparation for the build 2 script — Actual build 3 before cache — Optional 4 after success or after failure — Execute additional scripts depending on the outcome of the build 5 before deploy — Optional, used to prepare resources to be uploaded 6 deploy — Optional, used to actually deploy the produced artifacts 7 after deploy — Optional, additional operations to be executed after deployment 8 after script D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 15 / 40
  • 17. images/logo Configuration Basics .travis.yml: Example with several phases Example language: java dist: trusty sudo: required before_install: - sudo apt-get -qq update - sudo apt-get install -y graphviz before_install: echo Begin actual build script: - ./gradlew clean build - ./gradlew buildDashboard after_success: echo Build successful after failure: sudo mail -s "Build failure" [email protected] < /dev/null before_deploy: echo Preparing for deploy after_deploy: echo Deployment phase concluded. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 16 / 40
  • 18. images/logo Configuration Basics Build variables I Travis offers a number of environment variables that allow for fine tuning the build process. CI, TRAVIS, CONTINUOUS INTEGRATION, and HAS JOSH K SEAL OF APPROVALa a Josh K. is a co-founder of Travis CI: https://twitter.com/j2h Always set to true. Used for detecting if the build is running on the Continuous integration environment DEBIAN FRONTEND Always set to noninteractive. Some scripts use it to determine whether or not ask for user input. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 17 / 40
  • 19. images/logo Configuration Basics Build variables II USER Always set to travis. Do not depend on this value; do not override this value. HOME Always set to /home/travis. Do not depend on this value; do not override this value. LANG and LC ALL Always set to en US.UTF-8. RAILS ENV, RACK ENV, MERB ENV Always set to test D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 18 / 40
  • 20. images/logo Configuration Basics Build variables III JRUBY OPTS Always set to "--server -Dcext.enabled=false -Xcompile.invokedynamic=false" JAVA HOME Set to the appropriate value, depends on the selected JDK TRAVIS ALLOW FAILURE Set to true if the job is allowed to fail. Set to false if the job is not allowed to fail. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 19 / 40
  • 21. images/logo Configuration Basics Build variables IV TRAVIS BRANCH For push builds, or builds not triggered by a pull request, this is the name of the branch. For builds triggered by a pull request this is the name of the branch targeted by the pull request. For builds triggered by a tag, this is the same as the name of the tag (TRAVIS TAG). Note that for tags, git does not store the branch from which a commit was tagged. TRAVIS BUILD DIR The absolute path to the directory where the repository being built has been copied on the worker. TRAVIS BUILD ID The id of the current build that Travis CI uses internally. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 20 / 40
  • 22. images/logo Configuration Basics Build variables V TRAVIS BUILD NUMBER The number of the current build (for example, 4). TRAVIS COMMIT The commit that the current build is testing. TRAVIS COMMIT MESSAGE The commit subject and body, unwrapped. TRAVIS COMMIT RANGE The range of commits that were included in the push or pull request. Note that this is empty for builds triggered by the initial commit of a new branch. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 21 / 40
  • 23. images/logo Configuration Basics Build variables VI TRAVIS EVENT TYPE Indicates how the build was triggered. One of push, pull request, api, cron. TRAVIS JOB ID The id of the current job that Travis CI uses internally. TRAVIS JOB NUMBER The number of the current job (for example, 4.1). TRAVIS OS NAME On multi-OS builds, this value indicates the platform the job is running on. Values are linux and osx currently, to be extended in the future. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 22 / 40
  • 24. images/logo Configuration Basics Build variables VII TRAVIS OSX IMAGE The osx image value configured in .travis.yml. If this is not set in .travis.yml, it is empty. TRAVIS PULL REQUEST The pull request number if the current job is a pull request, false if it’s not a pull request. TRAVIS PULL REQUEST BRANCH If the current job is a pull request, the name of the branch from which the PR originated. If the current job is a push build, this variable is empty. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 23 / 40
  • 25. images/logo Configuration Basics Build variables VIII TRAVIS PULL REQUEST SHA If the current job is a pull request, the commit SHA of the HEAD commit of the PR. If the current job is a push build, this variable is empty. TRAVIS PULL REQUEST SLUG If the current job is a pull request, the slug (in the form owner name/repo name) of the repository from which the PR originated. If the current job is a push build, this variable is empty. TRAVIS REPO SLUG The slug (in form: owner name/repo name) of the repository currently being built. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 24 / 40
  • 26. images/logo Configuration Basics Build variables IX TRAVIS SECURE ENV VARS Set to true if there are any encrypted environment variables. Set to false if no encrypted environment variables are available. TRAVIS SUDO true or false based on whether sudo is enabled. TRAVIS TEST RESULT 0 if all commands in the script section (up to the point this environment variable is referenced) have exited with zero; 1 otherwise. TRAVIS TAG If the current build is for a git tag, this variable is set to the tag’s name. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 25 / 40
  • 27. images/logo Configuration Basics Build variables X TRAVIS BUILD STAGE NAME The build stage in capitalzed form, e.g. Test or Deploy. If a build does not use build stages, this variable is empty. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 26 / 40
  • 28. images/logo Configuration Security Outline 1 Introduction 2 Travis CI 3 Configuration Basics Security Deployment Complete builds D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 27 / 40
  • 29. images/logo Configuration Security Sensible data in builds It could be useful to access private data from within a build Downloading a password-protected file Decrypt a password-encrypted file Open a keystore for signing a file Store an API key for a service used e.g. for testing Store a OAuth token for accessing a remote service These data cannot be tracked on the repository (with the exception of encrypted files, but the problem is simply moved to passing the decrypt password to the build system). These data must be provided in form of enviroment variables Travis allows for inserting secure variables in the web interface D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 27 / 40
  • 30. images/logo Configuration Security Pull request attack Usually, you want the integrator to build pull requests You want to test the integration before committing it What if the pull request changes the .travis.yml, printing all the environment variables? The developer of an open source project is defenseless Travis CI does not allow access to secure variables when a pull request is executed As such, typically, the Travis build must be configured to detect whether a pull request is being bult, and in case don’t perform tasks that depend on secure variables D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 28 / 40
  • 31. images/logo Configuration Security Local Travis installation Travis CI provides an installable module to help with several tasks otherwise tedious: Secure encryption of files You may need your private key for automatic signing, but you want it to be secret and only readable by builds you create Secure encryption of global variables You may need your password or username or other sensible data to complete the deployment process, but you want it encrypted In case of OAuth tokens, you also don’t want to waste time dealing with it manually. Install Travis CI locally: 1 Install RubyGems On Arch Linux: pacman -Syu rubygems ruby-rdoc 2 Issue: gem install travis 3 Make sure your PATH includes the path where gems are installed D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 29 / 40
  • 32. images/logo Configuration Security Creating a secure variable From the web interface: Go to the settings page Insert name and value Select if it should be displayed on the build Disable if the variable is meant to be secure Use the environment variable in your build From the local Travis CI application: travis encrypt MY SECRET ENV=super secret The secured variable will be printed on terminal copy the secure="..." inside your .travis.yml D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 30 / 40
  • 33. images/logo Configuration Security Ecrypting a file From the local Travis CI application: travis encrypt-file my-super-secret-file A new my-super-secret-file.enc file will be created It must be added to track The originating file must not be in track, and must never have been (or it could be recovered): delete it immediately copy the secure="..." inside your .travis.yml Add the generated openssl command that appears on the terminal to the correct phase of your build D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 31 / 40
  • 34. images/logo Configuration Security Don’t screw up: non-exhaustive list of advices DO generate passwords, never use words related to the repository or project name DON’T use settings which duplicate commands to standard output, such as set -x or set -v in your bash scripts DON’T run env or printenv DON’T echo "$SECRET_KEY" DON’T use tools that print secrets on error output, such as php -i DOUBLE CHECK before using git fetch or git push, as they might expose tokens or other secure variables DUOBLE CHECK for mistakes in string escaping DUOBLE CHECK before using settings that increase verbosity PREFER redirecting output to /dev/null when possible e.g. git push url-with-secret >/dev/null 2>&1 D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 32 / 40
  • 35. images/logo Configuration Deployment Outline 1 Introduction 2 Travis CI 3 Configuration Basics Security Deployment Complete builds D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 33 / 40
  • 36. images/logo Configuration Deployment GitHub Releases Travis CI can automate deployment of artifacts on GitHub releases Example .travis.yml configuration deploy: provider: releases api_key: secure: YOUR_API_KEY_ENCRYPTED file: "FILE TO UPLOAD" skip_cleanup: true on: tags: true The authentication token for GitHub can be generated locally with: travis setup releases Remember to backup your travis file before running the command D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 33 / 40
  • 37. images/logo Configuration Deployment surge.sh A free host for static websites (HTML + Javascript) Install surge locally Create an account (with email and password) Create a new secret variable SURGE LOGIN Create a new secret variable SURGE TOKEN Obtain the value by using surge token Example .travis.yml configuration deploy: provider: surge project: ./build/docs/javadoc/ domain: myjavadoc.surge.sh skip_cleanup: true on: all_branches: true D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 34 / 40
  • 38. images/logo Configuration Deployment Deploy to PyPI The best place where to put your Python software modules! Sign up to PyPI Example .travis.yml configuration deploy: provider: pypi user: "Your (possibly encrypted) username" password: secure: "Your encrypted password" D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 35 / 40
  • 39. images/logo Configuration Deployment Other targets anynines – Appfog – Atlas – AWS CodeDeploy – AWS Elastic Beanstalk – AWS Lambda – AWS OpsWorks – AWS S3 – Azure Web Apps – bintray – BitBalloon – Bluemix CloudFoundry – Boxfuse – Catalyze – Chef Supermarket – Cloud 66 – CloudFoundry – Deis – Engine Yard – GitHub Pages – Google App Engine – Google Cloud Storage – Google Firebase – Hackage – Heroku – Launchpad – Modulus – npm – OpenShift – packagecloud.io – Puppet – Forge – PyPI – Rackspace Cloud Files – RubyGems – Scalingo – Script – TestFairy – Ubuntu Snap Store – Uploading Build Artifacts Plus any target your build system can directly deal with (e.g. Maven Central) D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 36 / 40
  • 40. images/logo Configuration Complete builds Outline 1 Introduction 2 Travis CI 3 Configuration Basics Security Deployment Complete builds D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 37 / 40
  • 41. images/logo Configuration Complete builds Example with Python The default Python environment uses isolated virtualenvs PyPy is supported out of the box The script entry is mandatory dependencies can be listed in a requirements.txt file Travis automatically runs pip install -r requirements.txt during the install phase of the build D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 37 / 40
  • 42. images/logo Configuration Complete builds Java examples Examples of rich, multi-project, multi-language, multi-target deployments are available at: https://github.com/AlchemistSimulator/Alchemist https://github.com/Protelis/Protelis D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 38 / 40
  • 43. images/logo References References I Travis CI. The build environment. https://docs.travis-ci.com/user/ci-environment/. Accessed: 2017-05-08. Darko Fabijan. Why we need continuous integration. https://semaphoreci.com/community/tutorials/continuous-integration. Accessed: 2017-05-03. Martin Fowler. Continuous integration. https://www.martinfowler.com/articles/continuousIntegration.html. Accessed: 2017-05-02. Randall Munroe. xkcd: Compiling. https://xkcd.com/303/. Accessed: 2017-05-03. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 39 / 40
  • 44. images/logo References References II The CodingHorror team. New programming jargon. https://blog.codinghorror.com/new-programming-jargon/. Accessed: 2017-05-02. The IMVU team. Imvu: 3d avatar free chat, make new friends, dress up, shop. https://www.imvu.com/. Accessed: 2017-05-02. D. Pianini (UniBo) 04 - Continuous Integration June 7, 2018 40 / 40