parent
b0d525a980
commit
ff7fcf2201
41
abra
41
abra
@ -7,10 +7,6 @@ PROGRAM_NAME=$(basename "$0")
|
|||||||
yml_pattern_exists() {
|
yml_pattern_exists() {
|
||||||
PATTERN=$1
|
PATTERN=$1
|
||||||
|
|
||||||
if ! type yq > /dev/null 2>&1; then
|
|
||||||
error "yq program is not installed"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f "$ABRA_CONFIG" ]; then
|
if [ -f "$ABRA_CONFIG" ]; then
|
||||||
RESULT=$(yq read "$ABRA_CONFIG" "$PATTERN")
|
RESULT=$(yq read "$ABRA_CONFIG" "$PATTERN")
|
||||||
|
|
||||||
@ -82,6 +78,8 @@ fi
|
|||||||
###### Load config
|
###### Load config
|
||||||
|
|
||||||
if [ -f "$ABRA_CONFIG" ]; then
|
if [ -f "$ABRA_CONFIG" ]; then
|
||||||
|
require_yq
|
||||||
|
|
||||||
if yml_pattern_exists stack_name; then
|
if yml_pattern_exists stack_name; then
|
||||||
STACK_NAME=$(yq read "$ABRA_CONFIG" stack_name)
|
STACK_NAME=$(yq read "$ABRA_CONFIG" stack_name)
|
||||||
fi
|
fi
|
||||||
@ -114,6 +112,18 @@ load_context() {
|
|||||||
|
|
||||||
###### Safety checks
|
###### 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() {
|
require_stack() {
|
||||||
if [ -z "$STACK_NAME" ]; then
|
if [ -z "$STACK_NAME" ]; then
|
||||||
error "no stack_name, export \$STACK_NAME=my_cool_app or add it to abra.yml"
|
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 " cp SRC_PATH SERVICE:DEST_PATH copy files to a container"
|
||||||
echo " deploy let 'em rip"
|
echo " deploy let 'em rip"
|
||||||
echo " logs SERVICE [ARGS] tail logs from a deployed service"
|
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 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 " run_args SERVICE ARGS CMD run, passing extra args to docker exec"
|
||||||
echo " secret [--help] [SUBCOMMAND] manage secrets"
|
echo " secret [--help] [SUBCOMMAND] manage secrets"
|
||||||
@ -283,11 +294,33 @@ sub_deploy (){
|
|||||||
|
|
||||||
###### Subcommand `logs`
|
###### 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 (){
|
sub_logs (){
|
||||||
require_stack
|
require_stack
|
||||||
|
|
||||||
SERVICE=$1
|
SERVICE=$1
|
||||||
|
|
||||||
|
if [ -z "$SERVICE" ]; then
|
||||||
|
warning "No \$SERVICE provided, running multilogs"
|
||||||
|
sub_multilogs
|
||||||
|
fi
|
||||||
|
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user