I wanted to move away from using webhooks to control my deployment. I didn’t really like the idea of having to run a server just to listen for deployments. Plus it meant I had some deployment scripts sitting on my server and not in source control which I really didn’t like.
I know I shouldn’t have been but I was surprised with how easy it was to get it set up and running1. Install the runner, make a couple of changes to the
.gitlab-ci.yml file and I was up and running.
Setting up the Runner
concurrent = 1 check_interval = 0 [session_server] session_timeout = 1800 [[runners]] name = "www.aselford.dev" url = "https://gitlab.com/" token = "yRTZzdV-5FHnMwcyiRyn" executor = "shell" [runners.custom_build_dir] enabled = true [runners.cache] [runners.cache.s3] [runners.cache.gcs]
GitLab CI Config
My deployment steps for staging are shown below.
Deploy_Staging: stage: deploy # Only run on my self-hosted staging runner tags: - self-hosted - staging variables: DOCKER_HOST: "" DOCKER_TLS_CERTDIR: "" # GIT_CLONE_PATH is not required anymore GIT_CLONE_PATH: $CI_BUILDS_DIR/dev-blog IMAGE_TAG: $DEV_IMAGE_TAG script: - docker pull $DOCKER_IMAGE_NAME:$IMAGE_TAG - docker stack deploy --compose-file docker-compose-dev.yml devblog environment: name: Staging only: - develop
I’m currently using Docker Swarm for deployments as a lightweight way to get rolling updates. I would like to move to Kubernetes but the extra overhead on my small VPS was not going to work.
Using GitLab runners also means I know the deployment has actually finished and worked. Previously when using webhooks I just had to assume the deployment had worked.
I’ve also got distracted again about hosting my images somewhere other than in my git repo. I still haven’t written my watch app…
At least that’s what I thought when I started writing this blog post. 8 hours later and I’ve only just got it fully working so maybe not as easy as I thought. Among other things I stumbled across a weird issue that meant environment variables weren’t expanding. ↩︎
In the end I didn’t need this - my old deployment method required a specific folder name but the new method doesn’t. But I’m leaving this paragraph in for my own records. ↩︎