Dragons & Demons: making your own blog website
Published: 2023-03-24 11:13:22

What's the best about having your own blog website?

Writing whatever you want...
Experimenting...
Doing all the crazy things that come to your mind!

My cute little [baby](https://sorry.domain_renewal_was_too_expensive)...

But what a hell of a ride that was!!

Prelude
-------

I work as a software engineer, python is the language I speak. I thought: *why not to learn django*? Why not to code my website from scratch? I'd have a sandbox to play in. I could do whatever I want.

Did anyone mention that flexibility comes with a price?

The Plan
--------

I've spent a day or two sketching out the basic functionality of the first release. I wanted:

1.  to be able to post something;
2.  comment the posts;
3.  basic feedback system (please use it, I sweat a loooot on it);
4.  notification emails (yeah yeah, I do prenumerate my one blog...);
5.  tag system.

Nothing fancy, just enough to get started. No unnecessary features (yet). Just enough to be able to post.

And later, if I realize that writing is my life's passion, then I'll quit my job, sell the house (which I don't own), leave my wife (which I don't have), buy a van and go to the end of the world where I could stay undisturbed and build the most feature creep rocking website in the world!!!

Django
------

Few desperate weeks went by in the django dungeons. The learning curve was steep as a rock and I'm no mountain goat. I was going through documentation and lots of tutorials, but django has some things going on under the hood. It took time 'til I discovered what's happening behind the scenes and how things are interconnected. Until I finally had a rough idea where I can start debugging when stuff doesn't work (and the stuff constantly doesn't work, especially when you're just starting out).

As silly as it may sound, I didn't think about css in the beginning (uh, what's bootstrap?). So I had to learn that one too so that the website doesn't look terrible. I mean terrible terrible.

Few rough weeks fast forward, I have a working version on my computer. I can write an article. I can comment. I can give myself a banana (and you can too!) I'm proud of myself.

But that sqlite looks suspicious to me, let's google if I should use it.

Migrations
----------

*After a while...*

Right, so google suggests postgresql. Who am I to argue?..

Oh, what about old migrations? Hmm... let's delete them. I can *makemigrations* anytime anyway, so what's the difference?

PS Yep, later I also did the same in my production website. As they say, *no pain, no gain.* Now I'm not deleting migrations anymore.

PPS At this point I didn't know anything about databases. SQL vs NoSQL? DB design? Anomalies? Just write a few lines of python in the model and it works!!

Hosting
-------

Website - check. Database - check. Now let's find where to host my amazing website.

*After a day...*

Shoot, it's expensive.

*After a few days...*

What do you mean I can't host my website on shared hosting?

*Time goes on...*

Yes, I ordered a server from you, but I need admin rights to host my django app. No, I won't use your website builder. Okay, I want my money back.

*...and on...*

Maybe some cloud solution?

*...tick tock...*

What?? How much do you charge for this???

*...and I started wondering...*

Should I just buy a domain and host it on my local pc?

*...and I'm happy I didn't...*

In the end I took [the cheapest VPS I could find](https://www.hostens.com/?affid=2728). It was a great feeling to finally have home for my baby.


Interlude
=========

_I'm at a crucial moment now. Choosing the OS. What do we have here? I had Ubuntu previously on my laptop, let's not be boring choosing the same. Fedora is similar to RHEL which I have for over a year now. Let's not disappoint my future readers. Let's go with Debian. Woohoo, let's learn something new!!!_

Containers
==========

No, I'm not a (total) masochist. I've been working with containers and openshift previously. I'm comfortable with creating Dockerfiles, building images and manipulating containers. Since I've never set up a website on a server, I wanted to make the setup as easily reproducible as possible. Maybe I'll have to reinstall a different OS or change the hosting entirely in the future. After all, it's my first time hanging out here. (innocent rational smile)

Now let's go to the fun part. (crazy devilish smile)

Last year I was working with podman and I adored its daemonless attitude. It spins like magic on my laptop.

Guess what I was doing next week on Debian.

Countless hours spent debugging...

...going through various github dependencies... 

...tickets...

...googling "podman debian kaput"...

One day I was woken up by a song. Birds behind the window were singing: docker docker... What can go worse? I installed docker. No errors. Pulled the images, created database, migrations... No errors. docker compose up -d. No errors. I entered the website: welcome to my blog. Didn't try to spin it on podman ever since.

Not that I'm against podman. Just trying to be pragmatic (as much as it's possible to be pragmatic building a website from scratch).

Oh, I almost forgot to mention the docker images. Let's keep them small. Let's go with alpine base images. One more linux to debug, yippee!

Server Setup
============

Now only a single minor formality is left: adapt django for production. I guess setting DEBUG=False will do it, but let's read more about it.

Boy I was naive...

What's nginx, apache? What's a gunicorn? Wsgi vs asgi? Why are my static files not visible? How is all this related???

...very naive...

I just want it to look and behave the same as on my laptop. Please work, pleaaaaasee woooOOoOOooOork!!!&!$^*%*#&^%#$

Did I just commit my password?

Meanwhile my girlfriend (studying at art school) got a task to create her portfolio website on Wix. She got it running filled with content in... a few days? Nevermind...

Server Setup (yes, still here)
==============================

_Want to receive email notifications on the activity in your blog? Don't want to destroy the F5 on your keyboard? No problem. Avoid spending the whole week reading about SMTP, setting up your personal postfix server, asking your website hosting to allow outbound port 25 and praying that gmail doesn't reject your spam mail ([SPF? DKIM? ARC? DMARC?](https://support.google.com/a/answer/10583557?hl=en&ref_topic=9061731) huh?). Only today is our special offer..._

No,
I'll
Do
It
Myself!

_After one week._

And I did! Oof...

_...after another week setting up iptables..._

Now, where should I store my db backup?

Ansible
=======

Imagine, every time You want to deploy a new version of your website, you repeat the following mantra:

1.  connect to the server,
2.  pull the newest versions of the repositories and images,
3.  backup the DB,
4.  restart containers,
5.  migrate models to DB,
6.  collect static files.

I know, after a few deployments I also got sick of that. So I just automated it with ansible. Simple.

(A confession: doing it took longer than reading this chapter.)

Also I automated the entire server configuration: ssh, install dependencies, iptables, nginx, cron jobs, you name it.

(Another confession: doing it took **much** longer than reading this chapter.)

Interlude 2
===========

_Finally I got the website running...
Wait, what do You mean "connection is not secure"?
Okay, how to get SSL certs?
How to get free SSL certs?
How to get free signed SSL certs, please???_

Wagtail
=======

Done. Finally. Basta. Finito.

Yes, I know you heard it before, but now it's done more than ever. I can post. I can blog. I can become VIRAL!!!

After writing my first article I decided to switch from markdown to wagtail. Is it my fault that it seemed a more comfortable and sustainable option? Instead of adding additional tags and mystical keyboard symbols, I just [WYSIWYG](https://en.wikipedia.org/wiki/WYSIWYG). Can't be too hard integrating a new app anyway, can it?

_Spent a couple of days trying to figure that out._

_Realized I'll need a dedicated week to understand wagtail and adapt my project._

_Waited two months until I could find a week for that._

_Rewrote the whole project in 6 days...
...and laid powerless on the 7th._

Final word
==========

If you made that far, congrats - you just read my 4-5 months journey of creating this blog in just a few minutes.

If I had a _tl;dr_ it'd be:

_If your only aim is to create content such as blog or portfolio, please, PLEASE don't try to make your own website from scratch._

There are various tools to prevent this huge headache. You can use website builders or pre-made templates. If you really want your own domain, you can buy a shared wordpress hosting and have your website running in a day. There's no need to do things the way I did.

Unless you want some adventures.

My aim was not only to have the final product, i.e. a website. I also wanted to learn all that great and interesting stuff. The harder part was that I bit off more than I could comfortably chew. Hence the journey was rough.

If you, like me, want to have your own website built from scratch and at the same time learn all this technology, my advice would be to start as simple as possible. Even much simpler than I aimed at. No django. No CI/CD. Just get the server working. Then secure it. Then create a very simple html page.

Or alternatively, go through various tutorials, learn technologies piece by piece before trying to connect them together. First figure out html and css before trying some framework. First get really comfortable with python before even thinking about django. First go through various django tutorials and simple projects before starting to build something bigger, something consisting of several apps or even reusing open source ones.

Don't go like me.

Don't aim to have a containerized django solution on VPS, deployed by ansible with various integrations as your first project. This will produce more heat than the cooler can handle, your blood vessels will swell, your nerves will sublimate, your head will explode and somebody will have to scratch your synapses off of the walls.

No need for that.

Take baby steps.

Meanwhile, if you want to write, you can use already made blogs. Just register and go. While you're learning new technologies, you can share your insights with the rest of the world. You'll avoid an ever growing _topost_ list which you're planning to address once you finish that one last feature. No, maybe after another feature. Alright, this will definitely be the final one... (true story)

I'm happy I went through it. I'm very grateful I found the source of energy and motivation from some mystical source to continue and finish it (sometimes I did feel like quitting). I wanted to learn all this stuff and I'm happy I did. And now I'm even more motivated to improve the website further, deepen and expand my knowledge. So if you're as curious and eager to learn like me, I invite you to this journey. Just be careful and go slow.

There are barracudas and hammerhead sharks out there.

There are icebergs hanging around.

Public secret: you'll be hitting them all the time. 

Recap
=====

What I thought I will learn:

1.  django

What I actually had to deal with:

1.  alpine linux
2.  ansible
3.  css
4.  database design
5.  debian linux
6.  django
7.  docker
8.  javascript
9.  iptables
10. nginx
11. podman
12. postfix
13. postgreSQL
14. server security
15. ssh
16. SSL
17. wagtail