Skip to content

docker runner: Add labels to volumes created by gitlab runner

For containers, the labels are added and makes possible to filter the containers and cleanup.

For consistency, this should be added to volumes as well.

# docker inspect 7567af8c9827
[
    {
        "Id": "7567af8c9827a68e75b3ab8f2848327c09a23cfeb21b9b3f579b79fb634a1222",
        "Created": "2019-05-02T14:03:51.071095193Z",
        "Path": "gitlab-runner-build",
        "Args": [],
...
        "Mounts": [
            {
                "Type": "volume",
                "Name": "059d90c351a97ae686c81bf85cae83f8b5c4b58cfb18220d2e91f7167f005ede",
                "Source": "/var/lib/docker/volumes/059d90c351a97ae686c81bf85cae83f8b5c4b58cfb18220d2e91f7167f005ede/_data",
                "Destination": "/builds/glen",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Type": "volume",
                "Name": "f63e402ccb3517389f2d8510988582f78dcdd759397d57b5f6a26de787d9bb97",
                "Source": "/var/lib/docker/volumes/f63e402ccb3517389f2d8510988582f78dcdd759397d57b5f6a26de787d9bb97/_data",
                "Destination": "/cache",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
...
            "Labels": {
                "com.gitlab.gitlab-runner.job.before_sha": "0000000000000000000000000000000000000000",
                "com.gitlab.gitlab-runner.job.id": "21458",
                "com.gitlab.gitlab-runner.job.ref": "issue-107083",
                "com.gitlab.gitlab-runner.job.sha": "e561fa9f43edd4aa3dc1575c1e809ecf7d2b0a6a",
                "com.gitlab.gitlab-runner.project.id": "243",
                "com.gitlab.gitlab-runner.runner.id": "9CKymoaq",
                "com.gitlab.gitlab-runner.runner.local_id": "0",
                "com.gitlab.gitlab-runner.type": "predefined"
            }

# docker volume inspect f63e402ccb3517389f2d8510988582f78dcdd759397d57b5f6a26de787d9bb97
[
    {
        "CreatedAt": "2019-05-02T17:01:58+03:00",
        "Driver": "local",
        "Labels": null,
        "Mountpoint": "/var/lib/docker/volumes/f63e402ccb3517389f2d8510988582f78dcdd759397d57b5f6a26de787d9bb97/_data",
        "Name": "f63e402ccb3517389f2d8510988582f78dcdd759397d57b5f6a26de787d9bb97",
        "Options": null,
        "Scope": "local"
    }
]
Edited by 🤖 GitLab Bot 🤖