First Post in Foreverz
It’s been a while since I’ve made any blog posts…
Here’s a quick update since the last time:
- I've changed jobs twice.
- I've had a bunch of kids.
I also switched everything (both blog and website) over to a Jekyll site about… 2 years ago.
I don’t have the time to contribute as much to open source as I used to, but here’s a little tidbit.
Deploying a Jekyll Blog to a Traditional Web Host, using GitLab CI
I’ve been using GitLab at work for a while now, and it’s grown on me. I’ve recently managed to get my entire website fully deployed by GitLab, both to a staging area with their Pages tool, and to my ‘ole reliable pair Networks hosting account.
I still have to audit my repo before I can make it fully public, but here’s the
.gitlab-ci.yml
I’m using:
# This file is a template, and might need editing before it works on your project.
# Full project: https://gitlab.com/pages/jekyll
image: ruby:2.3.1
before_script:
- bundle install
test:
stage: test
script:
- bundle exec jekyll build -d test
artifacts:
paths:
- test
except:
- master
pages:
stage: deploy
environment: staging
script:
- bundle exec jekyll build -b /pioto-org -d public
artifacts:
paths:
- public
only:
- master
production:
stage: deploy
environment: production
when: manual
variables:
JEKYLL_ENV: production
before_script:
- bundle install
- apt-get update && apt-get install -y rsync
- umask 0077 && mkdir -p /root/.ssh
- umask 0047 && echo "${PROD_KNOWN_HOSTS}" >> /root/.ssh/known_hosts
- umask 0077 && echo "${PROD_DEPLOY_KEY}" > /root/.ssh/id_rsa
script:
- bundle exec jekyll build -d public
- rsync -crvz --delete-after --delete-excluded public/ "${PROD_USERNAME}@${PROD_HOSTNAME}:"
artifacts:
paths:
- public
only:
- master
Here’s basically how this works:
- There’s a basic “test” job, which just confims that everything can actually be built.
- There’s a “pages” job, which is how things get deployed to GitLab Pages. Every commit
on the
master
branch goes there automatically. - There’s a “production” job, which is where the magic happens to deploy my site live:
- Before the build, we make sure we have rsync, and set up the ssh keys needed for the deploy. The contents of the key files are stored as secure variables.
- We build with the correct
baseurl
setting. - We build with
JEKYLL_ENV=production
, so that things like Google Analytics get wired in. - We use rsync (with
rrsync
set up on the other end) to deploy the site.