<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Gokula Krishna</title>
    <description>The latest articles on Forem by Gokula Krishna (@gokuladev).</description>
    <link>https://forem.com/gokuladev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F408676%2F6f425dc6-d1c9-4438-86a8-dc18172e597a.jpg</url>
      <title>Forem: Gokula Krishna</title>
      <link>https://forem.com/gokuladev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gokuladev"/>
    <language>en</language>
    <item>
      <title>Guide to setup your first blog with Continuous Deployments pipeline </title>
      <dc:creator>Gokula Krishna</dc:creator>
      <pubDate>Sun, 14 Jun 2020 11:12:39 +0000</pubDate>
      <link>https://forem.com/gokuladev/guide-to-setup-your-first-blog-with-continuous-deployments-pipeline-cop</link>
      <guid>https://forem.com/gokuladev/guide-to-setup-your-first-blog-with-continuous-deployments-pipeline-cop</guid>
      <description>&lt;h2&gt;
  
  
  What is Hexo?
&lt;/h2&gt;

&lt;p&gt;Hexo is one of the simplest blogging platforms. This blog powered by Hexo. It allows you to create your blog with a very minimal setup. Hexo is developed using the NodeJS environment. It has a lot of plugins and themes to make your blogging simpler.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Continuous Delivery?
&lt;/h2&gt;

&lt;p&gt;Continuous delivery is a concept where a Website or an App's content is updated instantly without any manual intervention. In this tutorial, I'll cover how that automation works and how you can expand on top of this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;You should be familiar with working on the terminal, NodeJS, and git.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project setup
&lt;/h2&gt;

&lt;p&gt;Let's start to use Hexo, it is as simple as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;goku:~&lt;span class="nv"&gt;$ &lt;/span&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;hexo-cli &lt;span class="nt"&gt;-g&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can refer the documentation &lt;a href="https://hexo.io/docs"&gt;https://hexo.io/docs/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once that is done, let's set up an Hexo project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;goku:~&lt;span class="nv"&gt;$ &lt;/span&gt;hexo init continuous-deployment-basics/
goku:~&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;continuous-deployment-basics/
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;hexo serve &lt;span class="nt"&gt;-p&lt;/span&gt; 8080
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Initialize an Hexo project on that new folder.&lt;/li&gt;
&lt;li&gt;Makes this new project's folder as the current directory.&lt;/li&gt;
&lt;li&gt;Start Hexo in development mode.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In your browser, you can check &lt;a href="http://localhost:8080"&gt;http://localhost:8080&lt;/a&gt; and see your blog.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5QEqMXyt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5QEqMXyt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-1.png" alt="localhost"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once confirmed, create a new repository (mine is &lt;code&gt;gokula-krishna-dev/continuous-deployment-basics&lt;/code&gt; ) and initialize a git repository in local.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git init
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git remote add origin git@github.com:&amp;lt;Your user ID&amp;gt;/&amp;lt;Your repo ID&amp;gt;.git
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git pull origin master
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-am&lt;/span&gt; &lt;span class="s2"&gt;"Hexo init"&lt;/span&gt;
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git push &lt;span class="nt"&gt;--set-upstream&lt;/span&gt; origin master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Initialize a new git repository.&lt;/li&gt;
&lt;li&gt;Link the current repository to your GitHub. I use SSH to communicate with my repo. You can also use HTTPS communication.&lt;/li&gt;
&lt;li&gt;Download remote contents from git to the local folder.&lt;/li&gt;
&lt;li&gt;Add Hexo files to the git watch list.&lt;/li&gt;
&lt;li&gt;Commit all files to the repo.&lt;/li&gt;
&lt;li&gt;Upload all contents from the local folder to Github.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Local Deployment
&lt;/h2&gt;

&lt;p&gt;Before we do an automated deployment we have to understand the Hexo tool and do a manual deployment. It can be done using the following commands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;hexo generate
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;public/
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;open index.html
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Generate HTML files for the project.&lt;/li&gt;
&lt;li&gt;Switch the directory to public.&lt;/li&gt;
&lt;li&gt;Open index.html.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wbiz63t---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wbiz63t---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-2.png" alt="Manual deployment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But where did the theme and layout go?&lt;/p&gt;

&lt;p&gt;Hexo expects us to run it on a webserver. Either you can copy the contents of the public and host it using Nginx or apache or run hexo serve to view the full site locally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Manual deployment:
&lt;/h2&gt;

&lt;p&gt;To develop an effective Continuous deployment pipeline, you must understand how manual deployment works. Let us host our first blog.&lt;/p&gt;

&lt;p&gt;Open the file &lt;code&gt;continuous-deployment-basics/_config.yml&lt;/code&gt; and modify the following line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://gokula-krishna-dev.github.io/continuous-deployment-basics&lt;/span&gt;
&lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/continuous-deployment-basics/&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once that is done do a commit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-am&lt;/span&gt; &lt;span class="s2"&gt;"Update website config"&lt;/span&gt;
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Hosting using gh-pages
&lt;/h2&gt;

&lt;p&gt;gh-pages is a branch that is used to host free sites.&lt;/p&gt;

&lt;p&gt;Open file &lt;code&gt;continuous-deployment-basics/.gitignore&lt;/code&gt; and remove the following line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Let's deploy to gh-pages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;hexo generate
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git stash
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git stash branch gh-pages stash@&lt;span class="o"&gt;{&lt;/span&gt;0&lt;span class="o"&gt;}&lt;/span&gt;
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; &lt;span class="o"&gt;!(&lt;/span&gt;&lt;span class="s2"&gt;"public"&lt;/span&gt;|&lt;span class="s2"&gt;".git"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mv &lt;/span&gt;public/&lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; public/
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git commit &lt;span class="nt"&gt;-am&lt;/span&gt; &lt;span class="s2"&gt;"My site"&lt;/span&gt;
goku:~/continuous-deployment-basics&lt;span class="nv"&gt;$ &lt;/span&gt;git push origin gh-pages
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Generate our site again.&lt;/li&gt;
&lt;li&gt;Copy all the contents from the public folder to a temporary store in git.&lt;/li&gt;
&lt;li&gt;Create a gh-pages branch from the temporary store.&lt;/li&gt;
&lt;li&gt;Copy site contents to root folder.&lt;/li&gt;
&lt;li&gt;Remove files that cause issues with gh-pages templates.&lt;/li&gt;
&lt;li&gt;Add all files to track.&lt;/li&gt;
&lt;li&gt;Commit the changes.&lt;/li&gt;
&lt;li&gt;Push it to Github.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you can see it is quite a bit of heavy lifting to deploy the resource. This process has to be generated whenever you have to publish it to your blog. But luckily with the help of CI/CD tools like Travis CI and Circle CI we can now publish our blog quite often. It is very simple to set up. The idea is to set up a reliable system when we don't have to worry about doing these manual steps every time. This is achieved when is a new content merged to our git we automatically publish the changes without worrying.&lt;/p&gt;

&lt;p&gt;Once that is done you can access your blog using the following format. It may take some to for the changes to reflect.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://&amp;lt;github username&amp;gt;.github.io/continuous-deployment-basics&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;In my case the URL is &lt;a href="https://gokula-krishna-dev.github.io/continuous-deployment-basics"&gt;https://gokula-krishna-dev.github.io/continuous-deployment-basics/.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qtBT-e6K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qtBT-e6K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-3.png" alt="Deployed to web"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Congrats! You have launched your first blog.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuous deployments
&lt;/h2&gt;

&lt;p&gt;Now we have set up a site with manual deployment. The next step is to do the process automatically with a trigger. The trigger's usual trigger is when the PR is merged.&lt;/p&gt;

&lt;p&gt;Register with Travis CI using your GitHub account.&lt;/p&gt;

&lt;p&gt;Goto the following URL &lt;a href="https://travis-ci.org/account/repositories"&gt;https://travis-ci.org/account/repositories&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Activate CI for your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RpNiX5PU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RpNiX5PU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-4.png" alt="Travis CI permission"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Go to &lt;a href="https://github.com/settings/tokens"&gt;https://github.com/settings/tokens&lt;/a&gt; and generate a token with the following access.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Mevq6XOn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Mevq6XOn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.gokulakrishna.com/img/blog-1/cd-5.png" alt="GitHub permissions"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node_js&lt;/span&gt;
&lt;span class="na"&gt;node_js&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="m"&gt;8&lt;/span&gt;
&lt;span class="na"&gt;before_install&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm install -g hexo-cli&lt;/span&gt;
&lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;hexo generate&lt;/span&gt;
&lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;provider&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pages&lt;/span&gt;
  &lt;span class="na"&gt;skip_cleanup&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;github_token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;$GITHUB_TOKEN&lt;/span&gt;
  &lt;span class="na"&gt;local_dir&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;public/&lt;/span&gt;
  &lt;span class="na"&gt;keep_history&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="no"&gt;true&lt;/span&gt;
  &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;master&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Explanation
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;language&lt;/code&gt; lets Travis CI know that we are using NodeJS app.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;node_js&lt;/code&gt; specifies NodeJS version.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;before_install&lt;/code&gt; makes sure that we have hexo installed before building.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;script&lt;/code&gt; builds the project.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;deploy&lt;/code&gt; will deploy the generated files to gh-pages.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now every time you update and push the code to Github contents will be updated to your site immediately without any manual intervention.&lt;/p&gt;

</description>
      <category>devops</category>
      <category>tutorial</category>
      <category>opensource</category>
      <category>github</category>
    </item>
  </channel>
</rss>
