Files
MyPlaygroundBlog/content/posts/hello-world.md
Carl Tibule 9739be540e
All checks were successful
ci/woodpecker/push/build Pipeline was successful
Removed test posts, publishing first post
2024-08-25 22:35:28 -05:00

61 lines
7.2 KiB
Markdown

+++
title = 'Hello World'
date = 2024-08-25T21:18:00-05:00
tags = ["homelab"]
+++
If you're seeing this message, this means I have finally gotten around to successfully setting up my very own, self-hosted Blog site. Ever since I've started my journey in tech, I've always wanted some sort of journal to document my journey and also record any mental notes I might have. I've explored the possibility of opening up an account with WordPress, or even Blogger.com (what a classic!) but as time goes on I've become increasingly uncomfortable with my data being at the hands of some other corporate entity. At the same time, my level of skill and confidence in self-hosting my own services has led me to opt into hosting my own blog instead!
You might be asking, what are you using to create your site and how did you choose them? First off, I went about choosing my platform the same way I start any other research when it comes to spinning up a new service: by visiting [awesome-selfhosted](https://github.com/awesome-selfhosted/awesome-selfhosted)! This page contains tremendous amounts of services you can self-host, broken down into categories. I'm astounded by the sheer amount of apps that people just put out there for free to be used by anybody.
## The hunt for a blogging platform
At first, I took a look at Ghost. I was filtered by it though as I had trouble at first finding out how I can self-host it instead of signing up for their subscription plans. Taking a closer look at it, it seems to have some great features like monetization. But for the time being, I have no intention of doing that. There's also added complications of it needing to have a dabatase backend. Not the end of the world, as I'm already running a MariaDB and a Postgres instance to support several self-hosted apps of mine, but for something that'll just be static content of my ramblings, I decided to keep looking and see if there's more in the horizon.
One of the things I've considered is just leveraging my DokuWiki instance and publish a section there of my blog posts. But while I love its simplicity (it's all just text files), I could not get around its ugly UI and the fact that it uses its own syntax instead of just Markdown, which I'm more familiar with. Both could very well be solved with the help of plugins, but I opted to keep looking instead.
And so...I was served [this video](https://youtu.be/LIFvgrRxdt4?si=LdvX29_gyr0VCUuJ) by the YouTube algorithm. A simple, 10 minute overview on Hugo and how it works and it seems to have ticked all my boxes. Markdown syntax? :white_check_mark:, No database backends required? :white_check_mark:, extensive library of themes (I hate web design)? :white_check_mark:. I downloaded it, picked my theme, wrote a couple of test pages and tried out their tags feature (also a must have for me!), and voila! My perfect blogging platform.
## The setup
And so the next question is...how can I automate deployment of this thing? When evaluating which platform I wanted to go for, I originally thought it'd just be an app I'll log on to, hit the Publish button and it'll just show up. But now that I've opted to use a static site generator instead (at least for the time being), I'll need to do some extra steps so get my ramblings from my head onto my servers for it to be hosted.
Thankfully, 1/2 of the battle's already been won. I could've just as easily hosted this blog on GitHub, follow the video I linked and call it a day. But in my journey to try and self-host as much of the services I use as possible, I've instead decided to leverage my existing Gitea + Woodpecker setup (I'll talk about this in more detail in a future post). I was originally just going to host an Nginx web server container in one of my existing servers, map the location where it'll serve the static files from onto somewhere in the VM and then create an SMB share off of it. Then I'll have Woodpecker deploy the static files onto those shares and that's that
What was I thinking right?! Sounds like a pain in the rear. Last thing I need is setting up Samba, which while I absolutely love using is also something I'm still struggling to manage because of permission issues I still run into from time to time. Then, in case I have to migrate off of my current VM for whatever reason, I'll have to do the same thing over again. Nope!
Then a light bulb suddenly turned on....Nginx is already a container! I could just have the Dockerfile do the building of static files for me, pull down the Nginx container, and copy the static files onto `/usr/share/nginx/html`. Voila! So I wrote this Dockerfile:
```
FROM alpine:latest
RUN apk add --update hugo
FROM nginx:stable-alpine
COPY public /usr/share/nginx/html
EXPOSE 80
```
Ran it locally, worked as expected. Pushed this onto Gitea and let Woodpecker do its thing (my workflow is set to run every push to master)...and failure:
```
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref hp2upydiclehwg70mnzw22xdq::svoa4nq8e22xsg6lkkf9by0rj: "/public": not found
```
While I'm pretty familiar with how to leverage docker to deploy services, I must admit I'm pretty clueless with how to build a docker image myself. I've got no idea why this Dockerfile works locally but not on Woodpecker.
I could try to do some more trial and error on this thing and come to an answer myself. But I've resolved myself to a goal: Successfuly write my first blog post on a self-hosted service and have it be served by the end of this weekend. This particular task of mine has been something I've been putting off for at least 2 years and it cannot wait any longer.
Since I cannot possibly be the first human being to have encountered this issue, I've decided to leverage my developer skills of Googling this exact same problem and lo and behold, [somebody has!](https://medium.com/@lorique/howto-multi-stage-docker-builds-with-hugo-78a53565d567)
I followed the instructions, and worked like a charm!
### A caveat
When I was following the tutorial, Ryan's put a `baseURL` on his `hugo.toml` configuration file. And for his setup, I think that works just fine. I initially followed his lead and put `http://localhost` on mine. However, it breaks all of the links to the site save for those going externally. This is because while I've configured my container to run on port 3000, the links are all configured to look for port 80 (aka: the base url `http://localhost`). Turfing that base URL solved my issue.
## What's next?
I mentioned earlier that I wanted to write my first blog and have it be served by my servers by the end of this weekend. And that's technically still true. But my end goal is to have it be served externally outside of my home network, under my personal domain name. At the time of this writing, I've only managed to have it be served within my local network and I do not have my personal domain name setup properly on Cloudflare to protect my site from any attacks. The next goals would be:
- Deploy a pair of highly-available VMs dedicated to just hosting static sites (yes, there will be more!)
- Migrate this Blog site over there
- Setup my personal domain on Cloudflare, and set it up to point to my reverse proxy, which then points to my HA setup
Stay tuned for that (hoping to get it done sometime this week :crossed_fingers:)!