{"id":329,"date":"2016-05-01T12:51:51","date_gmt":"2016-05-01T10:51:51","guid":{"rendered":"https:\/\/blog.unetresgrossebite.com\/?p=329"},"modified":"2016-05-01T14:14:42","modified_gmt":"2016-05-01T12:14:42","slug":"circle-ci","status":"publish","type":"post","link":"https:\/\/blog.unetresgrossebite.com\/?p=329","title":{"rendered":"CircleCI"},"content":{"rendered":"<p><a href=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle.png\"><img decoding=\"async\" loading=\"lazy\" class=\"alignleft wp-image-338 size-full\" src=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle.png\" alt=\"CircleCI logo\" width=\"204\" height=\"192\" \/><\/a><\/p>\n<p>A few months ago, starting a job for a client I never worked with before, I was asked to write unit tests to familiarize myself with their product, and find a way to run these tests whenever a coworker would push his changes\u00a0to GitHub. Testing our code requires a blank Riak database and a blank Redis server.\u00a0Back then, I looked at several solutions such as <a href=\"https:\/\/jenkins.io\/\">Jenkins<\/a> or <a href=\"https:\/\/www.jetbrains.com\/teamcity\/\">TeamCity<\/a>,\u00a0in combination with Docker. Although I also considered services such as <a href=\"https:\/\/travis-ci.org\">Travis<\/a> and the one we&#8217;ll focus on today: <a href=\"https:\/\/circleci.com\/\">CircleCI<\/a>.<\/p>\n<p>I didn&#8217;t knew of Travis and CircleCI before looking into running my own unit tests, which is a shame. Both service will provide you with free virtual machines within EC2, running unit tests according to some yaml file, describing how to setup your environment and validate your code works. The main difference between relies in billing.<br \/>\nCircle is free as long as you only run one build job at a time. You may pay to run concurrent jobs.<br \/>\nTravis is always free for opensource projects\u00a0&#8211;\u00a0as long as your repository is publicly available. You may pay to run tests against private repositories or\u00a0to run concurrent jobs.<br \/>\nThe big advantage behind such services is that you may easily install, configure and run\u00a0dependencies your test will require. Setting up Postgres, MySQL, Redis or Riak databases, set a version for NodeJS, Go, PHP, python, &#8230;. And they provide with ways of testing Android and iOS applications as well.<br \/>\nBoth will Circle and Travis will run your test from private VMs by default, although both would allow you to eventually enable SSH and forward some port\/ip combination to your instance, so you may troubleshoot your tests while they&#8217;re running.<br \/>\nIn terms of GUI, both services offer with a clean and relatively-lightweight way to track your jobs as they&#8217;re running.\u00a0Back when I had to choose, CircleCI GUI was performing better on my old laptop, hence I can&#8217;t tell much more about Travis.<br \/>\nBoth are integrated to GitHub, and will allow you to enable running automated tests on a per-repository basis, as well as pick the branches you need to build (or ignore).<\/p>\n<div id=\"attachment_334\" style=\"width: 238px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-tests-start.png\"><img aria-describedby=\"caption-attachment-334\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-334 size-medium\" src=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-tests-start-228x300.png\" alt=\"Tracking Tests on CircleCI\" width=\"228\" height=\"300\" srcset=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-tests-start-228x300.png 228w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-tests-start.png 439w\" sizes=\"(max-width: 228px) 100vw, 228px\" \/><\/a><p id=\"caption-attachment-334\" class=\"wp-caption-text\">Tracking Tests on CircleCI<\/p><\/div>\n<p>The first thing you need, running automated unit tests, is your unit tests. In my case, the project is a nodejs-based webservice. API documentation is pretty straight forward. I started with a small set of checks (is the service responding, does it fail when I try to call commands without authenticating?). Over the next days, I was able to check all our API calls, making sure our documentation was correct, and that error code were consistent when\u00a0feeding\u00a0these calls with incorrect arguments. Depending on your project, you may not need to get into this much trouble.<\/p>\n<div id=\"attachment_332\" style=\"width: 250px\" class=\"wp-caption alignright\"><a href=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circleyaml.png\"><img aria-describedby=\"caption-attachment-332\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-332\" src=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circleyaml-240x300.png\" alt=\"circle.yml\" width=\"240\" height=\"300\" srcset=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circleyaml-240x300.png 240w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circleyaml.png 536w\" sizes=\"(max-width: 240px) 100vw, 240px\" \/><\/a><p id=\"caption-attachment-332\" class=\"wp-caption-text\">circle.yml<\/p><\/div>\n<p>Having your unit tests ready, the next thing you\u00a0need is a Makefile, or set of script that would\u00a0initialize your databases (if applicable), install your nodejs\/ruby\/python\/php dependencies (if applicable), &#8230; you should be able to easily run\u00a0every step required, having fetched the last revision of your repository, to run your service.<\/p>\n<p>Now that you can easily start and run tests against your service, you may focus on configuring CircleCI creating a\u00a0<em>circle.yml<\/em>, at the root of your repository. In there, you will tell CircleCI what it needs to do to run your tests. Consider the base system is a Ubuntu 12.04 (precise), and may be changed to 14.04 (trusty). You may define environment variables, enable pre-installed services, install what could be missing. Your commands are issued as the <em>ubuntu<\/em> user, although you have unrestricted access to sudo. There&#8217;s much to say,\u00a0feel free to\u00a0give a look at <a href=\"https:\/\/circleci.com\/docs\/configuration\/\">their\u00a0documentation<\/a>.<\/p>\n<div id=\"attachment_335\" style=\"width: 310px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-jobs.png\"><img aria-describedby=\"caption-attachment-335\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-335\" src=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-jobs-300x116.png\" alt=\"circle jobs\" width=\"300\" height=\"116\" srcset=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-jobs-300x116.png 300w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-jobs-768x296.png 768w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-jobs-1024x395.png 1024w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-jobs.png 1350w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-335\" class=\"wp-caption-text\">circle jobs<\/p><\/div>\n<p>Having figured out a way to properly run your tests, and granted that your set of tests is &#8220;exhaustive enough&#8221;, then you will be able to spot mistakes in the next few minutes of their being pushed.<\/p>\n<p>Moreover, for those familiar with Slack: you easily\u00a0setup notifications. &#8212; and the others should definitely look into <a href=\"https:\/\/slack.com\/\">Slack<\/a>, I&#8217;ll probably post something soon about it, as I was able to get rid of lots of mail and SMS spam, sending my notifications (cron or nagios) there, and still getting notifications on my phone using their Android app: even if you do not work with teammates, Slack can make sense.<\/p>\n<p>Back on Circle, last but not least, having successfully passed your tests, those of you using CodeDeploy\u00a0(something else I should write a post about) may trigger a deployment, achieving both Continuous Integration and Continuous Delivery.<\/p>\n<div id=\"attachment_337\" style=\"width: 244px\" class=\"wp-caption alignright\"><a href=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-slack.png\"><img aria-describedby=\"caption-attachment-337\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-337\" src=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-slack-234x300.png\" alt=\"Slack Integration\" width=\"234\" height=\"300\" srcset=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-slack-234x300.png 234w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-slack.png 434w\" sizes=\"(max-width: 234px) 100vw, 234px\" \/><\/a><p id=\"caption-attachment-337\" class=\"wp-caption-text\">Slack Integration<\/p><\/div>\n<p>The\u00a0screenshot on the right shows our Slack thread: our team ends up deploying several times a day, errors\u00a0are spotted as they are pushed to GitHub, whereas the one on the left shows the end of a successful test, that ended up in pushing code to our staging setup.<\/p>\n<div id=\"attachment_333\" style=\"width: 310px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-test-done.png\"><img aria-describedby=\"caption-attachment-333\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-333\" src=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-test-done-300x137.png\" alt=\"circle unit tests done\" width=\"300\" height=\"137\" srcset=\"https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-test-done-300x137.png 300w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-test-done-768x350.png 768w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-test-done-1024x466.png 1024w, https:\/\/blog.unetresgrossebite.com\/wp-content\/uploads\/2016\/05\/circle-unit-test-done.png 1300w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-333\" class=\"wp-caption-text\">circle unit tests done<\/p><\/div>\n<p>To conclude, I had my first experiences with CI &amp; CD about 8\u00a0months ago, and was not completely sold on the idea to begin with. I always assume that when I push code, I did test it, and so did my colleagues. Although Continuous Integration definitely helped, in forcing our whole team spotting and quickly fixing whatever mistake someone would have pushed. And at some extent, it sometimes leads me to push &#8220;theoretical&#8221; patches without even testing them, knowing CircleCI would eventually yell at me, &#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few months ago, starting a job for a client I never worked with before, I was asked to write unit tests to familiarize myself with their product, and find a way to run these tests whenever a coworker would push his changes\u00a0to GitHub. Testing our code requires a blank Riak database and a blank [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8,10],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/posts\/329"}],"collection":[{"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=329"}],"version-history":[{"count":16,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/posts\/329\/revisions"}],"predecessor-version":[{"id":351,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=\/wp\/v2\/posts\/329\/revisions\/351"}],"wp:attachment":[{"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.unetresgrossebite.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}