Slide 1

Slide 1 text

IoT Jenkins Deployment Device Petar Slović && Ivan Ćirić Quantox Technology

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

Continuous Integration Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early. By integrating regularly, you can detect errors quickly, and locate them more easily. Because you’re integrating so frequently, there is significantly less back-tracking to discover where things went wrong, so you can spend more time building features. Continuous Integration is cheap. Not integrating continuously is expensive. If you don’t follow a continuous approach, you’ll have longer periods between integrations. This makes it exponentially more difficult to find and fix problems. Such integration problems can easily knock a project off-schedule, or cause it to fail altogether. Continuous Integration brings multiple benefits to your organization: Say goodbye to long and tense integrations, Increase visibility enabling greater communication, Catch issues early and nip them in the bud, Spend less time debugging and more time adding features, Build a solid foundation, Stop waiting to find out if your code’s going to work, Reduce integration problems allowing you to deliver software more rapidly. The main aim of CI is to prevent integration problems, referred to as "integration hell" in early descriptions of XP. CI is not universally accepted as an improvement over frequent integration, so it is important to distinguish between the two as there is disagreement about the virtues of each.[citation needed] In XP, CI was intended to be used in combination with automated unit tests written through the practices of test-driven development. Initially this was conceived of as running all unit tests in the developer's local environment and verifying they all passed before committing to the mainline. This helps avoid one developer's work-in-progress breaking another developer's copy. If necessary, partially complete features can be disabled before commit, such as by using feature toggles. Later elaborations of the concept introduced build servers, which automatically ran the unit tests periodically or even after every commit and reported the results to the developers. The use of build servers (not necessarily running unit tests) had already been practiced by some teams outside the XP community. Nowadays, many organizations have adopted CI without adopting all of XP. In addition to automated unit tests, organizations using CI typically use a build server to implement continuous processes of applying quality control in general — small pieces of effort, applied frequently. In addition to running the unit and integration tests, such processes run additional static and dynamic tests, measure and profile performance, extract and format documentation from the source code and facilitate manual QA processes. This continuous application of quality control aims to improve the quality of software, and to reduce the time taken to deliver it, by replacing the traditional practice of applying quality control after completing all development. This is very similar to the original idea of integrating more frequently to make integration easier, only applied to QA processes. In the same vein, the practice of continuous delivery further extends CI by making sure the software checked in on the mainline is always in a state that can be deployed to users and makes the actual deployment process very rapid. When embarking on a change, a developer takes a copy of the current code base on which to work. As other developers submit changed code to the source code repository, this copy gradually ceases to reflect the repository code. Not only can the existing code base change, but new code can be added as well as new libraries, and other resources that create dependencies, and potential conflicts. The longer a branch of code remains checked out, the greater the risk of multiple integration conflicts and failures when the developer branch is reintegrated into the main line. When developers submit code to the repository they must first update their code to reflect the changes in the repository since they took their copy. The more changes the repository contains, the more work developers must do before submitting their own changes. Eventually, the repository may become so different from the developers' baselines that they enter what is sometimes referred to as "merge hell", or "integration hell",[3] where the time it takes to integrate exceeds the time it took to make their original changes. When embarking on a change, a developer takes a copy of the current code base on which to work. As other developers submit changed code to the source code repository, this copy gradually ceases to reflect the repository code. Not only can the existing code base change, but new code can be added as well as new libraries, and other resources that create dependencies, and potential conflicts. The longer a branch of code remains checked out, the greater the risk of multiple integration conflicts and failures when the developer branch is reintegrated into the main line. When developers submit code to the repository they must first update their code to reflect the changes in the repository since they took their copy. The more changes the repository contains, the more work developers must do before submitting their own changes. Eventually, the repository may become so different from the developers' baselines that they enter what is sometimes referred to as "merge hell", or "integration hell",[3] where the time it takes to integrate exceeds the time it took to make their original changes. Continuous integration involves integrating early and often, so as to avoid the pitfalls of "integration hell". The practice aims to reduce rework and thus reduce cost and time.[4] A complementary practice to CI is that before submitting work, each programmer must do a complete build and run (and pass) all unit tests. Integration tests are usually run automatically on a CI server when it detects a new commit. In 1994, Grady Booch used the phrase continuous integration in Object-Oriented Analysis and Design with Applications (2nd edition)[5] to explain how, when developing using micro processes, "internal releases represent a sort of continuous integration of the system, and exist to force closure of the micro process." In 1997, Kent Beck and Ron Jeffries invented Extreme Programming (XP) while on the Chrysler Comprehensive Compensation System project, including continuous integration.[6] Beck published about continuous integration in 1998, emphasising the importance of face-to-face communication over technological support.[7] In 1999, Beck elaborated more in his first full book on Extreme Programming.[8] CruiseControl was released in 2001. When embarking on a change, a developer takes a copy of the current code base on which to work. As other developers submit changed code to the source code repository, this copy gradually ceases to reflect the repository code. Not only can the existing code base change, but new code can be added as well as new libraries, and other resources that create dependencies, and potential conflicts. The longer a branch of code remains checked out, the greater the risk of multiple integration conflicts and failures when the developer branch is reintegrated into the main line. When developers submit code to the repository they must first update their code to reflect the changes in the repository since they took their copy. The more changes the repository contains, the more work developers must do before submitting their own changes. Eventually, the repository may become so different from the developers' baselines that they enter what is sometimes referred to as "merge hell", or "integration hell",[3] where the time it takes to integrate exceeds the time it took to make their original changes. Continuous integration involves integrating early and often, so as to avoid the pitfalls of "integration hell". The practice aims to reduce rework and thus reduce cost and time.[4] A complementary practice to CI is that before submitting work, each programmer must do a complete build and run (and pass) all unit tests. Integration tests are usually run automatically on a CI server when it detects a new commit. In 1994, Grady Booch used the phrase continuous integration in Object-Oriented Analysis and Design with Applications (2nd edition)[5] to explain how, when developing using micro processes, "internal releases represent a sort of continuous integration of the system, and exist to force closure of the micro process." In 1997, Kent Beck and Ron Jeffries invented Extreme Programming (XP) while on the Chrysler Comprehensive Compensation System project, including continuous integration.[6] Beck published about continuous integration in 1998, emphasising the importance of face-to-face communication over technological support.[7] In 1999, Beck elaborated more in his first full book on Extreme Programming.[8] CruiseControl was released in 2001.

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

Continuous Integration ● Push code often ● Build/test ● Repeat

Slide 12

Slide 12 text

Continuous Delivery Software is always in a deliverable state, ready to be deployed on demand. Continuous Deployment Every change that passes automated testing is automatically deployed to specific servers.

Slide 13

Slide 13 text

Tools

Slide 14

Slide 14 text

● Has a bunch of plugins ● All the cool kids are using it

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Here we go!

Slide 19

Slide 19 text

Requirements A Laptop GIT installed on your machine GitHub account Composer Open the readme.md github.com/phpsrb/phpiot

Slide 20

Slide 20 text

Connect to this WiFi in order to connect to devices SSID: PHPSrb2017booth Password: php_serbia_conference_2017

Slide 21

Slide 21 text

- Create a GitHub repo - Create a Laravel application - Connect with Raspberry Pi - Install Jenkins on Raspberry Pi - Setup a Jenkins job - Setup Jenkins GitHub credentials - Test our deployment tool Steps

Slide 22

Slide 22 text

> Create a GitHub repo 1. Create an account on GitHub 2. Create a repo called ‘phpiot’

Slide 23

Slide 23 text

> Create a Laravel application $ composer create-project --prefer-dist laravel/laravel phpsrb $ cd phpsrb

Slide 24

Slide 24 text

phpsrb$ git init phpsrb$ git add . phpsrb$ git remote add origin https://github.com/{username}/phpiot.git phpsrb$ git commit -m ‘Initial commit’ phpsrb$ git push -u origin master

Slide 25

Slide 25 text

Create a GitHub repo > Connect with Raspberry Pi Install Jenkins on Raspberry Pi Setup a Jenkins job Setup Jenkins GitHub credentials Test our deployment tool

Slide 26

Slide 26 text

How do you connect with your Raspberry Pi? ● Go camping together ● Watch a movie ● Go out and get drunk ● ...

Slide 27

Slide 27 text

Connect the RPi USB microUSB

Slide 28

Slide 28 text

Wait a bit until Raspberry Pi boots...

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

$ ssh [email protected] Password: jenkinsX

Slide 31

Slide 31 text

Create a GitHub repo Connect with Raspberry Pi > Install Jenkins on Raspberry Pi Setup a Jenkins job Setup Jenkins GitHub credentials Test our deployment tool

Slide 32

Slide 32 text

$ sudo update-alternatives --config java (8) $ mkdir jenkins $ cd jenkins $ wget -q -O - https://jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add - $ sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list' $ sudo apt-get update $ sudo apt-get install jenkins $ sudo /etc/init.d/jenkins start

Slide 33

Slide 33 text

http://jenkinsX.local:8080

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Install suggested plugins...

Slide 36

Slide 36 text

Create a new Jenkins User Username: admin Password: jenkins

Slide 37

Slide 37 text

Create a GitHub repo Connect with Raspberry Pi Install Jenkins on Raspberry Pi > Setup a Jenkins job Setup Jenkins GitHub credentials Test our deployment tool

Slide 38

Slide 38 text

Create a Jenkins Job - Name: buildpi - Freestyle Job

Slide 39

Slide 39 text

Create a Jenkins Job General => GitHub Project [x] Project Url: https://github.com/{username}/phpiot/

Slide 40

Slide 40 text

Source Code Management => Git [x] Repository Url: https://github.com/{username}/phpiot.git

Slide 41

Slide 41 text

Create a GitHub repo Connect with Raspberry Pi Install Jenkins on Raspberry Pi Setup a Jenkins job > Setup Jenkins GitHub credentials Test our deployment tool

Slide 42

Slide 42 text

Add Credentials to Jenkins Connect your GitHub account using username and password

Slide 43

Slide 43 text

Build Triggers => Trigger Builds Remotely [x] Authentication Token: php-srb-2017

Slide 44

Slide 44 text

Configure the Jenkins job to have a Build Step => Execute Shell Copy the script from README.md

Slide 45

Slide 45 text

python green-light.py python red-light.py

Slide 46

Slide 46 text

class ExampleTest extends TestCase { /** * A basic test example. * * @return void */ public function testBasicTest() { $response = $this->get('/'); $response->assertStatus(418); // I’m a teapot } }

Slide 47

Slide 47 text

Create a GitHub repo Connect with Raspberry Pi Install Jenkins on Raspberry Pi Setup a Jenkins job Setup Jenkins GitHub credentials > Test our deployment tool

Slide 48

Slide 48 text

Wave left! (and wait a few seconds)

Slide 49

Slide 49 text

1. sudo nano /etc/wpa_supplicant/wpa_supplicant.conf 2. Add/modify the ‘network’ element: Changing/adding WiFi networks to Rpi via CLI network={ ssid="PHPSrb2017booth" psk="php_serbia_conference_2017" key_mgmt=WPA-PSK }

Slide 50

Slide 50 text

Fixed IP address Your pi’s have fixed IP addresses. In order to remove this setting, open up the sudo nano /etc/dhcpcd.conf file and remove or edit the following: interface wlan0 static ip_address=192.168.0.200/24 static routers=192.168.0.1 static domain_name_servers=192.168.0.1

Slide 51

Slide 51 text

Remember to check this repo for details https://github.com/phpsrb/phpiot/blob/master/readme.md

Slide 52

Slide 52 text

https://joind.in/talk/b4103

Slide 53

Slide 53 text

Questions? Thank you!