Gitlab Runner Cache using Linode Object Storage

Linode offers 250GB of object storage for 5$ a month. Using this we can create a cache for use in Gitlab Runner. This allows us proper access to a cache when running our own runners.

Setup Linode Object Storage

First need to setup your Linode Object Storage. Using this will setup the base 5$/month price and you get 250GB of storage.

https://cloud.linode.com/object-storage/buckets

Setup Linode Object Storage Bucket

Make a bucket for the cache.

Ex. my-gitlab-runner-cache

https://cloud.linode.com/object-storage/buckets

Setup Access keys for Linode Object Storage

Setup limited access keys for your object storage.

https://cloud.linode.com/object-storage/access-keys

Setup Gitlab Runner

Setup Gitlab runner where you want to run the jobs.

https://docs.gitlab.com/runner/install/

Configure runner.cache

For gitlab runner, you will need to configure the cache type. Here we want to set it to s3.

[runner.cache]
Type = s3

https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscache-section

Configure runner.cache.s3 to use Linode Object Storage

[runners.cache.s3]
	ServerAddress = "my-gitlab-runner-cache.us-east-1.linodeobjects.com"
	AccessKey = "LINO**************"
	SecretKey = "SECR*********************************"
	BucketName = "gitlab-runner-cache"
	BucketLocation = "us-east-1"

https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runnerscaches3-section

All Together

My /etc/gitlab-runner/config.toml roughly.

[[runners]]
  name = "MyRunner"
  url = "https://gitlab.com"
  token = "*******************"
  executor = "docker"
  [runners.cache]
    Type = "s3"
    [runners.cache.s3]
			ServerAddress = "my-gitlab-runner-cache.us-east-1.linodeobjects.com"
			AccessKey = "LINO**************"
			SecretKey = "SECR*********************************"
			BucketName = "my-gitlab-runner-cache"
			BucketLocation = "us-east-1"

  [runners.docker]
    tls_verify = false
    image = "alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    disable_cache = false

Register Gitlab Runner

https://docs.gitlab.com/runner/register/

Start Gitlab Runner

sudo systemctl start gitlab-runner

If you want to start on boot you can use enable.

sudo systemctl enable gitlab-runner

https://docs.gitlab.com/runner/configuration/init.html

Result

Should end up something like this.

Restoring cache
Checking cache for my-cache-1...
FATAL: file does not exist                         
Failed to extract cache
...
Saving cache for successful job
Creating cache my-cache-1...
Uploading cache.zip to https://***.us-east-1.linodeobjects.com/my-gitlab-runner-cache/runner/***/project/***/my-cache-1 
Created cache

Troubleshooting

If you see 403, your access keys are not working.

If you see 404, it means it is missing (but should create it properly).

Use log_level = "debug" in gitlab-runner/config.toml to see more info on what’s happening.