Skip to main content

Watch git repositories for Docker compose configuration changes

Project description

PullDocker

Travis CI Build Status CircleCI Build Status PyPI - Version PyPI - Python Version

Description: Watch git repositories for Docker compose configuration changes

Copyright: 2024-2025 Fabio Castelli (Muflone) muflone@muflone.com

License: GPL-3+

Source code: https://github.com/muflone/pulldocker

Documentation: http://www.muflone.com/pulldocker/

Description

PullDocker is a command line tool monitor a git repository for changes and run docker deploy (and optionally others commands) when changes are detected.

This tool comes handy to automate Docker compose deployments on git operations (gitops) and can automatically deployments every time a repository receives updates or a new tag is made.

System Requirements

Usage

PullDocker is a command line utility and it requires some arguments to be passed:

pulldocker
  --configuration <YAML FILE>
  [--verbose | --quiet]
  [--watch] [--sleep <SECONDS>]

The argument --configuration refers to a YAML configuration file containing repositories specifications (see below).

The argument --verbose will show additional debug messages for diagnostic purposes.

The argument --quiet will hide every diagnostic messages showing only errors.

The argument --watch will enable the watch mode, continuously checking the repository for changes.

The argument --sleep can specify a number of seconds to await in watch mode between each iteration.

YAML Configuration specifications

A YAML configuration file consists of one or more repositories, separated using --- and a newline. A repository will require the following minimum arguments:

NAME: Repository name
REPOSITORY_DIR: <Path where the git repository is cloned and can be pull>
REMOTES:
  - Remotes list from where to pull the new commits

Some more advanced specifications can be found below.

Minimal example file

NAME: PullDocker
REPOSITORY_DIR: /home/muflone/pulldocker.git
REMOTES:
  - origin

The previous example would monitor the /home/muflone/pulldocker.git repository and it will pull new commits from the remote called origin.

Whenever a new commit is found, a new docker compose up -d command will be issued in the repository directory.

Multiple repositories specifications

Multiple repositories can be configured in the same YAML file and they will be monitored one after the other, sequentially.

A multi-repository file could be the following:

NAME: PullDocker
REPOSITORY_DIR: /home/muflone/pulldocker.git
REMOTES:
  - origin
---
NAME: PixelColor
REPOSITORY_DIR: /home/muflone/pixelcolor.git
REMOTES:
  - github

The first repository will monitor the origin remote and the second repository will monitor the github remote.

Additional YAML specifications

The following YAML specifications

NAME: Repository name
REPOSITORY_DIR: <Path where the git repository is cloned and can be pull>
REMOTES:
  - origin
  - github
  - gitlab
TAGS: '*'
COMPOSE_FILE: docker/docker-compose.yaml
COMPOSE_EXEC:
  - docker
  - compose
DETACHED: true
BUILD: true
RECREATE: true
COMMAND: docker compose -f docker/docker-compose.yaml up -d
BEGIN:
  - bash -c 'echo BEGIN ${DATE} ${TIME}'
BEFORE:
  - bash -c 'echo BEFORE ${DATE} ${TIME}'
  - bash -c 'echo ${TAG} ${TAG_HASH} ${TAG_DATE} ${TAG_TIME}'
AFTER:
  - bash -c 'echo AFTER ${DATE} ${TIME}'
  - bash -c 'echo ${TAG} ${TAG_HASH} ${TAG_DATE} ${TAG_TIME}'
END:
  - bash -c 'echo END ${DATE} ${TIME}'

The TAGS argument can be used to deploy the update only when the latest commit matches a tag. The tag specification can be '*' to indicate any tag available or a regex (Regular expression) can be used to match the available tags. For example the following: TAGS: '0\.[1-9]\.*' will only match the tags starting with 0.1.x up to 0.9.x and it would exclude the tags with 0.0.x.

If no tags are specified, any available commit newer than the current commit will issue the deployment.

The COMPOSE_FILE argument is used to specify the path for a docker-compose.yaml/yml file in the case the file is contained in another directory, or it has a different name than the default docker-compose.yaml.

The COMPOSE_EXEC argument is used to specify the default docker compose to execute to deploy the container. This defaults to docker compose command but any other command can be specified. Please note this is a list of strings, not a single string.

The DETACHED argument is used to specify a boolean value for running the docker compose in detached mode (the default, passing true) or without the detached mode, by specifying the value false.

The BUILD argument is used to build the images before starting the deployment.

The RECREATE argument is used to force the recreation of the containers even if the configuration wasn't changed.

The PROGRESS argument is used to enable or disable the progress output during the deployment.

The COMMAND argument can be used to specify the explicit command for the deployment, instead of using docker compose up. This command will override any previous COMPOSE_FILE, DETACHED, BUILD, RECREATE, PROGRESS arguments.

The BEGIN argument can be a list of commands to execute when checking the status for the repository, regardless if it has updates or not. Multiple commands can be specified.

The BEFORE argument can be a list of commands to execute after checking the status for the repository, before the deploy is done if it has updates. Multiple commands can be specified.

The AFTER argument can be a list of commands to execute after checking the status for the repository, after the deploy is done if it has updates. Multiple commands can be specified.

The END argument can be a list of commands to execute after checking the status for the repository, regardless if it has updates or not. Multiple commands can be specified.

Commands details

The commands arguments can use both strings (one command per line) or list of arguments (one argument per line) using the YAML lists syntax.

The following are both valid:

BEGIN:
  - bash -c 'echo BEGIN ${DATE} ${TIME}'

Using the list syntax:

BEGIN:
  -
    - bash
    - -c
    - 'echo BEGIN ${DATE} ${TIME}'

Command variables

The following special variables can be used in any command to replace the variable with its value:

  • ${NAME}: repository name in the YAML file
  • ${DIRECTORY}: repository directory path
  • ${DATE}: current date with the format YYYY-MM-DD
  • ${TIME}: current time with the format HH:mm:ss
  • ${COMMIT_HASH}: latest commit hash
  • ${COMMIT_DATE}: latest commit date with the format YYYY-MM-DD
  • ${COMMIT_TIME}: latest commit with the format HH:mm:ss
  • ${COMMIT_BRANCH}: latest commit branch name
  • ${COMMIT_AUTHOR}: latest commit author name
  • ${COMMIT_EMAIL}: latest commit author email
  • ${COMMIT_MESSAGE}: latest commit message
  • ${COMMIT_SUMMARY}: latest commit summary
  • ${COMMITS_COUNT}: number of commits

The following variables can only be used for the COMMAND, BEFORE and AFTER arguments when the TAGS argument is used so their values will refer to the matching tag used:

  • ${TAG}: tag name
  • ${TAG_HASH}: commit hash for the matching tag
  • ${TAG_AUTHOR}: commit author name for the matching tag
  • ${TAG_EMAIL}: commit author email for the matching tag
  • ${TAG_MESSAGE}: tag message
  • ${TAG_SUMMARY}: commit message for the matching tag
  • ${TAG_DATE}: tag date with the format YYYY-MM-DD
  • ${TAG_TIME}: tag time with the format HH:mm:ss

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pulldocker-0.3.5.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pulldocker-0.3.5-py3-none-any.whl (15.7 kB view details)

Uploaded Python 3

File details

Details for the file pulldocker-0.3.5.tar.gz.

File metadata

  • Download URL: pulldocker-0.3.5.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for pulldocker-0.3.5.tar.gz
Algorithm Hash digest
SHA256 ac3c5531277e516c26b067690046378a1f8128f2c0bd2fbd3d77024fa4051e5b
MD5 023fa2018492100eb7800540cc3c575b
BLAKE2b-256 be2d104df8553484c3f47694c2669b8b5e54d15cbbb945dcf4e02dc567352fe2

See more details on using hashes here.

File details

Details for the file pulldocker-0.3.5-py3-none-any.whl.

File metadata

  • Download URL: pulldocker-0.3.5-py3-none-any.whl
  • Upload date:
  • Size: 15.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for pulldocker-0.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 42ed4b59931904515a4ac01d13a56e8033808f707f26771c8b50e59b3ede4a34
MD5 a927aec44de8d4ec7f7f42447d8d28c9
BLAKE2b-256 cf3a67c6796e69b823cb9ebb4993a0bbe43b094a1b9f680e870a2f150cbbefe4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page