Skip to content

Commit

Permalink
Add build container start/stop/restart commands (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanedirt committed Dec 24, 2024
1 parent 14ac94b commit ba7b1f8
Showing 1 changed file with 63 additions and 13 deletions.
76 changes: 63 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ show_usage() {
printf " configure-ssl Configure SSL certificates (Let's Encrypt or self-signed)\n"
printf " configure-email Configure email domains for receiving emails\n"
printf " configure-registration Configure new account registration (enable or disable)\n"
printf " start Start AliasVault containers\n"
printf " stop Stop AliasVault containers\n"
printf " restart Restart AliasVault containers\n"
printf " start Start AliasVault containers using remote images\n"
printf " stop Stop AliasVault containers using remote images\n"
printf " restart Restart AliasVault containers using remote images\n"
printf " reset-password Reset admin password\n"
printf " build Build AliasVault from source (takes longer and requires sufficient specs)\n"
printf " build [operation] Build AliasVault from source (takes longer and requires sufficient specs)\n"
printf " Optional operations: start|stop|restart (uses locally built images)\n"
printf " configure-dev-db Configure development database (for local development only)\n"
printf " migrate-db Migrate data from SQLite to PostgreSQL\n"

Expand All @@ -58,6 +59,12 @@ show_usage() {
printf " --verbose Show detailed output\n"
printf " -y, --yes Automatic yes to prompts (for uninstall)\n"
printf " --help Show this help message\n"
printf "\n"
printf "Examples:\n"
printf " $0 build Build from source\n"
printf " $0 build start Build from source and start using local images\n"
printf " $0 build stop Stop containers using local build configuration\n"
printf " $0 build restart Restart containers using local build configuration\n"
}

# Function to parse command line arguments
Expand All @@ -83,10 +90,23 @@ parse_args() {
shift
fi
;;
# Other commands remain unchanged
build|b)
COMMAND="build"
shift
# Check for additional operation argument
if [ $# -gt 0 ] && [[ ! "$1" =~ ^- ]]; then
case $1 in
start|stop|restart)
COMMAND_ARG="$1"
shift
;;
*)
echo "Invalid build operation: $1"
echo "Valid operations are: start, stop, restart"
exit 1
;;
esac
fi
;;
uninstall|u)
COMMAND="uninstall"
Expand Down Expand Up @@ -184,12 +204,26 @@ main() {

print_logo
case $COMMAND in
"build")
if [ -z "$COMMAND_ARG" ]; then
handle_build
else
case $COMMAND_ARG in
"start")
handle_start "build"
;;
"stop")
handle_stop "build"
;;
"restart")
handle_restart "build"
;;
esac
fi
;;
"install")
handle_install "$COMMAND_ARG"
;;
"build")
handle_build
;;
"uninstall")
handle_uninstall
;;
Expand Down Expand Up @@ -1184,26 +1218,42 @@ generate_self_signed_cert() {

# New functions to handle container lifecycle:
handle_start() {
local mode="$1"
printf "${CYAN}> Starting AliasVault containers...${NC}\n"
$(get_docker_compose_command) up -d
if [ "$mode" = "build" ]; then
$(get_docker_compose_command "build") up -d
else
$(get_docker_compose_command) up -d
fi
printf "${GREEN}> AliasVault containers started successfully.${NC}\n"
}

handle_stop() {
local mode="$1"
printf "${CYAN}> Stopping AliasVault containers...${NC}\n"
if ! docker compose ps --quiet 2>/dev/null | grep -q .; then
printf "${YELLOW}> No containers are currently running.${NC}\n"
exit 0
fi

$(get_docker_compose_command) down
if [ "$mode" = "build" ]; then
$(get_docker_compose_command "build") down
else
$(get_docker_compose_command) down
fi
printf "${GREEN}> AliasVault containers stopped successfully.${NC}\n"
}

handle_restart() {
local mode="$1"
printf "${CYAN}> Restarting AliasVault containers...${NC}\n"
$(get_docker_compose_command) down
$(get_docker_compose_command) up -d
if [ "$mode" = "build" ]; then
$(get_docker_compose_command "build") down
$(get_docker_compose_command "build") up -d
else
$(get_docker_compose_command) down
$(get_docker_compose_command) up -d
fi
printf "${GREEN}> AliasVault containers restarted successfully.${NC}\n"
}

Expand Down Expand Up @@ -1640,7 +1690,7 @@ handle_migrate_db() {
--network="${NETWORK_NAME}" \
-v "${SQLITE_DB_DIR}:/sqlite" \
-e "CONNECTION_STRING=Host=postgres;Database=aliasvault;Username=aliasvault;Password=${POSTGRES_PASSWORD}" \
${GITHUB_CONTAINER_REGISTRY}-installcli:0.10.0 migrate-sqlite "/sqlite/${SQLITE_DB_NAME}")
${GITHUB_CONTAINER_REGISTRY}-installcli migrate-sqlite "/sqlite/${SQLITE_DB_NAME}")
else
# Run migration with volume mount using pre-built image
HASH=$(docker run --rm \
Expand Down

0 comments on commit ba7b1f8

Please sign in to comment.