diff --git a/Makefile b/Makefile index 0aba840..9ae3ccc 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ dev_install: ln -s $(PWD)/abra ~/.local/bin install: - install abra $(HOME)/.local/bin/abra + install abra /usr/bin/abra get_yq: wget https://github.com/mikefarah/yq/releases/download/3.3.2/yq_linux_amd64 && \ diff --git a/abra b/abra index cb8fdb0..6fcab75 100755 --- a/abra +++ b/abra @@ -10,7 +10,7 @@ sub_help(){ echo "Usage: $PROGRAM_NAME [options]" echo "" echo "Subcommands:" - echo " service_run SERVICE [CMD] run a command in the specified service's container" + echo " run SERVICE [CMD] run a command in the specified service's container" echo " secret_generate SECRET VERSION [CMD] generate a secret, store it in pass & as a Docker secret" echo " deploy [COMPOSE_FILE] let 'em rip" echo " logs SERVICE tail logs from a deployed service" @@ -33,10 +33,15 @@ sub_secret_generate(){ >(pass insert "hosts/autonomic-swarm/${STACK_NAME}/${SECRET}" -m) } -sub_service_run(){ +sub_run(){ SERVICE=$1 SH=${2:-/bin/sh} + if [ -z "$SERVICE" ]; then + echo "Usage: $PROGRAM_NAME run SERVICE [CMD]" + exit + fi + CONTAINER=$(docker container ls --format "table {{.ID}},{{.Names}}" \ | grep "${STACK_NAME}_${SERVICE}" | cut -d',' -f1) @@ -46,15 +51,17 @@ sub_service_run(){ fi docker exec -it "$CONTAINER" "$SH" + + return } sub_deploy (){ COMPOSE=${1:-compose.yml} echo "About to deploy:" - echo "Compose: $(tput setaf 3)${PWD}/${COMPOSE}$(tput sgr0)" - echo "Domain: $(tput setaf 2)${DOMAIN}$(tput sgr0)" - echo "Stack: $(tput setaf 1)${STACK_NAME}$(tput sgr0)" + echo " Compose: $(tput setaf 3)${PWD}/${COMPOSE}$(tput sgr0)" + echo " Domain: $(tput setaf 2)${DOMAIN}$(tput sgr0)" + echo " Stack: $(tput setaf 1)${STACK_NAME}$(tput sgr0)" read -rp "Continue? (y/[n])? " choice @@ -64,7 +71,11 @@ sub_deploy (){ * ) return;; esac - docker stack deploy -c "$COMPOSE" "$STACK_NAME" + if docker stack deploy -c "$COMPOSE" "$STACK_NAME"; then + echo "$(tput setaf 2)Yay! App should be available at https://${DOMAIN}$(tput sgr0)" + else + echo "$(tput setaf 1)Oh no! Something went wrong 😕 Check errors above$(tput sgr0)" + fi } sub_logs (){