This blog is made with Hexo, a simple npm-based blog framework. Up to now (the whole 2 weeks i run this blog now) i had a local publish script that generated the static output of hexo, build the docker container locally and pushed it to the gitlab docker registry for that project. Then i had to navigate my browser to my rancher admin gui and manually upgrade the service for the blog with the new docker image. Way too much effort! So i went and put my automation hat on.
The goal was that everytime i push/merge to
master the blog should be generated and published.
So what is my starting point:
- My GitLab also runs on docker including the CI/CD runners, so the build process itself has to be docker based
- I run everything in Rancher 1.x so it needs to deploy a rancher stack
The first order of business is to get the hexo blog build on the gitlab ci. For that i added a
docker-compose file named
docker-compose.build.yml with the following content:
Here we simply take the official
node docker image, map our project directory into the container, install hexo (registered in the
package.json) through npm and run it. As the project directory is mapped the generated content will be placed in our project directory.
Next we need to instuct the GitLab CI to run this docker compose file. As the runner itself is running in docker we do something named Docker-in-Docker or
here the full
.gitlab-ci.yml we need to control the GitLab CI:
First we define the docker image that gitlab should use to run our build and deploy scripts in. It’s an image i created with inspiration from the https://hub.docker.com/r/jonaskello/docker-and-compose/ image. I used the same commands from Jonas’
Dockerfile and added the
rancher-compose tools to it.
That way we have a meta-image that can handle all our docker build and rancher deploy tasks.
build stage does all the heavy lifting and run everytime we push to the gitlab repo. It runs our
hexo build compose file and then uses the
Dockerfile to put the generated content into an
nginx based image. The resulting images gets pushed to gitlabs docker registry.
If i push to
master it runs the
deploy stage which then uses the
docker-compose.yml below to create/update the
keil-connect-blog stack on my rancher instance. The rancher host and access keys are delivered to the environment by gitlabs Secret Variables feature.
That compose file is super minimalistic. Basically just the image from the gitlab registry and a couple of options.
After the first deploy of the rancher stack i manually wired the generated
blog service to the loadbalancer. That wiring keeps working as long as i keep the service and stack name the same.
And thats it. Now i can easily bring you new posts without fiddeling with docker or rancher and this post is the first one deployed this way! Yay!