Gitlab allows you not only to have free private repositories, but also to test them using free runners. These can run automatically, on push, for any branch or tag.
I keep a few private repositories with them, for personal projects and small experiments. I decided to give Gitlab CI a shot for a PostgreSQL-backed Clojure project.
There’s a basic example on the Gitlab CI repository. It gets and installs lein, which isn’t necessary. Instead, we’ll build use the clojure:lein
Docker image.
Let’s start with an empty .gitlab-ci.yml
file on your repository’s root.
1 | image: clojure:lein-2.7.0 |
You’ll see I’ve also included Postgres as a service since it’s what I’m using for the database.
We’ll then need to add a section for any environment variables
1 | variables: |
Gitlab also allows you to define secret variables on a per-project basis, but there’s no need for that here.
Finally, we’ll add our before_script
section, which just updates apt-get and loads the dependencies.
1 | before_script: |
Update: Notice that I’m updating the package lists using apt-get
. This is necessary because I’ll also need to install the Postgres client. If you don’t need to install anything using apt, you might save some build time by removing that line.
Before proceeding to test, we’ll install the Postgres client, initialize the database (adding some plugins), and run the migrations.
1 | test: |
And voilá! Tests will run on push. You can find a history for the status of the Pipelines section of your project.
If for any reason you don’t see a Pipelines option, make sure that Builds are enabled in the project’s settings.
You’ll also get a build history
Here you’ll find the complete file as a snippet.
Cheers!
Published: 2016-10-10