Closes #8
This commit is contained in:
parent
b0d525a980
commit
ff7fcf2201
41
abra
41
abra
@ -7,10 +7,6 @@ PROGRAM_NAME=$(basename "$0")
|
||||
yml_pattern_exists() {
|
||||
PATTERN=$1
|
||||
|
||||
if ! type yq > /dev/null 2>&1; then
|
||||
error "yq program is not installed"
|
||||
fi
|
||||
|
||||
if [ -f "$ABRA_CONFIG" ]; then
|
||||
RESULT=$(yq read "$ABRA_CONFIG" "$PATTERN")
|
||||
|
||||
@ -82,6 +78,8 @@ fi
|
||||
###### Load config
|
||||
|
||||
if [ -f "$ABRA_CONFIG" ]; then
|
||||
require_yq
|
||||
|
||||
if yml_pattern_exists stack_name; then
|
||||
STACK_NAME=$(yq read "$ABRA_CONFIG" stack_name)
|
||||
fi
|
||||
@ -114,6 +112,18 @@ load_context() {
|
||||
|
||||
###### Safety checks
|
||||
|
||||
require_yq() {
|
||||
if ! type yq > /dev/null 2>&1; then
|
||||
error "yq program is not installed"
|
||||
fi
|
||||
}
|
||||
|
||||
require_multitail() {
|
||||
if ! type multitail > /dev/null 2>&1; then
|
||||
error "multitail program is not installed"
|
||||
fi
|
||||
}
|
||||
|
||||
require_stack() {
|
||||
if [ -z "$STACK_NAME" ]; then
|
||||
error "no stack_name, export \$STACK_NAME=my_cool_app or add it to abra.yml"
|
||||
@ -147,6 +157,7 @@ sub_help() {
|
||||
echo " cp SRC_PATH SERVICE:DEST_PATH copy files to a container"
|
||||
echo " deploy let 'em rip"
|
||||
echo " logs SERVICE [ARGS] tail logs from a deployed service"
|
||||
echo " multilogs tail logs from a whole stackk"
|
||||
echo " run SERVICE CMD run a command in the specified service's container"
|
||||
echo " run_args SERVICE ARGS CMD run, passing extra args to docker exec"
|
||||
echo " secret [--help] [SUBCOMMAND] manage secrets"
|
||||
@ -283,11 +294,33 @@ sub_deploy (){
|
||||
|
||||
###### Subcommand `logs`
|
||||
|
||||
sub_multilogs() {
|
||||
require_stack
|
||||
require_multitail
|
||||
|
||||
# Get a list of the service names
|
||||
SERVICES=$(docker stack services --format "{{.Name}}" "${STACK_NAME}")
|
||||
# Sort the service names
|
||||
SERVICES=$(echo "${SERVICES}" | sort)
|
||||
# Create the command to run
|
||||
COMMAND='multitail --mergeall'
|
||||
for SERVICE in ${SERVICES}; do
|
||||
COMMAND="${COMMAND} -L 'docker service logs --tail 20 -f ${SERVICE}'"
|
||||
done
|
||||
# Run the command
|
||||
bash -c "${COMMAND}"
|
||||
}
|
||||
|
||||
sub_logs (){
|
||||
require_stack
|
||||
|
||||
SERVICE=$1
|
||||
|
||||
if [ -z "$SERVICE" ]; then
|
||||
warning "No \$SERVICE provided, running multilogs"
|
||||
sub_multilogs
|
||||
fi
|
||||
|
||||
shift
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
|
Reference in New Issue
Block a user