commit 813e203e35e7b5f4e969e8fa1c2dcb874ddf97c6 Author: Sebastian Mark Date: Fri Dec 15 20:49:46 2023 +0100 Genesis diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..efd19d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +stacklist diff --git a/README.md b/README.md new file mode 100644 index 0000000..e510784 --- /dev/null +++ b/README.md @@ -0,0 +1,19 @@ +# Docker Compose Ops (dc-ops) + +`dc-ops` is a shell script designed to operations automate the local building and updating of several Docker services. +It aims to simplify continuous delivery (CD) processes and infrastructure management in a Docker environment. + +## How does it work? + +* The script iterates through each line of the `stacklist` file, skipping comments +* It fetches the latest changes from the remote git repository and checks if there are new commits +* If there is a change it pulls the updates from the remote git repository, otherwise the entry is skipped +* Following this, it runs `docker compose up` which builds, (re)creates and starts the containers + +The `stacklist` file can list either a directory containing a `docker-compose.yml` file or a precise `docker-compose` file. +(see `stacklist.example`) + +## Usage + +1. Ensure that your 'stacklist' file is up-to-date +2. Run the script manually or create a crontab entry diff --git a/dc-ops b/dc-ops new file mode 100755 index 0000000..3b662e8 --- /dev/null +++ b/dc-ops @@ -0,0 +1,38 @@ +#! /bin/bash + +## Author: Sebastian Mark +## CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de) +## for civil use only + +## see README.md + +h1() { echo "* $*"; } +msg() { echo "$*"; } + +BASEDIR=$(dirname $0) + +while read -r LINE; do + + grep -q "^[[:space:]]*#" <<<$LINE && continue # skip comments + + STACKDIR=$LINE + + if [[ -f $LINE ]]; then + STACKDIR=$(dirname $LINE) + COMPOSEFILE=$LINE + fi + + h1 "processing $STACKDIR" + + cd $STACKDIR || continue + + git fetch --quiet + if [[ $(git rev-parse HEAD) == $(git rev-parse "@{u}") ]]; then + msg "no changes - skipping" + continue + fi + + git pull + docker compose --file ${COMPOSEFILE:=docker-compose.yml} up --build --detach --remove-orphans + +done <$BASEDIR/stacklist diff --git a/stacklist.example b/stacklist.example new file mode 100644 index 0000000..1b1ec87 --- /dev/null +++ b/stacklist.example @@ -0,0 +1,4 @@ +/path/to/repo +/path/to/another-repo +/path/with/docker-compose.yml +/another-path/with/docker-compose-dev.yml