Files
jdescopingtool/NEW/deploy/docker/deploy-host.sh
T

134 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMPOSE_FILE="$SCRIPT_DIR/compose.yaml"
SERVICE_NAME="jdescoping-host"
show_help() {
cat <<USAGE
Usage: $(basename "$0") [command] [options]
Commands:
deploy Build image (default) and deploy container
start Start existing container
stop Stop running container
restart Redeploy container (build by default)
rebuild Force rebuild image and recreate container
logs Stream container logs
status Show container status
destroy Remove container; add --volumes to remove volumes
help Show this help
Options:
--no-build Skip image build for deploy/restart
--volumes With destroy, also remove named volumes
-h, --help Show this help
USAGE
}
ensure_compose() {
if ! command -v docker >/dev/null 2>&1; then
echo "docker is not installed or not in PATH" >&2
exit 1
fi
if ! docker compose version >/dev/null 2>&1; then
echo "docker compose is not available" >&2
exit 1
fi
}
compose() {
docker compose -f "$COMPOSE_FILE" "$@"
}
command="deploy"
no_build="false"
remove_volumes="false"
if [[ $# -gt 0 ]]; then
command="$1"
shift
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--no-build)
no_build="true"
;;
--volumes)
remove_volumes="true"
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1" >&2
show_help
exit 1
;;
esac
shift
done
ensure_compose
case "$command" in
deploy)
if [[ "$no_build" == "true" ]]; then
compose up -d --force-recreate --no-build "$SERVICE_NAME"
else
compose up -d --build --force-recreate "$SERVICE_NAME"
fi
;;
start)
compose start "$SERVICE_NAME"
;;
stop)
compose stop "$SERVICE_NAME"
;;
restart)
if [[ "$no_build" == "true" ]]; then
compose up -d --force-recreate --no-build "$SERVICE_NAME"
else
compose up -d --build --force-recreate "$SERVICE_NAME"
fi
;;
rebuild)
compose build --no-cache "$SERVICE_NAME"
compose up -d --force-recreate --no-build "$SERVICE_NAME"
;;
logs)
compose logs -f "$SERVICE_NAME"
;;
status)
compose ps "$SERVICE_NAME"
;;
destroy)
if [[ "$remove_volumes" == "true" ]]; then
compose down --volumes --remove-orphans
else
compose down --remove-orphans
fi
;;
help)
show_help
;;
*)
echo "Unknown command: $command" >&2
show_help
exit 1
;;
esac