<metaproperty="og:title"content="How I Created My Homepage (for free) Using Docker, Hugo, and Firebase"/>
<metaproperty="og:description"content="Currently, there are several solutions to build and host your personal website. I wanted to challenge myself to see if I could do it with the same set of features as some of the paid solutions out there and for free. Here are the results."/>
<metaname="twitter:title"content="How I Created My Homepage (for free) Using Docker, Hugo, and Firebase"/>
<metaname="twitter:description"content="Currently, there are several solutions to build and host your personal website. I wanted to challenge myself to see if I could do it with the same set of features as some of the paid solutions out there and for free. Here are the results."/>
<scripttype="application/ld+json">
[{
"@context": "https://schema.org",
"@type": "Article",
"articleSection": "Posts",
"name": "How I Created My Homepage (for free) Using Docker, Hugo, and Firebase",
"headline": "How I Created My Homepage (for free) Using Docker, Hugo, and Firebase",
"description": "Currently, there are several solutions to build and host your personal website. I wanted to challenge myself to see if I could do it with the same set of features as some of the paid solutions out there and for free. Here are the results.",
"abstract": "Currently, there are several solutions to build and host your personal website. I wanted to challenge myself to see if I could do it with the same set of features as some of the paid solutions out there and for free. Here are the results.",
<p>Currently, there are several solutions to build and host your personal website. I wanted to challenge myself to see if I could do it with the same set of features as some of the paid solutions out there and for free. Here are the results.</p>
<h2id="why-would-a-pm-build-their-own-homepage-from-scratch"class="relative group">Why would a PM build their own homepage from scratch… <spanclass="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100"><aclass="group-hover:text-primary-300 dark:group-hover:text-neutral-700"style="text-decoration-line: none !important;"href="#why-would-a-pm-build-their-own-homepage-from-scratch"aria-label="Anchor">#</a></span></h2>
<p>A couple of months ago I decided that I wanted to start writing more in order to a) exercise my writing skills and b) get feedback on some of my ideas. With this goal in mind, I started researching tools/platforms that would help me publish without creating too much friction for me, or for the people wanting to read what I have to say e.g. having to pay. Ultimately I decided upon creating my own website.</p>
<p>I had a couple of reasons for wanting to try this:</p>
<ul>
<li>
<p>challenge me to see if I, a previous software engineering student, could still bodge something together that would work and feel good about not having forgotten everything I ever learned about programming,</p>
</li>
<li>
<p>find a flexible free solution that would allow me to kickstart my website without investing money right away into it, aka avoiding operational costs with platforms and services that would lock me in the future,</p>
</li>
<li>
<p>have my content hosted in a place that will not require people to pay for reading it,</p>
</li>
<li>
<p>play around with <atarget="_blank"href="https://docs.docker.com/desktop/dev-environments/">Docker’s developer environments</a> and <atarget="_blank"href="https://github.com/microsoft/vscode-dev-containers">Microsoft’s developer containers</a> to get myself familiar with both solutions.</p>
<p>After some research, I decided to choose a website generator framework and a free hosting service. For the website framework, I choose <atarget="_blank"href="https://gohugo.io">Hugo</a> with <atarget="_blank"href="https://github.com/jpanther/congoand">Congo</a> as the theme, and for the hosting service <atarget="_blank"href="https://firebase.google.com">Firebase</a>. And for obvious reasons, I decided to set up my development environment using <atarget="_blank"href="https://www.docker.com">Docker</a> in order to put myself in the user’s shoes for this experiment.</p>
<p>I didn’t go into a deep analysis of which framework was the best for my problem as I wanted to get an MVP out fast so I went through a couple of options and picked the first one that I liked. There are several other options with different features and approaches from the one I picked. If you want to explore other options these are some you can explore: <atarget="_blank"href="https://docusaurus.io/">Docussaurus</a>, <atarget="_blank"href="https://www.gatsbyjs.com/">Gatsby</a>, <atarget="_blank"href="https://jekyllrb.com/">Jekyll</a>, <atarget="_blank"href="https://ghost.org/">Ghost</a>, and even <atarget="_blank"href="https://wordpress.com/">WordPress</a>. The same is applicable to the hosting part, even though I chose <atarget="_blank"href="https://firebase.google.com/">Firebase</a> there are other solutions like <atarget="_blank"href="https://pages.cloudflare.com/">Cloudflare Pages</a>, <atarget="_blank"href="https://pages.github.com/">GitHub Pages</a>, <atarget="_blank"href="https://www.digitalocean.com/">Digital Ocean</a>, <atarget="_blank"href="https://www.netlify.com/">Netlify</a>, <atarget="_blank"href="https://vercel.com/">Vercel</a>, and others that you might consider exploring. If you have any suggestions for this guide feel free to reach out, always happy to chat and learn.</p>
<p>For this guide, I will use the following tools, which should be installed on your machine. Here is a small explanation of what each component is going to be used for and a link to the installation instructions.</p>
<ul>
<li>
<p><strong>Docker</strong> - I will use Docker to configure a development environment for this project so that we can skip the need to install all the software required to run Hugo and Firebase CLI i.e. cURL, Go, Hugo, Node, NPM, etc. This will allow you to start from a git repository, start the environment and go straight into writing code instead of spending hours figuring out how to install a specific compiler for your CPU architecture. <atarget="_blank"href="https://www.docker.com/get-started/">Install Docker</a></p>
</li>
<li>
<p><strong>Visual Studio Code</strong> - I’m using Visual Studio Code as my code editor at the moment, and all the material in the guide assumes that this is what you’re using. If you have a different preference you’ll need to adapt some parts of this guide to achieve the same results. <atarget=”_blank”href="https://code.visualstudio.com/">Install Visual Studio Code</a></p>
</li>
</ul>
<h2id="setup-the-development-environment"class="relative group">Setup the Development Environment <spanclass="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100"><aclass="group-hover:text-primary-300 dark:group-hover:text-neutral-700"style="text-decoration-line: none !important;"href="#setup-the-development-environment"aria-label="Anchor">#</a></span></h2>
<p>Let’s start by configuring your development environment using <atarget="_blank"href="https://www.docker.com">Docker</a>. This will allow you to create a container with all the tools you need inside of it without having to mess with your system configurations. Moreover, it will also make it easier to just delete the container and rebuild it whenever you need it instead of keeping old versions of software you don’t require daily in your personal machine.</p>
<spanclass="dark:text-neutral-300">Note: If you just want to clone a repo with the final skeleton feel free to clone <atarget="_blank"href="https://github.com/nunocoracao/homepage-hugo-congo">this repo</a> and skip to the deploy section</span>
</div>
<p>I’ll provide two ways of setting up your development environment feel free to choose the one you prefer or try both to explore the differences between them. Both options rely on a <code>Dockerfile</code> built by me which uses <code>klakegg/hugo:0.93.2-ubuntu</code> as the base image, even though this is not Hugo’s official image (since there isn’t one at the moment) it’s the one <atarget="_blank"href="https://gohugo.io/getting-started/installing/#docker">recommended on their website,</a>.</p>
<p>To spin up a Dev Environment just open Docker Dashboard and select the “Dev Environments” tab on the left. If you don’t have any dev environments setup select “Create New Environment” otherwise use the button on the upper right side “Create”. Proceed to the setup step.</p>
<imgsrc="devenvs/step2.png"/>
<p>Here choose the “Existing Git repo” option and use the following GitHub URL:</p>
<p>In both situations, you will be able to see and click the button “Open in VSCode” which will open the editor and will allow you to start working. From there open a terminal and proceed to <ahref="#create-site-skeleton">create the site skeleton</a></p>
</code></pre><p>This method requires the installation of an extra VSCode extension in order to spin up the containers. Please search for <strong>Remote - Containers</strong> and install the extension to continue this guide.</p>
<p>After successfully installing the extension, open your source folder in VSCode and open the “Remote - Containers” extension panel on the left. Select “Open Folder in Container” to spin up a container with the development environment.</p>
<imgsrc="setup/extension.png"/>
<p>Wait a couple of minutes while the image is built. Docker is creating an image with all the required software for the development of the website. This will only happen the first time you spin the environment.</p>
<imgsrc="setup/imagebuild.png"/>
<p>Once the image is built, VSCode will spin the container and will place your working environment inside of it (information available in the bottom left corner of the window). You now have a development environment with Go, Hugo, Firebase CLI, and all the tools you will need for this guide. Just open a new terminal and you’re ready to begin creating your site.</p>
<imgsrc="setup/newterminal.png"/>
<h3id="but-i-really-want-to-run-everything-locally"class="relative group">…but I really want to run everything locally <spanclass="absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100"><aclass="group-hover:text-primary-300 dark:group-hover:text-neutral-700"style="text-decoration-line: none !important;"href="#but-i-really-want-to-run-everything-locally"aria-label="Anchor">#</a></span></h3>
<p>If you either prefer or need to run your environment locally follow the guides below to install everything you need for your setup:</p>
<p>Now that we have a development environment running the first step is to create the base version of your website. For this let’s use <strong>Hugo</strong> to generate the folder template and configuration files we need by running the following command (<code>--force</code> parameter is required to run Hugo on a non-empty directory):</p>
<pretabindex="0"><code>hugo new site . --force
</code></pre><p>This should have created a set of folders inside your workspace that you don’t need to worry about for now. The next step is to install a theme for Hugo. I choose <atarget="_blank"href="https://github.com/jpanther/congo">Congo</a> as it had all the features I required for my website and it seemed to be easy to change if I ever need it to. If you want to try a different theme there are several available in Hugo’s documentation, each with documentation and examples.</p>
<p>Install Congo using git submodules by running the following command:</p>
</code></pre><p>Now we need to make some changes to the directory and file structure so that Congo can work properly. I will not get into the details of what is happening in this guide (you can consult Congo’s documentation if you want to learn more), the main takeaway is that we’re creating and configuring a folder in <code>config/_default/</code> which will contain all the important configuration files for Hugo and Congo.</p>
<p>Please run the following commands in order:</p>
</code></pre><p>Congratulations, you should have your site up and running now. Let’s try it out by running Hugo’s debug server:</p>
<pretabindex="0"><code>hugo server -D
</code></pre><p>Please open your favorite browser and navigate to <atarget="_blank"href="http://localhost:1313">localhost:1313</a> to see your page.</p>
<imgsrc="theme/vanilla.png"/>
<p>You should see something similar to the image above. Doesn’t look that exciting, does it? Let’s configure the theme in the next sections and learn how to create your first article.</p>
<p>Now I’ll be covering how to change the look and feel of your website, add some personal information, and activate the dark mode toggle (aka the most important feature in any website these days).</p>
<spanclass="dark:text-neutral-300">A note, I am covering a very simple configuration for this theme please check <atarget="_blank"href="https://jpanther.github.io/congo/docs/">Congo’s theme documentation</a> to understand everything you can do with this theme.</span>
<p>Let’s start by adding a profile picture to your site. Create a folder called “assets” at the root of your project. Choose a profile picture and place it inside the assets folder. The rest of the guide will assume the final picture is named “profile.jpg”, so please rename your picture or take that into account when configuring some of the other files.</p>
<figure>
<imgsrc="configure/profile.jpg"/>
<figcaption>If you still need to take a proper awesome picture for this feel free to download this one to proceed with the tutorial.</figcaption>
<p>Let’s open a couple of configuration files and start updating them. All the files we are going to change are inside <code>config/_default/</code> folder.</p>
<p>Uncomment the <code>baseURL</code> parameter and replace it with the final domain of your website. This value will be used to create the robots.txt file for any search engines to successfully crawl and index your website.</p>
<spanclass="dark:text-neutral-300">Note: if you want to configure Google Analytics please add the following line with your id to this file <code>googleAnalytics = "G-XXXXXX"</code></span>
<p>This file will drive the main information for the website and the author of the page (you). Replace the <code>title</code> and <code>description</code> for the ones you want for your page, these values will drive the HTML title and description tags.</p>
<p>Within the <code>[author]</code> block you can update the details that you wish to highlight in your profile. The bare minimum would be <code>name</code>, <code>image</code>, <code>headline</code>, and <code>links</code>. For the <code>links</code> parameter don’t forget to uncomment the last line of the file as this is a json array. Update each entry with your personal links.</p>
<p>This file defines much of the overall behavior across the entire framework. For this tutorial I changed some of the overall values and one for the homepage, if you want to learn more about the other available configurations please consult <atarget="_blank"href="https://jpanther.github.io/congo/docs/">Congo’s theme documentation</a>.</p>
<p>I’ve changed <code>colorScheme</code> to “ocean” which changes the global UI theme. Congo defines a three-color palette that is used throughout the theme. Valid values are congo (default), avocado, ocean, fire, and slate. Although these are the default schemes, you can also create your own. Refer to the theme’s main documentation to learn how.</p>
<p>Activated <code>showAppearanceSwitcher</code> to enable the light/dark mode toggle. Activated <code>enableSearch</code> which indexes all future posts each time you build the site and provides a simple search feature. I’ve also changed the value of <code>layout</code>, inside <code>[homepage]</code>, to “profile” which changes the way the landing page is rendered. Finally, the last interesting value here is <code>showRecent</code>, which when turned on shows the recent posts on the homepage.</p>
<p>Let’s see how it looks, run the Hugo again:</p>
<pretabindex="0"><code>hugo server -D
</code></pre><p>And navigate to <atarget="_blank"href="http://localhost:1313">localhost:1313</a> you should see something similar to the page below.</p>
<p>Hugo provides some tools to generate your articles (<atarget="_blank"href="https://www.markdownguide.org/">markdown</a> files) with a base set of tags already in them. Run the following command to create your first post</p>
<pretabindex="0"><code>hugo new posts/my-first-post.md
</code></pre><p>replace the contents of the file with the following:</p>
<pretabindex="0"><code>---
title: "My Published Post"
date: 2022-06-19T20:10:29Z
draft: false
categories: ["published", "test"]
tags: ["first", "awesome"]
---
This is my first blog post
</code></pre><p>This just created your first blog post. We’ve added a couple of categories and tags, which will be indexed by Hugo during build time. These tags will be used to create the Categories and Tags section of the website automatically for you. Notice that I’ve changed the <code>draft</code> to false to simulate a published post.</p>
<p>Run the following command to create your second post</p>
<pretabindex="0"><code>hugo new posts/my-draft-post.md
</code></pre><p>and replace the contents of that file with the following:</p>
</span></span><spanclass="line"><spanclass="cl">This is my second blog post
</span></span></code></pre></div><p>For the second post, I’ve left the <code>draft</code> parameter true to simulate a draft post.</p>
<p>Hugo automatically hides draft posts from the final site generation. You can keep working on articles leaving the draft label true and they will be ignored by the engine. If you want to run in DEBUG mode just use the command:</p>
<pretabindex="0"><code>hugo server -D
</code></pre><p>If you go to the posts on the site you should be able to see both entries. If you then run the server in normal mode the draft articles will disappear. You can use the command below to do so:</p>
<pretabindex="0"><code>hugo server
</code></pre><p>You can use this command to test the final version of the website or an article before generating the final build. When you’re ready just use the command ‘Hugo’ to generate the final website inside the /public folder.</p>
<pretabindex="0"><code>hugo
</code></pre><p>All files are written in <atarget="_blank"href="https://en.wikipedia.org/wiki/Markdown">Markdown</a> which Hugo then uses to generate the final pages. I’ll not teach you how to write markdown files in this guide but I can recommend this <atarget="_blank"href="https://www.markdownguide.org/getting-started/">“getting started”</a> tutorial and this <atarget="_blank"href="https://www.markdownguide.org/cheat-sheet/">“cheat sheet”</a> to get you started.</p>
<p>Ok, you’ve configured your website and created a couple of articles, but we still need to deploy it somewhere. As I mentioned before I chose Firebase for this guide, even though I know that it offers much more than just a simple hosting service it allows me to host my site for free without much of a hassle.</p>
<p>Let’s start by going to <atarget="_blank"href="https://firebase.google.com"><ahref="https://firebase.google.com">https://firebase.google.com</a></a> and creating an account. Once that is done you can create a project for free. The process should be straightforward and when you finish you should be in Firebase’s project dashboard.</p>
<p>Now you can go back to your environment which already has Firebase CLI tools installed and ready to go. Let’s start by authenticating using:</p>
<pretabindex="0"><code>firebase login
</code></pre><p>Once you are successfully logged in you need to initiate the project configurations for firebase. For that please use:</p>
<pretabindex="0"><code>firebase init
</code></pre><p>The tool will offer you a wide variety of different options in order to configure your Firebase project. For now, we just want to configure hosting. If you are using GitHub, you might want to consider configuring GitHub action deploys which can automatically build and deploy your site every time there is a push to a specific branch or a merged pull request.</p>
<imgsrc="deploy/firebasehosting.png"/>
<p>Choose the Firebase project created before as the hosting destination. And select the configurations you wish for the deployment process. The important one here is the folder where the final files to the server will be placed and this is the <code>public</code> folder. For the other parameters you experiment with what better matches your use-case, the image below shows you what I picked (<em>Note: for this tutorial I didn’t configure GitHub actions but I am using that in my real setup</em>).</p>
<p>Ok, now for the long and boring process of deployment… joking! Once you are ready and have all your files generated by the <code>hugo</code> command in the public folder just use the following command to deploy:</p>
<p>The process should take a couple of seconds and there you go your site is deployed. The final line of the CLI tool will give you a URL to see for yourself, otherwise, you can explore your Firebase dashboard hosting section which will have more information regarding the deployment.</p>
<p>By now you should have a simple version of your website which you can configure to your needs. The main advantage of this solution is that it is flexible and extensible to a variety of different needs especially if you take the time to explore Hugo’s theme catalog. True that it might require some coding to implement complex but I would guess that this solves the problem for almost everyone.</p>
<p>Above all, it’s a completely free solution if you’re looking to start and can’t (or don’t want to) spend money. Hope this guide helps you, feel free to share it with your network and give me feedback so that I can make it better over time.</p>