feat: enhance stacklist handling
- add support for passing stacklist as cli parameters
- refactor iteration over stacklist entries
- improve comments for better code understanding
- update README.md
🤖
This commit is contained in:
parent
813e203e35
commit
41d3d04fe7
2 changed files with 15 additions and 9 deletions
10
README.md
10
README.md
|
@ -5,15 +5,15 @@ It aims to simplify continuous delivery (CD) processes and infrastructure manage
|
||||||
|
|
||||||
## How does it work?
|
## 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
|
* 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
|
* 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
|
* 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.
|
The `stacklist` file can list either a directory containing a `docker-compose.yml` file or a precise `docker-compose` file (see `stacklist.example`).
|
||||||
(see `stacklist.example`)
|
Alternatively, the stacklist can also be passed as a list of parameters.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
1. Ensure that your 'stacklist' file is up-to-date
|
* Pass list of directory or docker-compose files as parameters to `dc-ops` or
|
||||||
2. Run the script manually or create a crontab entry
|
* Ensure that your `stacklist` file is up-to-date and run the script (or create a crontab entry)
|
||||||
|
|
14
dc-ops
14
dc-ops
|
@ -11,12 +11,16 @@ msg() { echo "$*"; }
|
||||||
|
|
||||||
BASEDIR=$(dirname $0)
|
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
|
grep -q "^[[:space:]]*#" <<<$LINE && continue # skip comments
|
||||||
|
|
||||||
|
# determine if passed a directory or a file
|
||||||
STACKDIR=$LINE
|
STACKDIR=$LINE
|
||||||
|
|
||||||
if [[ -f $LINE ]]; then
|
if [[ -f $LINE ]]; then
|
||||||
STACKDIR=$(dirname $LINE)
|
STACKDIR=$(dirname $LINE)
|
||||||
COMPOSEFILE=$LINE
|
COMPOSEFILE=$LINE
|
||||||
|
@ -24,15 +28,17 @@ while read -r LINE; do
|
||||||
|
|
||||||
h1 "processing $STACKDIR"
|
h1 "processing $STACKDIR"
|
||||||
|
|
||||||
|
# skip if directroy not found
|
||||||
cd $STACKDIR || continue
|
cd $STACKDIR || continue
|
||||||
|
|
||||||
|
# fetch from repo and check for new commits
|
||||||
git fetch --quiet
|
git fetch --quiet
|
||||||
if [[ $(git rev-parse HEAD) == $(git rev-parse "@{u}") ]]; then
|
if [[ $(git rev-parse HEAD) == $(git rev-parse "@{u}") ]]; then
|
||||||
msg "no changes - skipping"
|
msg "no changes - skipping"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# pull new commits and run docker compose
|
||||||
git pull
|
git pull
|
||||||
docker compose --file ${COMPOSEFILE:=docker-compose.yml} up --build --detach --remove-orphans
|
docker compose --file ${COMPOSEFILE:=docker-compose.yml} up --build --detach --remove-orphans
|
||||||
|
done
|
||||||
done <$BASEDIR/stacklist
|
|
||||||
|
|
Loading…
Reference in a new issue