How I deploy my site

I am generally a big fan of Continues deployment (CD) systems for production applications. but for a small scale system like this website most of these are far to heavy weight. But I can build a simple solution to do this for me getting most of the same benefits.

Building a script (or some other application) is generally done to speed up the deployments. But this is hardly an issue for me. My main goal here is to automate updating my site as every time I go to do it I have to relearn how I had set it up. So consistency of the deployments is what I am looking for.

Overview

So a couple of notes on how I have this built.

I use pelican to create a static website. So the automation I need to do is to pull down the most resent files, build the html pages, then upload to my VPS.

I store my file in a self hosted Git server (gitea to be exact).

The solution

First I need to create a user on each of these hosts and set up SSH access to both my Git server and my VPS host.

For the initial set up I did need to run the following. (I am running this in an Ubuntu 20.10 LXC container)

# Install dependencies
sudo apt update
apt-get install python3-venv git -y


# Setup Python dependencies

python3 -m pip install "wheel"
python3 -m pip install "pelican"
python3 -m pip install "pelican[markdown]"
python3 -m pip install markdown

After that I can update the site with the following zsh script.

#!/bin/zsh

# update packages
git clone git@gitea.home.invoke.coffee:andrew/pelican.git



# Create venv
python3 -m venv pelican/
cd pelican
source bin/activate
python3 -m pip install "wheel"
python3 -m pip install "pelican"
python3 -m pip install "pelican[markdown]"
python3 -m pip install markdown


# Generate content
pelican

# Upload to Site
rsync -avc --delete output/ andrew@www.invoke.coffee:~/www/
ssh andrew@www.invoke.coffee "sudo rsync -r ~/www/ /var/www/html/"
ssh andrew@www.invoke.coffee "sudo chown -R www-data /var/www/html/"

# Cleaning up files
cd ../
rm -rf pelicann

Now I can 2 ways to run this I can run this as a Cron job on a schedule or I can manually run this as needed. In this case I will be running this manually as I post infrequently and don't want to wait for a cron job. If I get around to it I am sure that I could set up some automation in gitea to kick this off when I push to the master branch.

Conclusion

While I don't expect many to be needing this exact solution I did want to demonstrate how easy it would be to create a simple CD script to handle deployment for you. As I need to build and deploy very rarely the scripts man advantage is to deploy consistently every time Vs any time savings.

Anytime you need to deploy something rarely taking the time to automate it even partially will still be worth your time.


i