Skip to content

roytouw/Gitlab-Image-Refresher

Repository files navigation

Gitlab-Image-Refresher

Polls Gitlab image registry for updates for images listed in config.json and updates containers and services using these images. Developed for Ubuntu 18.04, other distributions or operating systems not tested.

Images

Images listed in config.json will be replaced by the new version upon detection of the new version.

Services

Services that run outdated images will be cleaned up by removing all stopped containers beloning to the service, after which the service will be force-updated to run the newly pulled image.

Running Containers

Running containers belonging to a service will be updated by force-updating the containing service. Containers not belonging to any service will be stopped and removed. For each stopped container a new one wil be ran with the updated image.

Stopped Containers

Stopped containers will be treated the same as running containers.

No Running or Stopped Containers Found

When no running or stopped containers with the image as listed in the config.json are found, upon detection of a new version of the image a single container with this image will be ran.

Usage

  • Configure config.json1
  • Create a config.json file and replace the placeholders with your data.
    {
    "config": {
        "interval": <interval-seconds>,
        "login": "<gitlab-login>",
        "password": "<gitlab-password>"
      },
      "registries": [
        {
          "user": "<user-name>",
          "project": "<project-name>",
          "apiToken": "<api-token>",
          "images": [
            {
              "tag": "<tag>"
            }
          ]
        },
        {
          "user": "<user-name>",
          "project": "<project-name>",
          "apiToken": "<api-token>",
          "images": [
            {
              "tag": "<tag>"
            },
            {
              "tag": "<tag2>"
            }
          ]
        }
      ]
    }
  • Make docker-compose.yml2
  • Create a docker-compose.yml file and replace the placeholders with your files.
    version: '3.2'
    services:
      gitlab-image-refresher:
        image: gitlab-image:refresher:latest
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - <path-to-config.json>:/app/config.json
          - <path-to-cache.json>:/app/cache.json
          - <path-to-log.txt>:/app/cache.json
  • Deploy Service
  • Deploy service e.g. docker stack deploy -c docker-compose.yml refresher



    1 To generate Gitlab private API token see: https://gitlab.com/profile/personal_access_tokens Gitlab Image Refresher requires api rights to work.
    2cache.json and log.txt are optional for perseverance, use touch to create empty file.

    About

    Automatically update Docker services and containers with new image from Gitlab image registry.

    Resources

    License

    Stars

    Watchers

    Forks

    Releases

    No releases published

    Packages

    No packages published