diff --git a/README.md b/README.md index e510784..fed4a85 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,15 @@ It aims to simplify continuous delivery (CD) processes and infrastructure manage ## How does it work? -* The script iterates through each line of the `stacklist` file, skipping comments +* The script iterates through each line of the `stacklist` file (skipping comments) or through all cli parameters * 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`) +The `stacklist` file can list either a directory containing a `docker-compose.yml` file or a precise `docker-compose` file (see `stacklist.example`). +Alternatively, the stacklist can also be passed as a list of parameters. ## Usage -1. Ensure that your 'stacklist' file is up-to-date -2. Run the script manually or create a crontab entry +* Pass list of directory or docker-compose files as parameters to `dc-ops` or +* Ensure that your `stacklist` file is up-to-date and run the script (or create a crontab entry) diff --git a/dc-ops b/dc-ops index 3b662e8..4f9ee59 100755 --- a/dc-ops +++ b/dc-ops @@ -11,12 +11,16 @@ msg() { echo "$*"; } BASEDIR=$(dirname $0) -while read -r LINE; do +# use list from file or passed parameters +STACKLIST=$(cat $BASEDIR/stacklist) +[[ $# -gt 0 ]] && STACKLIST=$* +# iterate list +for LINE in $STACKLIST; do grep -q "^[[:space:]]*#" <<<$LINE && continue # skip comments + # determine if passed a directory or a file STACKDIR=$LINE - if [[ -f $LINE ]]; then STACKDIR=$(dirname $LINE) COMPOSEFILE=$LINE @@ -24,15 +28,17 @@ while read -r LINE; do h1 "processing $STACKDIR" + # skip if directroy not found cd $STACKDIR || continue + # fetch from repo and check for new commits git fetch --quiet if [[ $(git rev-parse HEAD) == $(git rev-parse "@{u}") ]]; then msg "no changes - skipping" continue fi + # pull new commits and run docker compose git pull docker compose --file ${COMPOSEFILE:=docker-compose.yml} up --build --detach --remove-orphans - -done <$BASEDIR/stacklist +done