lab-ansible/roles/apps/templates/scripts/deploy.sh.j2

42 lines
1,010 B
Django/Jinja

{# code: language=ansible-jinja #}
# THIS FILE IS MANAGED BY ANSIBLE
#!/usr/bin/env bash
ARG="$1"
APPS_DIR="{{ apps_data_root }}"
case $ARG in
start)
for app in $APPS_DIR/*; do
docker compose -f $app/docker-compose.yml up --remove-orphans -d
done
;;
stop)
for app in $APPS_DIR/*; do
docker compose -f $app/docker-compose.yml down --remove-orphans
done
;;
restart)
for app in $APPS_DIR/*; do
docker compose -f $app/docker-compose.yml restart
done
;;
{% if 'caddy' in apps_include %}
reload-proxy)
CADDYFILE="/etc/caddy/Caddyfile"
docker compose -f $APPS_DIR/caddy/docker-compose.yml exec web \
sh -c "caddy validate -c $CADDYFILE && caddy reload -c $CADDYFILE" \
2>/dev/null
;;
{% elif 'nginx' in apps_include %}
reload-proxy)
docker compose -f $APPS_DIR/nginx/docker-compose.yml exec web \
sh -c "nginx -t && nginx -s reload"
;;
{% endif %}
*)
echo "Unrecognized argument"
exit 1
;;
esac