Since I keep this blog versioned on my gitea instance, and since I have Drone CI installed, it occurred to me that I could probably automate post publishing with drone. It took me a couple tries (and this post is part of a final test), but I think I got it sorted now.
The easiest part was setting up the environment:
steps:
- name: setup environment
image: python
commands:
- pip install pipenv
- pipenv install
- pipenv run pelican
when:
branch:
- main
Although, I was reading about poetry the other day and I'd like to take that for a spin one of these days. Maybe on a django project? And maybe even that crud app I have been trying to write for weeks now. But I digress ...
The bit that took me a couple tries was the copying of files over to the server. I beat my head against a wall a couple of times before I realised that in order to ditch the 'output' directory from the pelican build, I needed to tell drone to strip components because explicitly telling it to copy just the files just doesn't work ...
- name: copy flat files to server
image: appleboy/drone-scp
settings:
host:
from_secret: DigitalOceanIP
port:
from_secret: DigitaloceanPort
username: camille
key:
from_secret: jupiterPrivateKey
target: /home/www/pelican/
source: ./output/
strip_components: 2
rm: true
overwrite: true
But then I ran into a new problem. The site is served from an nginx:alpine docker container with a bind directory outside the container. When drone finishes copying the new files over, the container breaks. The way to fix that is to restart the container. So for this final test, I am adding a docker restart to the pipeline.
- name: restart docker container
image: appleboy/drone-ssh
settings:
host:
from_secret: DigitalOceanIP
port:
from_secret: DigitaloceanPort
username: camille
key:
from_secret: jupiterPrivateKey
command_timeout: 2s
script:
- docker restart pelican
Here's hoping it works ...
Editing to add that apart from a couple minor glitches (I had the plugin name wrong), it works!!! Yay me!