{"id":3151,"date":"2021-04-19T08:22:31","date_gmt":"2021-04-19T06:22:31","guid":{"rendered":"https:\/\/inlab.fib.upc.edu\/?p=3151"},"modified":"2023-10-23T17:49:14","modified_gmt":"2023-10-23T15:49:14","slug":"devops-example-how-perform-continuous-deployment","status":"publish","type":"post","link":"https:\/\/inlab.fib.upc.edu\/en\/blog\/devops-example-how-perform-continuous-deployment","title":{"rendered":"DevOps: Example of how to perform a Continuous Deployment"},"content":{"rendered":"<p>Continuous deployment is one of the tools provided by <em>DevOps<\/em> where we as a developer want to control the deployment process of the APP we are developing. Therefore, in this example we start from the assumption that we already have an application &nbsp;(or at least it is under development) and we want this application to be deployed by ourselves and automatically.<\/p>\n<p>When we talk about <em>CD<\/em> around <em>DevOps<\/em> it has two possible meanings:<\/p>\n<ul>\n<li><em>Continuous Delivery<\/em>: the package is built and left ready to be deployed, but the deployment is done manually.<\/li>\n<li><em>Continuous Deployment<\/em>: the deployment is also automated.<\/li>\n<\/ul>\n<p>Before starting with the configuration, it is necessary that we place ourselves in the environment that we have in order to be able to make the deployment. In this case the environment we have is <strong>gitlbab + kubernetes.<\/strong> This environment consists of one around <em>PRE<\/em>&nbsp;and one around <em>PRO<\/em> . In this article we want to explain how to deploy automatically in the ERP environment.<\/p>\n<p>The first thing to do is to request the registration of the service and, once the relevant procedures have been completed, we receive a series of configuration parameters to be added to the gitlab. So we will enter gitlab and the bar on the left go to &nbsp;<em>SETTINGS -&gt; CI\/CD<\/em>.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\" size-full wp-image-3131\" alt=\"\" src=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril1.png\" style=\"width: 960px; height: 258px;\" width=\"960\" height=\"258\" srcset=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril1.png 960w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril1-300x81.png 300w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril1-768x206.png 768w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril1-370x99.png 370w\" sizes=\"(max-width: 960px) 100vw, 960px\" \/><\/p>\n<p>Now we &#8220;<em>expand<\/em>&#8221; the variables and &#8220;<em>add value<\/em>&#8221; and add the values that have been sent to us.<\/p>\n<p><img decoding=\"async\" class=\" size-full wp-image-3134\" alt=\"\" src=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril2.png\" style=\"width: 601px; height: 427px;\" width=\"601\" height=\"427\" srcset=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril2.png 601w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril2-300x213.png 300w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/abril2-370x263.png 370w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/p>\n<p>These values configure where our &#8220;<em>artifactory<\/em>&#8221; is located (place where we will leave&nbsp; the images of our app) and with which user and password we will access.<\/p>\n<p>We also configure&nbsp; <em>API<\/em> &nbsp;and the <em>RUNDECK<\/em> <em>TOKEN<\/em> &nbsp;(console for task automation accessed via <em>API<\/em>).<\/p>\n<p>At this point we have the environment ready to start with the CD. In the case of gitlab everything concerning CI\/CD&nbsp; goes through the configuration file named <strong>.gitlab-*ci.yml<\/strong><\/p>\n<p>A first version of this file will be as follows:<\/p>\n<p><span style=\"font-size:12px;\"><img decoding=\"async\" class=\" size-full wp-image-3137\" alt=\"\" src=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/11.png\" style=\"width: 561px; height: 357px;\" width=\"561\" height=\"357\" srcset=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/11.png 561w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/11-300x191.png 300w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/11-370x235.png 370w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/span><\/p>\n<p>A first version of this file will be the Let&#8217;s note that we define 3 stages (pot, <em>build_*pre and deploy_*pre<\/em>):<\/p>\n<p>In this article we will not refer to the potting stage, since it is about running everything that needs to be done to verify that our app works.<\/p>\n<p>The <em>build_*pre<\/em>el builds the <em>docker<\/em> images of our app (we must have a <em>DOCKERFILE<\/em>&nbsp; file in our repository where we explain how each of the images of the project must be built).<\/p>\n<p>In the case of the example in question, our APP consisted of <em>BD+ API+UI<\/em>. The database as it was docker image by default we didn&#8217;t need to build it therefore the garbage is:<\/p>\n<ul>\n<li>We build the images that we need (<em>API and UI<\/em>).<\/li>\n<li>We authenticate against the <em>arifactory<\/em>.<\/li>\n<li>Let&#8217;s push the images we have created.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Before I go on let me give a brief explanation of how&nbsp; <strong>.gitlab-*ci.ym<\/strong>l works.<\/p>\n<p>We as developers often do: <strong>git push origin master<\/strong> to upload the code to the repository, if we have the <strong>.gitlab-*ci.yml<\/strong> file very configured to each push it will execute the pot stage, but it will not execute the other stages (for not making a CD each time we do a push).<\/p>\n<p>When&nbsp; we decide that we want to make a new image of our app we will have to execute the following commands:<\/p>\n<ul>\n<li><strong><em>git push origin master<\/em><\/strong> (check that we have not broken anything)<\/li>\n<li><strong><em>git tag &lt;num_version&gt;<\/em><\/strong><\/li>\n<li><strong><em>git push \u2013tags <\/em><\/strong><\/li>\n<\/ul>\n<p>This behavior that the <em>build_*pre and deploy_*pre<\/em>&nbsp; stages, which are only done when a tag is garbage, is configured with the following lines &nbsp;within&nbsp; the <em>build_*pre and deploy_*pre<\/em> stages:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-3140\" alt=\"\" src=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/12.png\" style=\"width: 561px; height: 63px;\" width=\"561\" height=\"63\" srcset=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/12.png 561w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/12-300x34.png 300w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/12-370x42.png 370w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/p>\n<p>If we were to end our article here the one we would have done is <em>Contiuos Delvery<\/em>, we have the images about to be deployed, but the deployment would be done manually.<\/p>\n<p>But we want to go further, we want to deploy, so we add in our <strong>.gitlab-*ci.yml<\/strong> in the variable section we add all the following variables:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-3143\" alt=\"\" src=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/13.png\" style=\"width: 561px; height: 119px;\" width=\"561\" height=\"119\" srcset=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/13.png 561w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/13-300x64.png 300w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/13-370x78.png 370w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/p>\n<p>And below the <em>build_*pre<\/em> stage we add <em>deploy_*pre<\/em> stage:<\/p>\n<p><em><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-3146\" alt=\"\" src=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/14.png\" style=\"width: 561px; height: 258px;\" width=\"561\" height=\"258\" srcset=\"https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/14.png 561w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/14-300x138.png 300w, https:\/\/inlab.fib.upc.edu\/wp-content\/uploads\/2021\/04\/14-370x170.png 370w\" sizes=\"(max-width: 561px) 100vw, 561px\" \/><\/em><\/p>\n<p>The garbage with these lines is to take the images from the <em>artifactory<\/em> and copy them to the <em>RUNDECK<\/em> by copying them through &nbsp;<em>API<\/em>, the <em>TOKEN<\/em> and the <em>JOB_*ID<\/em> that we have defined (some things are in the Settings of the <em>gitlab<\/em> and the <em>job<\/em> is in the variables of the .gitlab-*ci.yml file).<\/p>\n<p>If everything has gone well, at this point we can access our APP (to the URL and port where we have defined it) and we will be able to see the <em>logs<\/em> of the <em>APP<\/em> through the <em>kibana<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Continuous deployment is one of the tools provided by DevOps where we as a developer want to control the deployment process of the APP we are developing. Therefore, in this example we start from the assumption that we already have an application &nbsp;(or at least it is under development) and we want this application to [&hellip;]<\/p>\n","protected":false},"author":594,"featured_media":3128,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[572],"tags":[],"experteses":[],"class_list":["post-3151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/posts\/3151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/users\/594"}],"replies":[{"embeddable":true,"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/comments?post=3151"}],"version-history":[{"count":1,"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/posts\/3151\/revisions"}],"predecessor-version":[{"id":26426,"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/posts\/3151\/revisions\/26426"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/media\/3128"}],"wp:attachment":[{"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/media?parent=3151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/categories?post=3151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/tags?post=3151"},{"taxonomy":"experteses","embeddable":true,"href":"https:\/\/inlab.fib.upc.edu\/en\/wp-json\/wp\/v2\/experteses?post=3151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}