Sign inSign up

pengbai/gitlab-runner-docker-cleanup

By pengbai

‱Updated almost 8 years ago

garbage collects the GitLab Runner Caches and Images when running on low disk space

Image
1

4.6K

pengbai/gitlab-runner-docker-cleanup repository overview

Docker Hub

⁠GitLab Runner Docker Cleanup

Project forked from gitlab-org/gitlab-runner-docker-cleanup⁠. Thanks to the original project owner.

This is simple docker application that automatically garbage collects the GitLab Runner Caches and Images when running on low disk space. Same require features are implemented in this project.

⁠New features:
  • Update go version to 1.9
  • Be able to define a protected internal images list in a file to prevent from removing, your builder image for example.
  • Support to remove multi-tag images

⁠How to run it?

The tool requires access to Docker Engine.

By default the Docker Engine listens under /var/run/docker.sock

docker run -d \
    -e LOW_FREE_SPACE=10G \
    -e EXPECTED_FREE_SPACE=20G \
    -e LOW_FREE_FILES_COUNT=1048576 \
    -e EXPECTED_FREE_FILES_COUNT=2097152 \
    -e DEFAULT_TTL=10m \
    -e USE_DF=1 \
    --restart always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /etc/gitlab_runner_docker_cleanup_internal_images:/etc/gitlab_runner_docker_cleanup_internal_images \
    --name=gitlab-runner-docker-cleanup \
    pengbai/gitlab-runner-docker-cleanup

example of /etc/gitlab_runner_docker_cleanup_internal_images

$ cat /etc/gitlab_runner_docker_cleanup_internal_images
golang:l.8.4
tutum/curl:alpine
alpine:*

The above command will ensure to always have at least 10GB of free disk space and at least 1M of free files (i-nodes) on disk.

The i-nodes is especially important when using Docker with overlay storage engine. More information about i-node problem here⁠.

⁠Options

You can configure GitLab Runner Docker Cleanup with environment variables:

VariableDefaultDescription
CHECK_PATH/The path which is used when checking disk usage
LOW_FREE_SPACE1GBWhen trigger the cache and image removal
EXPECTED_FREE_SPACE2GBHow much the free space to cleanup
LOW_FREE_FILES_COUNT131072When the number of free files (i-nodes) runs below this value trigger the cache and image removal
EXPECTED_FREE_FILES_COUNT262144How many free files (i-nodes) to cleanup
USE_DFtrueUse a command line df tool to check disk space. Set to false when connecting to remote Docker Engine. Set to true when using with locally installed Docker Engine
CHECK_INTERVAL10sHow often to check the disk space
RETRY_INTERVAL30sHow long to wait before retrying in case of failure
DEFAULT_TTL1mMinimum time to preserve a newly downloaded images or created caches
ADDITIONAL_INTERNAL_IMAGES_FILE_PATH/etc/gitlab_runner_docker_cleanup_internal_imagesUser defined images not to remove

⁠Automated build

The image is automatically built by hub.docker.com.

To see a latest build status, go to:

⁠Development

  1. Install Go Runtime, the 1.9.x is preferred

  2. Download the sources with dependencies:

go get gitlab.com/gitlab-org/gitlab-runner-docker-cleanup

  1. Modifying sources and run tests:
cd $GOPATH/src/gitlab.com/gitlab-org/gitlab-runner-docker-cleanup

go test

⁠Author

Kamil TrzciƄski

⁠Contributor

Peng BAI

⁠License

MIT

Tag summary

Content type

Image

Digest

Size

487.2 MB

Last updated

almost 8 years ago

docker pull pengbai/gitlab-runner-docker-cleanup