We already saw a way to deploy our pelican website. To do it we add a SSH private SSH key to the environment variables. That not so nice since everybody that have access to the project can get the SSH private key. We will see here an other possibility to deploy our pelican website by mounting the final repository directly inside the build environment.
You will need to have functional installation of GitLab and GitLab Runner with
Docker. In addition we suppose that the required python are in the
requirements.txt file. The build and deployment will be managed with
python and classical tools like
mv, so a minimal docker image with
python should be enough to do the job. The GitLab Runner should be on the
machine that serve the website.
Create a runner
We will first create a runner that use docker that have python 2 installation
and the web destination folder mounted (in our case it will be
General runner registration
If not already done, you will need to setup a runner for the project:
# gitlab-runner register
Enter then the token that will link GitLab and the runner:
- If you would like to have a shared runner go to the Admin Area, then Overview and finally Runners, to get the token.
- If you prefer to have a runner for the project, go in the configuration menu of the projects and select Runners and use the token of the project.
Give a name to your runner and eventually some tags. I suggest to had as tags
all the functionality of the runner. Indeed we can specify in the build system
to use only the runners that carry specified tags. In our example the tags will
Specify the executor as
docker and the docker image as
Configuration of the mounted volume
At the creation of the runner, automatically a volume is created as cache
/cache). We will add an other one that will be linked to a real path on
the machine running the gitlab-ci-multi-runner.
To do it we need to edit the
/etc/gitlab-runner/config.toml. Search the
runner you are interested and change the
volumes line as follow:
volumes = ["/cache", "/var/www:/var/www:rw"]
Each time the runner will be executed the
/var/www folder of the host at
the same place in the container as read write.
Here are the different steps for the deployment.
- Clone the repository.
- First install dependencies with the help of pip and the
- Generate pelican website.
- Backup the old version of the website (just in case)
- Move the output directory in the destination
Configuration of the continuous integration
We will create a Gitlab continuous integration configuration file
.gitlab-ci.yml) at the root of the repository. It is automatically
recognised by GitLab. The file is inspired from the one proposed by GitLab.
image: python:2.7-alpine pages: tags: - www-mount - python2 script: - pip install -r requirements.txt - pelican -s publishconf.py - mv -f /var/www/website.domain /var/www/archives/website.domain.$(date "+%Y%m%d_%H%M%S") || true - mv output /var/www/website.domain
For the build we specify two tags here:
This will allow the build system to select the runner that have the same tags.