-1

I am working with a gitlab-ci server (with registry enabled).

Each time something is merged on master branch, i am building a docker image which contains all my source code.

Next, this image is deployed on a rancher server.

Here is an extract of my .gitlab-ci.yml file:

variables:
      CONTAINER_TEST_IMAGE: mypersonnalgitlabserver.com:5005/myname/myproject:$CI_BUILD_REF_NAME
...
build:
  ...
  script:
     - docker build --cache-from=$CONTAINER_TEST_IMAGE --file=Dockerfile --tag=$CONTAINER_TEST_IMAGE .
     - docker login -u gitlab-ci-token -p "$CI_BUILD_TOKEN" $CI_REGISTRY
     - docker push $CONTAINER_TEST_IMAGE
...
deploy:
   image: cdrx/rancher-gitlab-deploy
   variables:
     GIT_STRATEGY: none
   script:
      - upgrade --stack mystack --service myservice --no-start-before-stopping --no-wait-for-upgrade-to-finish

Everything works: When i change something on my source code, if i push it to master branch, i can see updates on my production rancher server.

But i can see a lot of images and containers with this commands:

docker images -a
docker ps -a

This images and containers are growing each time i am pushing something on master. I have the same problem on gitlab-ci server and rancher server.

So my question is: How can i automatically delete thoses images and containers ?

Thanks

Bob5421
  • 7,757
  • 14
  • 81
  • 175

1 Answers1

0

If this is rancher version 1.x, look in the catalog and see if the item called "Janitor" will help. We use it to remove images left-over from build agents.

Scott Anderson
  • 1,666
  • 12
  • 12
  • Thanks but can you explain me why we need a tool like this to delete this images. They should be automatically deleted ? – Bob5421 Jul 06 '18 at 10:13
  • In the case of the gitlab-runner, [it is a known issue that it doesn't clean up](https://gitlab.com/gitlab-org/gitlab-runner/issues/2980) after itself. However, it is a much more difficult problem than it sounds because the runner doesn't know what the builds are actually doing. Just like a filesystem, when it fills up, it is delegated to the user to choose what stuff to delete. – Scott Anderson Jul 06 '18 at 10:31