make deployment targets configurable

This commit is contained in:
Yax 2026-03-20 20:04:50 +01:00
parent b1acba76f1
commit f10a3b5012
6 changed files with 248 additions and 8 deletions

View file

@ -16,12 +16,36 @@ fi
# Store the user-provided arguments
ARGS="$@"
# Find all directories containing a file named docker-compose*.yml
find . -type f -name 'docker-compose*.yml' | while IFS= read -r compose_file; do
CONFIG_FILE=".env"
# Run the docker compose command with user arguments
echo "Running: docker compose $compose_file"
docker compose -f "$compose_file" $ARGS
# Check if config file exists
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: Config file '$CONFIG_FILE' not found"
exit 1
fi
# Extract DEPLOY variable from .env file
DEPLOY=$(grep '^DEPLOY=' "$CONFIG_FILE" | cut -d '=' -f 2-)
if [ -z "$DEPLOY" ]; then
echo "Error: DEPLOY variable not set in $CONFIG_FILE"
exit 1
fi
# Find all directories containing docker-compose*.yml files
DIRS=$(find . -type f -name 'docker-compose*.yml' -exec dirname {} \; | sort -u)
# Iterate through the filtered directories
for dir in $DIRS; do
# Extract directory name (e.g., "01-blog" from "./01-blog")
dir_name=$(basename "$dir")
# Check if directory name is in DEPLOY list
if echo "$DEPLOY" | grep -qw "$dir_name"; then
compose_file=$(find "$dir" -maxdepth 1 -type f -name 'docker-compose*.yml' | head -1)
echo "Running: docker compose --env-file .env -f $compose_file $ARGS"
docker compose --env-file .env -f "$compose_file" $ARGS
fi
done