Files
homeprod/generate-docker-swarmcd.sh
vhaudiquet 6ded6f7d28 Add SOPS encryption for env files
(and decryption with SwarmCD)
2025-09-16 21:22:00 +02:00

38 lines
1001 B
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Create .swarmcd directory if needed
if [ ! -d .swarmcd ]; then
mkdir -p .swarmcd
fi
tmpfile=$(mktemp)
# Make sure to cleanup our temp file on any kind of exit
trap 'rm -f "$tmpfile"' EXIT
# Find and sort all docker-compose.yml directories
find docker -name 'docker-compose.yml' -print0 \
| xargs -0 -n1 dirname \
| sed 's|^\./||' \
| sort \
| while read -r dir; do
file="$dir/docker-compose.yml"
# Discover env file if it exists, and add it to secret list
if [ -f "$dir/.env" ]; then
env=" sops_files:\n - $dir/.env\n"
else
env=""
fi
name=$(basename "$dir")
echo -e "$name:\n repo: homeprod\n branch: main\n compose_file: $file\n$env" >> "$tmpfile"
done
# Overwrite file on change
if ! [ -f .swarmcd/stacks.yaml ] || ! cmp -s "$tmpfile" .swarmcd/stacks.yaml; then
mv "$tmpfile" .swarmcd/stacks.yaml
echo "Updated .swarmcd/stacks.yaml!"
else
echo "No changes to .swarmcd/stacks.yaml."
fi