Skip to content

Commit

Permalink
Add hourly tips to help discover and learn subcommands
Browse files Browse the repository at this point in the history
New subcommand added as a hook and reordered some hooks

Fixes #129
  • Loading branch information
Nekroze committed Nov 2, 2018
1 parent 04c5025 commit 3d9631d
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 33 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Are you ready to get STABLE!
- Automatically install PKI CA certificate in browsers when possible
- `tools list` and `services list` now have username and password columns for applicable services
- When creating an entrypoint check if anything already exists before writing
- Generate `tools list` and `services list` out dynamically from docker-compose files
- Generate `tools list` and `services list` dynamically from docker-compose files
- `dab group tool` is now `dab group tools`
- `dab group repo` is now `dab group repos`
- Disconnect containers before recreating `lab` and `services` networks then reconnect them
Expand All @@ -50,6 +50,7 @@ Are you ready to get STABLE!
- Deprecated `compose-external-default-network.sh`
- Reversed changelog output, newest changes are at the bottom
- `dab config keys` can now take a config key to limit its output
- Moved some hooks to post execution such as checking wrapper updates

### Added

Expand Down Expand Up @@ -79,6 +80,10 @@ Are you ready to get STABLE!
- Subcommand aliases
- `dab repo entrypoint run` to allow execution of any entrypoint
- docker-compose-gen
- Tips to be displayed hourly on dab usage
- `REQUIRED SERVICES` column to `dab tools list` output to better indicate required services
- `dab tip` subcommand
- Added post execution hooks

### Fixed

Expand Down
18 changes: 9 additions & 9 deletions app/docker/docker-compose.tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ services:
chronograf:
image: "chronograf:${DAB_TOOLS_CHRONOGRAF_TAG:-alpine}"
labels:
description: 'Chronograf metrics explorer from the TICK stack'
description: 'Chronograf metrics explorer from the TICK stack`influxdb'
com.centurylinklabs.watchtower.enable: 'true'
depends_on:
- kapacitor
Expand All @@ -62,7 +62,7 @@ services:
kapacitor:
image: "kapacitor:${DAB_TOOLS_KAPACITOR_TAG:-alpine}"
labels:
description: 'Real-Time metrics processing from the TICK stack'
description: 'Real-Time metrics processing from the TICK stack`influxdb'
com.centurylinklabs.watchtower.enable: 'true'
networks:
- services
Expand Down Expand Up @@ -148,7 +148,7 @@ services:
sysdig:
image: "sysdig/sysdig:${DAB_TOOLS_SYSDIG_TAG:-latest}"
labels:
description: 'Universal system visibility tool with native support for containers'
description: 'Universal system visibility tool'
volumes:
- /var/run/docker.sock:/host/var/run/docker.sock
- /dev:/host/dev
Expand All @@ -166,7 +166,7 @@ services:
args:
- "GRAFANA_TAG=${DAB_TOOLS_GRAFANA_TAG:-latest}"
labels:
description: 'The open platform for analytics and monitoring`admin`admin'
description: 'The open platform for analytics and monitoring``admin`admin'
com.centurylinklabs.watchtower.enable: 'true'
networks:
- services
Expand Down Expand Up @@ -206,7 +206,7 @@ services:
context: .
dockerfile: Dockerfile.ntopng
labels:
description: 'Monitor network interfaces, requires redis service'
description: 'Monitor network interfaces`redis'
network_mode: host
ports:
- 3000
Expand All @@ -218,7 +218,7 @@ services:
vaultbot:
image: "msvechla/vaultbot:${DAB_TOOLS_VAULTBOT_TAG:-latest}"
labels:
description: 'Automate interaction with Hashicorp Vault'
description: 'Automate interaction with Hashicorp Vault`vault'
com.centurylinklabs.watchtower.enable: 'true'
entrypoint:
- ./vaultbot
Expand All @@ -233,7 +233,7 @@ services:
pgadmin:
image: "dpage/pgadmin4:${DAB_TOOLS_PGADMIN_TAG:-latest}"
labels:
description: 'Postgres administration console`user@dab`admin'
description: 'Postgres administration console``user@dab`admin'
com.centurylinklabs.watchtower.enable: 'true'
environment:
PGADMIN_DEFAULT_EMAIL: 'user@dab'
Expand All @@ -249,7 +249,7 @@ services:
kafkacat:
image: "confluentinc/cp-kafkacat:${DAB_TOOLS_KAFKACAT_TAG:-latest}"
labels:
description: 'Lightweight kafka console consumer/producer'
description: 'Lightweight kafka console consumer/producer`kafka'
com.centurylinklabs.watchtower.enable: 'true'
networks:
- services
Expand All @@ -276,7 +276,7 @@ services:
image: "kibana:${DAB_TOOLS_KIBANA_TAG:-6.4.2}"
restart: on-failure
labels:
description: 'Explore and visualize elasticsearch data'
description: 'Explore and visualize elasticsearch data`elasticsearch'
com.centurylinklabs.watchtower.enable: 'true'
networks:
- services
Expand Down
2 changes: 0 additions & 2 deletions app/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ set -euf
# shellcheck disable=SC1091
. ./lib/update.sh
# shellcheck disable=SC1091
. ./lib/dab.sh
# shellcheck disable=SC1091
. ./lib/vault.sh
# shellcheck disable=SC1091
. ./lib/services.sh
35 changes: 32 additions & 3 deletions app/lib/hooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,36 @@ maybe_post_chronograf_annotiation() {
"
}

hooks() {
hour_in_seconds=3600
tip_interval="$hour_in_seconds"
should_display_tip() {
[ "${DAB_TIPS:-yes}" = 'yes' ] || return 1

last_tip="$(config_get "tips/last")"
[ -n "$last_tip" ] || return 0

now="$(date +%s)"
seconds_since_last_tip="$((now - last_tip))"
[ "$seconds_since_last_tip" -gt "$tip_interval" ]
}

maybe_display_tip() {
if should_display_tip; then
echo
config_set tips/last "$(date +%s)"
dab tip
fi
}

pre_hooks() {
trap post_hooks EXIT

quietly maybe_post_chronograf_annotiation "$*" || true

DAB_SERVICES_VAULT_TOKEN="$(vault_token)"
export DAB_SERVICES_VAULT_TOKEN

config_load_envs || true
maybe_notify_wrapper_update || true
maybe_update_completion || true

case "${1:-}" in
'-h' | '--help' | 'help' | 'network' | 'update')
Expand All @@ -41,4 +63,11 @@ hooks() {
quietly ensure_network || true
;;
esac

maybe_update_completion || true
}

post_hooks() {
maybe_display_tip || true
maybe_notify_wrapper_update || true
}
16 changes: 10 additions & 6 deletions app/lib/output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@ carelessly() {

fatality() {
# shellcheck disable=SC2039
echo -e "${COLOR_RED}$*${COLOR_NC}" 1>&2
echo_color "$COLOR_RED" "$@" 1>&2
exit 1
}

inform() {
# shellcheck disable=SC2039
echo -e "${COLOR_CYAN}$*${COLOR_NC}"
echo_color "$COLOR_CYAN" "$@"
}

warn() {
# shellcheck disable=SC2039
echo -e "${COLOR_YELLOW}$*${COLOR_NC}"
echo_color "$COLOR_YELLOW" "$@" 1>&2
}

whisper() {
echo_color "$COLOR_LIGHT_GRAY" "$@"
}

echo_color() {
color="$1"
shift
# shellcheck disable=SC2039
echo -e "${COLOR_LIGHT_GRAY}$*${COLOR_NC}"
echo -e "${color}$*${COLOR_NC}"
}
2 changes: 1 addition & 1 deletion app/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euf

# shellcheck disable=SC1091
. ./lib/hooks.sh
hooks "$@"
pre_hooks "$@"

APPLICATION='dab'
DESCRIPTION='The Developer Laboratory
Expand Down
8 changes: 0 additions & 8 deletions app/subcommands/template

This file was deleted.

62 changes: 62 additions & 0 deletions app/subcommands/tip
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/sh
# Description: Display a tip, you may define custom tips by adding to the config key 'tips/custom'
# vim: ft=sh ts=4 sw=4 sts=4 noet
set -euf

# shellcheck disable=SC1091
. ./lib/config.sh

TIPS="
Tips can be disabled by setting the environment variable \$DAB_TIPS to 'no'
Use 'dab repo list' to see which repositories are not on origin/master
Try 'dab tools portainer' to manage and monitor docker containers in your browser
Did you know the dab configuration is a tree structure, run 'dab config keys' to explore it
You can explore the dab container with 'dab shell' which is helpful for testing commands
You can explore the dab lab network with 'dab network shell'
You do not need to do anything to ensure you are using the latest version of dab, but can trigger an update with 'dab update'
Each repository can have any number of entrypoints defined
Repository entry points can take parameters for extra customizability
Services are backround applications that your repositories may want to build upon, see what is availale with 'dab services list'
Tools provide helpful interfaces for accomplishing devops tasks, see what is available with 'dab tools list'
Any git repository can be managed and orchestrated by Dab, even if it does not need to start a service
When a group depends on a repositry you can give an additional parameter after name to customize the enrypoint that will be executed
Services and Tools persist data by default where appropriate, if you want to wipe data try 'dab tools destroy' or 'dab services destroy'
A public key infrastructure (pki) and secrets management engine backed by Hashicorp Vault and Consul is provided that persists across reboots
The public key infrastructure (pki) is able to issue x509 certificates suitable for HTTPS that are only renewed when neccesary
The public key infrastructure (pki) will generate a certificate authority only once (unless destroyed) and automatically install it into all local browsers
Most Services and Tools have docker health checks so you can see at a glance if dependencies are behaving correctly
Dab creates a customizable lab network, any container's your repositories starts should connect to it for instrumentation and tooling
The lab network can be rebuilt with 'dab network recreate' with little ill effect as all containers are first detached then reattached to the new network
Repository entry points might use \$DAB_UID and \$DAB_GID environment variables when running docker containers with bind mounts to prevent permissions issues
You can set environment variables for all users of your config by setting for example the 'enironment/FOO' config key which defined the \$FOO environment variable
You may specify custom tips specific to your config by adding to the 'tips/custom' config key one tip per line
You may specify specific versions of services by setting an environment variable such as \$DAB_SERVICES_VAULT_TAG to a valid docker tag for the vault docker image for example
You may specify specific versions of tools by setting an environment variable such as \$DAB_SERVICES_KIBANA_TAG to a valid docker tag for the kibana docker image for example
Dab provides tab completion for bash, zsh, and fish which is automatically updated. For more information try 'dab completion'
Groups are a collection of other groups, services, repositories, and tools that get started in that order
Group dependencies are in First In First Out (FIFO) order making the top of the list the first to run
To view the history of dab run 'dab changelog'
Every subcommand accepts '-h' or '--help' or just 'help' to display usage information
Every subcommand accepts '-v' or '--version' or just 'version' to display version and machine information
Should you wish to wipe your public key infrustructure and certificate authority and start fresh you may run 'dab pki destroy'
x509 Certificates are stored in the dab config for example the key 'pki/ca/certificate' for the certificate authority
If you are running the built in influxdb service then all dab runs will be recorded as metric annotations
Tools and Services can be updated to their latest image with 'dab tools update' and 'dab services update' respectively
When a group is started all services and tools it depends on are first checked for updates
Some Tools require specific services to be running, if so they will display it in 'dab tools list'
Check the running service's statuses with 'dab services status'
Check the running tools's statuses with 'dab tools status'
Check the running service's logs with 'dab services logs'
Check the running tools's logs with 'dab tools logs'
"

get_tip_corpus() {
echo "$TIPS" | sed '/^\s*$/d' | awk '{ print "[tips:dab] " $0 }'
config_get tips/custom | sed '/^\s*$/d' | awk '{ print "[tips:custom] " $0 }'
}

get_tip() {
get_tip_corpus | sed '/^\s*$/d' | shuf -n 1
}

echo_color "$COLOR_PURPLE" "$(get_tip)!"
2 changes: 1 addition & 1 deletion app/subcommands/tools/list
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set -euf
# shellcheck disable=SC1091
. ./lib/compose.sh

get_compose_service_rows 'tools' | column -s'`' -o' | ' -t -N TOOL,DESCRIPTION,USERNAME,PASSWORD -R TOOL
get_compose_service_rows 'tools' | column -s'`' -o' | ' -t -N 'TOOL,DESCRIPTION,REQUIRED SERVICES,USERNAME,PASSWORD' -R TOOL
1 change: 1 addition & 0 deletions completion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var dab = complete.Command{
},
},
"shell": {}, "sh": {}, "cmd": {},
"tip": {},
"update": {}, "upgrade": {},
"changelog": {}, "changes": {},
},
Expand Down
18 changes: 18 additions & 0 deletions tests/features/misc.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,21 @@ Feature: Docker entrypoint wrapper script works
* 13782eb|↓|Use tests tag for tests image to match docker hub tags <Taylor Nekroze Lawson>
* 25276b8|↓|Improve docker caching <Taylor Nekroze Lawson>
"""

Scenario: Dab tip subcommand displays useful tips
With no custom tips defined

Given I successfully run `dab config set tips/custom`

When I run `dab tip`

Then it should pass with "[tips:dab]"

Scenario: Displays a tip periodically
With no custom tips defined

Given I successfully run `dab config set tips/custom`

When I run `dab config set tips/last`

Then it should pass with "[tips:dab]"
2 changes: 1 addition & 1 deletion tests/features/services.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Subcommand: dab services
Containers can be fast... but not over
Australian internet.

Given the aruba exit timeout is 120 seconds
Given the aruba exit timeout is 300 seconds

Scenario: Can list all available services
When I run `dab services list`
Expand Down
2 changes: 1 addition & 1 deletion tests/features/tools.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Feature: Subcommand: dab tools
Containers can be fast... but not over
Australian internet.

Given the aruba exit timeout is 120 seconds
Given the aruba exit timeout is 300 seconds

Scenario: Can list all available tools
When I run `dab tools list`
Expand Down

0 comments on commit 3d9631d

Please sign in to comment.