After migrating this blog to Jekyll, I wanted to explain how I went about it. There's nothing complicated about it, just a time-saver for those who want to do the same.

I wanted to experiment with static site generators and use them to fill the micro-hosting that OVH provides with its domains. I had already tested Jekyll with GitHub pages for my projects, so I went with it again for OVH.

I started by creating a functional Jekyll project on my machine. Then I added the pipeline file to publish Jekyll on GitLab pages:

image: ruby:2.3 

variables:
  JEKYLL_ENV: production
  LC_ALL: C.UTF-8 

before_script: 
  - bundle install 

pages: 
  stage: deploy 
  script: 
  - bundle exec jekyll build -d public 
  artifacts: 
    paths: 
      - public 
  only: 
    - master

This allowed me to verify that the pipeline was working correctly and test GitLab pages at the same time. :) But my goal is to publish on my OVH hosting.

Having recently seen that even the small free hosting (10 MB) linked to domains was accessible via SFTP, I wanted the upload to be done with this method. However, SCP doesn't work alone - only SFTP works. This creates a problem, because SFTP doesn't know how to create directories when copying multiple files. So I "cheated" with a bit of bash :).

Here's the resulting pipeline file:

image: ruby:2.3 

variables:
  JEKYLL_ENV: production
  LC_ALL: C.UTF-8 

before_script: 
  - chmod 755 /builds/thepozer/thepozer/.ssh
  - chmod 600 /builds/thepozer/thepozer/.ssh/ovh_deploy
  - bundle install 

ovh_deploy: 
  stage: deploy 
  script: 
  - bundle exec jekyll build -d public 
  - find public/* -type d | ( while read dir ; do echo "mkdir ${dir#public/}" ;  done ; echo "put -r public/*" ; echo "exit") | sftp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i .ssh/ovh_deploy thepozerc@ssh.cluster014.ovh.net:www/
  artifacts: 
    paths: 
      - public 
  only: 
    - master

For creating directories, I simply did a find to list the directories, then passed this list to a small bash script that converts each directory into a mkdir command. Finally, it adds the file copy command and the exit command. All these commands are transmitted to the SFTP command.

For example, with the following file structure:

.
├── 404.html
├── cv
│   └── index.html
├── edito
│   └── 2018
│       └── 07
│           └── 21
│               └── passage-a-jekyll.html
├── feed.xml
├── index.html
├── javascript
│   └── 2017
│       └── 04
│           └── 09
│               └── navez-besoin-de-jquery.html
├── mysql
│   ├── 2010
│   │   └── 10
│   │       └── 19
│   │           └── backup-all-mysql-user-from-server.html
│   └── 2017
│       └── 04
│           └── 04
│               └── decoupe-de-fichier-sql.html
└── projects
    ├── gmysqlcc
    │   ├── changelog.html
    │   └── index.html
    ├── index.html
    ├── quickpad
    │   └── index.html
    └── simpledit
        └── index.html

It will generate the following SFTP command list:

mkdir cv
mkdir edito
mkdir edito/2018
mkdir edito/2018/07
mkdir edito/2018/07/21
mkdir javascript
mkdir javascript/2017
mkdir javascript/2017/04
mkdir javascript/2017/04/09
mkdir mysql
mkdir mysql/2010
mkdir mysql/2010/10
mkdir mysql/2010/10/19
mkdir mysql/2017
mkdir mysql/2017/04
mkdir mysql/2017/04/04
mkdir projects
mkdir projects/gmysqlcc
mkdir projects/quickpad
mkdir projects/simpledit
put -r public/*
exit

All directories are created before copying files. However, I don't delete anything that was there before, I just overwrite existing files.

Finally, I added a passwordless SSH key in my private Git repository for deployment in a .ssh directory at the root. I use the before_script section to update permissions for SSH keys.

This is the pipeline I use to deploy this site on my shared hosting. It can be easily adapted to other hosting services.