{"id":1161,"date":"2022-01-02T15:30:03","date_gmt":"2022-01-02T22:30:03","guid":{"rendered":"https:\/\/bullyrooks.com\/?p=1161"},"modified":"2022-01-05T16:33:57","modified_gmt":"2022-01-05T23:33:57","slug":"cloud-kube-build-pipeline-initialization","status":"publish","type":"post","link":"https:\/\/bullyrooks.com\/index.php\/2022\/01\/02\/cloud-kube-build-pipeline-initialization\/","title":{"rendered":"Cloud Kube | Build Pipeline Initialization"},"content":{"rendered":"\n<p>Now that we have a service we&#8217;re going to start building our pipeline so that as we add functionality to the application we can incorporate any build needs into the pipeline.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Initialize Github Actions<\/h2>\n\n\n\n<p>Create a new directory from the root of the project called .github\/workflows\/  create a file called features.yaml in that directory<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"368\" height=\"85\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-14.png?resize=368%2C85&#038;ssl=1\" alt=\"\" class=\"wp-image-1162\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-14.png?w=368&amp;ssl=1 368w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-14.png?resize=300%2C69&amp;ssl=1 300w\" sizes=\"auto, (max-width: 368px) 100vw, 368px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>add this code to features.yaml<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name: Cloud Application Feature Branch Build\n\non:\n  push:\n    branches-ignore:\n      - main\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\/checkout@v2\n        with:\n          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis\n\n      - name: Set up JDK 11\n        uses: actions\/setup-java@v2.3.1\n        with:\n          java-version: '11'\n          distribution: 'adopt'\n          cache: maven\n\n      - name: Build with Maven\n        run: .\/mvnw -B test<\/code><\/pre>\n\n\n\n<p>Here&#8217;s a quick breakdown on what we&#8217;re doing with this action definition:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Execute this on every push except if the push is to master.  This will build on every commit\/push.  We&#8217;re using this to tell us if we broke the build by either not compiling or tests not passing.<\/li><li>Checkout our git repo<\/li><li>Setup a build environment (ubuntu with java 11).  Cache the maven dependencies so that we can reuse our maven repo between builds.<\/li><li>Run the maven build with test.<\/li><\/ul>\n\n\n\n<p>Push it up to execute the build.  You should be on the microservice_dev branch already (change to that branch if you need to).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git add .\n\n$ git commit -m \"build pipeline\"\n&#91;microservice_dev 37843c6] build pipeline\n 1 file changed, 24 insertions(+)\n create mode 100644 .github\/workflows\/features.yaml\n\n$  git push --set-upstream origin microservice_dev\nEnumerating objects: 31, done.\nCounting objects: 100% (31\/31), done.\nDelta compression using up to 4 threads\nCompressing objects: 100% (13\/13), done.\nWriting objects: 100% (20\/20), 2.30 KiB | 1.15 MiB\/s, done.\nTotal 20 (delta 2), reused 0 (delta 0), pack-reused 0\nremote: Resolving deltas: 100% (2\/2), completed with 2 local objects.\nremote: \nremote: Create a pull request for 'microservice_dev' on GitHub by visiting:\nremote:      https:\/\/github.com\/bullyrooks\/cloud_application\/pull\/new\/microservice_dev\nremote:\nTo github.com-bullyrook:bullyrooks\/cloud_application.git\n * &#91;new branch]      microservice_dev -&gt; microservice_dev\nBranch 'microservice_dev' set up to track remote branch 'microservice_dev' from 'origin'.\n<\/code><\/pre>\n\n\n\n<p>Now navigate to your project in github and click on the Actions tab<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"96\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-15.png?resize=400%2C96&#038;ssl=1\" alt=\"\" class=\"wp-image-1163\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-15.png?w=400&amp;ssl=1 400w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-15.png?resize=300%2C72&amp;ssl=1 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<p>You should see your build running, if you click on the build job, you&#8217;ll see your actions being run.  Eventually, it should succeed<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"257\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-16-1024x274.png?resize=960%2C257&#038;ssl=1\" alt=\"\" class=\"wp-image-1164\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-16.png?resize=1024%2C274&amp;ssl=1 1024w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-16.png?resize=300%2C80&amp;ssl=1 300w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-16.png?resize=768%2C206&amp;ssl=1 768w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-16.png?resize=1536%2C411&amp;ssl=1 1536w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-16.png?w=1654&amp;ssl=1 1654w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Create the Main Build and Deploy<\/h2>\n\n\n\n<p>Copy your <code>feature.yaml<\/code> file into a new file in the same directory called <code>main.yaml<\/code>.  Change the push branch configuration to look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>on:\n  push:\n    branches:\n      - main<\/code><\/pre>\n\n\n\n<p>Now commit and push this change<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git add .\n\n$ git commit -m \"main build\"\n&#91;microservice_dev 6491da8] main build\n 1 file changed, 24 insertions(+)\n create mode 100644 .github\/workflows\/main.yaml\n\n$ git push\nEnumerating objects: 8, done.\nCounting objects: 100% (8\/8), done.\nDelta compression using up to 4 threads\nCompressing objects: 100% (4\/4), done.\nWriting objects: 100% (5\/5), 676 bytes | 676.00 KiB\/s, done.\nTotal 5 (delta 1), reused 0 (delta 0), pack-reused 0\nremote: Resolving deltas: 100% (1\/1), completed with 1 local object.\nTo github.com-bullyrook:bullyrooks\/cloud_application.git\n   82f4cb5..6491da8  microservice_dev -&gt; microservice_dev<\/code><\/pre>\n\n\n\n<p>This will trigger a single build (because it&#8217;s a commit to a non main branch), but it shouldn&#8217;t trigger <strong>two<\/strong> builds.<\/p>\n\n\n\n<p>Now lets merge <code>microserivce_dev<\/code> into <code>main<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git checkout main\nSwitched to branch 'main'\nYour branch is up to date with 'origin\/main'.\n\n$ git merge --squash microservice_dev\nUpdating 1a73461..6491da8\nFast-forward\nSquash commit -- not updating HEAD\n .github\/workflows\/features.yaml                    | 24 +++++++++++\n .github\/workflows\/main.yaml                        | 24 +++++++++++\n .gitignore                                         |  3 +-\n ...\/controller\/HelloWorldController.java           | 15 +++++++\n ...\/controller\/dto\/HelloWorldResponse.java         | 14 +++++++\n ...\/controller\/HelloWorldControllerTest.java       | 46 ++++++++++++++++++++++\n 6 files changed, 125 insertions(+), 1 deletion(-)\n create mode 100644 .github\/workflows\/features.yaml\n create mode 100644 .github\/workflows\/main.yaml\n create mode 100644 src\/main\/java\/com\/bullyrooks\/cloud_application\/controller\/HelloWorldController.java\n create mode 100644 src\/main\/java\/com\/bullyrooks\/cloud_application\/controller\/dto\/HelloWorldResponse.java\n create mode 100644 src\/test\/java\/com\/bullyrooks\/cloud_application\/controller\/HelloWorldControllerTest.java\n\n$ git commit -m \"microservice endpoint and build pipeline\"\n&#91;main cf0e328] microservice endpoint and build pipeline\n 6 files changed, 125 insertions(+), 1 deletion(-)\n create mode 100644 .github\/workflows\/features.yaml\n create mode 100644 .github\/workflows\/main.yaml\n create mode 100644 src\/main\/java\/com\/bullyrooks\/cloud_application\/controller\/HelloWorldController.java\n create mode 100644 src\/main\/java\/com\/bullyrooks\/cloud_application\/controller\/dto\/HelloWorldResponse.java\n create mode 100644 src\/test\/java\/com\/bullyrooks\/cloud_application\/controller\/HelloWorldControllerTest.java\n\n$ git push\nEnumerating objects: 35, done.\nCounting objects: 100% (35\/35), done.\nDelta compression using up to 4 threads\nCompressing objects: 100% (16\/16), done.\nWriting objects: 100% (24\/24), 2.78 KiB | 950.00 KiB\/s, done.\nTotal 24 (delta 3), reused 0 (delta 0), pack-reused 0\nremote: Resolving deltas: 100% (3\/3), completed with 2 local objects.\nTo github.com-bullyrook:bullyrooks\/cloud_application.git\n   1a73461..cf0e328  main -&gt; main<\/code><\/pre>\n\n\n\n<p>Navigate back to github actions tab.  You should see a single build being kicked off from the main branch.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"855\" height=\"325\" src=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-17.png?resize=855%2C325&#038;ssl=1\" alt=\"\" class=\"wp-image-1166\" srcset=\"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-17.png?w=855&amp;ssl=1 855w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-17.png?resize=300%2C114&amp;ssl=1 300w, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-17.png?resize=768%2C292&amp;ssl=1 768w\" sizes=\"auto, (max-width: 855px) 100vw, 855px\" data-recalc-dims=\"1\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>This is a very important stage in our application lifecycle.  We&#8217;re going to be building off of these two pipelines continually in the next stages of the course.  It&#8217;s important to have a distinction between &#8216;feature&#8217; branch and &#8216;main&#8217; branch builds.  If we were going to work in a team environment, we may have a code review and pull request process which might have different behavior (code coverage report, static code analysis report, etc&#8230;) than the main build and deploy pipeline (which might actually deploy our code into a production environment).<\/p>\n\n\n\n<p>In the following steps, I&#8217;m going to be building docker images as part of my feature branch pipeline, so that I can pull an image down and deploy manually (or automatically) as part of &#8216;acceptance testing&#8217;.  However, you may choose a different process.  Having the flexibility to implement your own pipeline is important, but just as important is understanding how they work so that you actually understand the options and implement the process that works for you and your team.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"entry-summary\">\nNow that we have a service we&#8217;re going to start building our&hellip;\n<\/div>\n<div class=\"link-more\"><a href=\"https:\/\/bullyrooks.com\/index.php\/2022\/01\/02\/cloud-kube-build-pipeline-initialization\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &ldquo;Cloud Kube | Build Pipeline Initialization&rdquo;<\/span>&hellip;<\/a><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[77,5,147,50],"course":[149],"class_list":["post-1161","post","type-post","status-publish","format-standard","hentry","category-software-development","tag-cicd","tag-docker","tag-github-actions","tag-maven","course-kubernetes-application-hosted-in-the-cloud","entry"],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":1230,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/01\/23\/kube-cloud-pt2-database-configuration-in-kubernetes\/","url_meta":{"origin":1161,"position":0},"title":"Kube Cloud Pt2 | Database Configuration in Kubernetes","author":"Bullyrook","date":"January 23, 2022","format":false,"excerpt":"We now have an application that will connect to our MongoDB locally, but we'll need to tell it how to connect when its deployed to Okteto. Create Kubernetes Configuration First, create a secret in okteto with the database details. Run this command on your terminal. The uri should look like\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-43.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-43.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-43.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1205,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/01\/04\/kube-cloud-automate-kube-deploy\/","url_meta":{"origin":1161,"position":1},"title":"Kube Cloud | Automate Kube Deploy","author":"Bullyrook","date":"January 4, 2022","format":false,"excerpt":"Lets improve our CD pipeline by automating deployment. Update Build Pipeline I only want main to deploy on successful build. So add these lines to the end of the main.yaml github action workflow - name: Deploy uses: WyriHaximus\/github-action-helm3@v2 with: exec: | helm repo add bullyrooks https:\/\/bullyrooks.github.io\/helm-charts\/ helm repo update helm\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-36.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-36.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-36.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":1169,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/01\/04\/cloud-kube-docker-build-and-registry\/","url_meta":{"origin":1161,"position":2},"title":"Cloud Kube | Docker Build and Registry","author":"Bullyrook","date":"January 4, 2022","format":false,"excerpt":"Now that we've got a pipeline, we're going to start working on deploying our service into the cloud. The first step is to create a docker image and store it somewhere that our pipeline as well as our cloud provider can access. Create a Docker Image Registry Canister.io provides a\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-19.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1115,"url":"https:\/\/bullyrooks.com\/index.php\/2021\/07\/24\/automated-terraform-deploy-using-github-actions\/","url_meta":{"origin":1161,"position":3},"title":"Automated Terraform Deploy Using Github Actions","author":"Bullyrook","date":"July 24, 2021","format":false,"excerpt":"Now we just need to build and deploy our application automatically so that whenever we push changes to the main branch, they'll automatically become available through our endpoint. Create Our Artifact Storage We're going to use a 'poor man's artifactory' to store our compiled .jar files. With our current build\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2021\/07\/image-34.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1153,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/01\/02\/cloud-kube-simple-rest-endpoint-and-test\/","url_meta":{"origin":1161,"position":4},"title":"Cloud Kube | Simple REST Endpoint and Test","author":"Bullyrook","date":"January 2, 2022","format":false,"excerpt":"In the previous article we created the skeleton repo and project. In this article we'll be building a very basic endpoint and component test. Although I do hate hello world examples my intent is to get us to a point where we can focus on the build and deploy path.\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-11.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1176,"url":"https:\/\/bullyrooks.com\/index.php\/2022\/01\/04\/cloud-kube-helm-initialization-and-chart-publishing\/","url_meta":{"origin":1161,"position":5},"title":"Cloud Kube | Helm Initialization and Chart Publishing","author":"Bullyrook","date":"January 4, 2022","format":false,"excerpt":"Now that we're producing versioned docker images into our registry lets get helm setup and publish versioned charts. This will allow us to deploy fully configured services into kubernetes. Helm Init I'm assuming that helm is already installed in your development environment, so I'm not going to cover installing it.\u2026","rel":"","context":"In &quot;Software Development&quot;","block_context":{"text":"Software Development","link":"https:\/\/bullyrooks.com\/index.php\/category\/software-development\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-25.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-25.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/bullyrooks.com\/wp-content\/uploads\/2022\/01\/image-25.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/comments?post=1161"}],"version-history":[{"count":5,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1161\/revisions"}],"predecessor-version":[{"id":1214,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/posts\/1161\/revisions\/1214"}],"wp:attachment":[{"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/media?parent=1161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/categories?post=1161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/tags?post=1161"},{"taxonomy":"course","embeddable":true,"href":"https:\/\/bullyrooks.com\/index.php\/wp-json\/wp\/v2\/course?post=1161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}