Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PHP and IoT: Creating a Deployment Device

Ivan
May 28, 2017

PHP and IoT: Creating a Deployment Device

Setup Jenkins on a raspberry pi, connect it to a GitHub project and trigger the build remotely via gesture sensor on NodeMCU.

Ivan

May 28, 2017
Tweet

Other Decks in Technology

Transcript

  1. 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.
  2. 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.
  3. Requirements A Laptop GIT installed on your machine GitHub account

    Composer Open the readme.md github.com/phpsrb/phpiot
  4. Connect to this WiFi in order to connect to devices

    SSID: PHPSrb2017booth Password: php_serbia_conference_2017
  5. - 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
  6. > Create a GitHub repo 1. Create an account on

    GitHub 2. Create a repo called ‘phpiot’
  7. 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
  8. 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
  9. How do you connect with your Raspberry Pi? • Go

    camping together • Watch a movie • Go out and get drunk • ...
  10. 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
  11. $ 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
  12. 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
  13. Create a Jenkins Job General => GitHub Project [x] Project

    Url: https://github.com/{username}/phpiot/
  14. 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
  15. Configure the Jenkins job to have a Build Step =>

    Execute Shell Copy the script from README.md
  16. class ExampleTest extends TestCase { /** * A basic test

    example. * * @return void */ public function testBasicTest() { $response = $this->get('/'); $response->assertStatus(418); // I’m a teapot } }
  17. 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
  18. 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 }
  19. 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