<?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>DEV Community: vcatalin</title>
    <description>The latest articles on DEV Community by vcatalin (@vcatalin).</description>
    <link>https://dev.to/vcatalin</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%2F351104%2F398f1c71-a02a-4567-806d-11741822d20e.jpg</url>
      <title>DEV Community: vcatalin</title>
      <link>https://dev.to/vcatalin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vcatalin"/>
    <language>en</language>
    <item>
      <title>Continuously deploy a Jekyll generated static site to Firebase with Gitlab in under 6 minutes.</title>
      <dc:creator>vcatalin</dc:creator>
      <pubDate>Sun, 22 Mar 2020 19:02:00 +0000</pubDate>
      <link>https://dev.to/vcatalin/continuously-deploy-a-jekyll-generated-static-site-to-firebase-with-gitlab-in-under-6-minutes-112a</link>
      <guid>https://dev.to/vcatalin/continuously-deploy-a-jekyll-generated-static-site-to-firebase-with-gitlab-in-under-6-minutes-112a</guid>
      <description>&lt;p&gt;There comes a time when a software developer either wants acknowledgement, build an online presence or just show how cool he/she/it is. Myself? I just wanted to give back to the newcomers who seek knowledge, as I once did, and I still do, every time I open a browser or a book.  &lt;/p&gt;

&lt;p&gt;To solve that I decided to create a &lt;a href="https://catalinvasile.dev"&gt;blog&lt;/a&gt;, and there I found Jekyll, a fantastic tool to develop fast, reliable websites. It generates pure HTML, but it can also be integrated with 3rd party tools like Disqus (comment section). Writing content for Jekyll is straight forward: write some markdown, build and check your site, and you’re ready to push.  &lt;/p&gt;

&lt;p&gt;Making the site pretty with CSS is out of the scope of this post and will only focus on getting it deployed to Firebase. I will open-source ‘my design’ if there’s enough interest, but just so you know, I am really bad with everything about front-end.  &lt;/p&gt;

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

&lt;ul&gt;
    &lt;li&gt;&lt;a href="https://code.visualstudio.com/download"&gt;Visual Studio Code (or any 
        other editor)&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="https://git-scm.com/doc"&gt;Git and Bash Knowledge&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="https://jekyllrb.com/"&gt;Jekyll&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="https://firebase.google.com/"&gt;Firebase hosting&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="https://about.gitlab.com/"&gt;Git on Gitlab&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="https://www.npmjs.com/get-npm"&gt;Node.js and npm&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="https://www.docker.com/"&gt;Docker (optional)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The services above are free to use, this very blog uses the same infrastructure. The only difference is that this blog is running on a paid domain name.  &lt;/p&gt;

&lt;p&gt;I chose Firebase as a hosting provider because it provides free SSL and CDN on Google’s servers. Gitlab for versioning because it comes with a pipeline included and its free tier is more than enough. Jekyll because I don’t know anything about JavaScript and Gatsby.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Jekyll
&lt;/h2&gt;

&lt;p&gt;Installing Jekyll and creating your first website is as simple as following their guide &lt;a href="https://jekyllrb.com/docs/"&gt;here&lt;/a&gt;. But if you already have Ruby installed on your machine, even better, just run this one-liner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo gem install jekyll bundler &amp;amp;&amp;amp; jekyll new my-blog &amp;amp;&amp;amp; cd my-blog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To quickly test that everything went well run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bundle exec jekyll serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And access your newly generated website at &lt;code&gt;http://127.0.0.1:4000/&lt;/code&gt;, this is what you're supposed to see in the browser:&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ngqhl5ok--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://catalinvasile.dev/assets/images/jekyll-landing-page.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ngqhl5ok--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://catalinvasile.dev/assets/images/jekyll-landing-page.png" alt="jekyll-landing-page" title="jekyll-landing-page" width="880" height="489"&gt;&lt;/a&gt;&lt;br&gt;
Great! Now that you generated your first static website, we can move on to the next part: Taking it to ‘production’ and making it accessible from the public internet.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Firebase Hosting
&lt;/h2&gt;

&lt;p&gt;So let’s create a Firebase account, for that follow Google’s page &lt;a href="https://firebase.google.com/"&gt;here&lt;/a&gt; and sign up unless you already have a Google account, then you only have to log in.&lt;br&gt;&lt;br&gt;
Continue by creating your first project on the Firebase Console and while waiting for that to be set up, install Node.js and npm as described &lt;a href="https://www.npmjs.com/get-npm"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bHFGrPSl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://catalinvasile.dev/assets/images/firebase-create-project.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bHFGrPSl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://catalinvasile.dev/assets/images/firebase-create-project.png" alt="firebase-project-setup" title="firebase-project-setup" width="880" height="492"&gt;&lt;/a&gt;&lt;br&gt;
Why the need for npm? To deploy to Firebase Hosting we are going to use &lt;em&gt;firebase-tools cli&lt;/em&gt;. Therefore once &lt;em&gt;node&lt;/em&gt; and &lt;em&gt;npm&lt;/em&gt; are installed run &lt;code&gt;npm install -g firebase-tools&lt;/code&gt; within your terminal to install that as well.&lt;br&gt;&lt;br&gt;
After it’s done, you need to give the tool access to your account, so switch to your terminal, change directory to your website’s root and run &lt;code&gt;firebase init&lt;/code&gt;. Select &lt;em&gt;‘Hosting’&lt;/em&gt;, and then select your project. You will now have two new files in your project: &lt;code&gt;firebase.json&lt;/code&gt; and &lt;code&gt;.firebaserc.&lt;/code&gt;&lt;br&gt;&lt;br&gt;
By default, the &lt;em&gt;firebase tool&lt;/em&gt; expects the folder it deploys to be called &lt;strong&gt;public&lt;/strong&gt; whereas Jekyll (by default) builds to &lt;strong&gt;_site&lt;/strong&gt;. To change that we need to open up &lt;code&gt;firebase.json&lt;/code&gt; in Visual Studio Code or any other text editor of your choice, paste in the following and save it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
    "hosting": {
      "public": "_site",
      "ignore": [
        "firebase.json",
        "**/.*"
      ]
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You've reached so far, but guess what? Now you can deploy your generated Jekyll website to Firebase Hosting. All you have to do is run &lt;code&gt;firebase deploy --verbose&lt;/code&gt; in your terminal.  &lt;/p&gt;

&lt;p&gt;The URL to access your newly deployed website on the internet can be found on the project's overview within the &lt;em&gt;Firebase Dashboard&lt;/em&gt;. On the left side of the screen, there’s a &lt;em&gt;Hosting&lt;/em&gt; menu item which will lead to your project's registered domains. If you can't find it, just type in your browser &lt;code&gt;http://&amp;lt;your-project-name&amp;gt;.web.app&lt;/code&gt; which should take you to your newly deployed website.&lt;br&gt;&lt;br&gt;
Now let's deploy every time we create and commit a new post or any other change you push to your Gitlab repository. If you didn't create a Gitlab account yet, you can do it &lt;a href="https://gitlab.com/"&gt;here&lt;/a&gt;.&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Gitlab
&lt;/h2&gt;

&lt;p&gt;Before pushing your generated website to any repository in Gitlab, we need 2 last things: &lt;br&gt;
A &lt;code&gt;$FIREBASE_TOKEN&lt;/code&gt; which grants our CI/CD pipeline access to run the deployment and a file that describes the actions happening on the pipeline.&lt;br&gt;&lt;br&gt;
To get the token run &lt;code&gt;firebase login:ci&lt;/code&gt; at the root of your generated website in your terminal. A successful message would look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔  Success! Use this token to login on a CI server:

1/as4Gqp8rm31xNecDRcD939xpk7g4h2R6fycEwFTqPaw

Example: firebase deploy --token "$FIREBASE_TOKEN"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll set the token as a variable inside the Gitlab repository as seen here:&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--silNIHak--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://catalinvasile.dev/assets/images/gitlab-environment-variable.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--silNIHak--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://catalinvasile.dev/assets/images/gitlab-environment-variable.png" alt="gitlab-environment-variable" title="gitlab-environment" width="880" height="492"&gt;&lt;/a&gt;&lt;br&gt;
For the last part, we will use the &lt;code&gt;$FIREBASE_TOKEN&lt;/code&gt; in our &lt;code&gt;.gitlab-ci.yml&lt;/code&gt;. For that, we need to create the &lt;code&gt;.gitlab-ci.yml&lt;/code&gt; file at the root of the generated website folder, and paste the following content to it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;variables:
  PROJECT_NAME: &amp;lt;your-project-name&amp;gt;
  JEKYLL_ENV: production
stages:
  - deploy

cache:
  paths:
  - vendor/

production:
  stage: deploy
  only:
    - master
  image: catalinvasile/firebase-tools:latest
  script:
    - bundle install --path vendor
    - JEKYLL_ENV=${JEKYLL_ENV} bundle exec jekyll build 
    - firebase use ${PROJECT_NAME} --token $FIREBASE_TOKEN
    - firebase deploy --only hosting -m "Pipe $CI_PIPELINE_ID Build $CI_BUILD_ID" --token $FIREBASE_TOKEN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! All you have left to do is &lt;code&gt;git push&lt;/code&gt; your website to a Gitlab repository. From now on, every time you will write a new post for your website or add any change to your repository, it will trigger a deployment. The changes will be reflected as soon as the pipeline finishes running.&lt;br&gt;&lt;br&gt;
I know that some of the mentioned snippets aren't self-explanatory, but to keep things short enough, without getting into too many details, I left them out on purpose, waiting to be discovered.&lt;br&gt;&lt;br&gt;
Well done 👏! I hope you enjoyed this, as much as I did writing it!&lt;/p&gt;

</description>
      <category>devops</category>
      <category>git</category>
      <category>firebase</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
