Jenkins Blog Automation
Automate site generation with Jenkins.
In The Past
My blog workflow is as follow:
- Write articles
- Proof read
- Git commit and push remote
- Execute Hugo
- Rsync Hugo public to my VPS
Though I used to have aa single zsh function for step 4 and 5 taking care of permission, change directory, and eliminate potential fat finger, it no longer fit with the new docker setup on the VPS server.
I want them automated whenever I push to Github.
Preparation
- Hugo Container I need a docker container to pull my blog repository, execute Hugo and update my web server docker volume.
- Webhook The webhook trigger my Jenkins project.
- Jenkins SSH Site Setup Jenkins ssh site for my VPS.
The Build Step
Once the above are ready, I created a Freestyle project:
Source Code Management, select Git and put in my site repository information
Build Triggers, select GitHub hook trigger for GITScm polling to enabled webhook
Build Step, choose Execute shell script on remote host using ssh, select my web server in SSH site drop down
Command:
1 2 3 4 5 6 7 8
docker run --rm --name ${JOB_NAME}_${BUILD_NUMBER} --network host \ -v CADDY_WWW:/www \ -e P_TZ=America/New_York \ -e MY_GIT_URL=https://github.com/J-Siu/johnsiu.com.git \ -e MY_GIT_SUB=true \ -e MY_GIT_DIR=/www/repo/johnsiu.com \ -e MY_PUB_DIR=/www/site/johnsiu.com \ jsiu/hugo --cleanDestinationDir --minify
I use git sub-module for theme. If you don’t have sub-module, you can remove line 5.
Caddy Setup
docker-compose.yml
|
|
caddyfile
|
|
Conclusion
So far this is running smoothly and the article you are reading now also went through this workflow.
This also mark the completion of my VPS dockerization project. Cheers everyone!