Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
92c91ddbb0 | |||
cff9b13f60 | |||
0444991636 | |||
28ba33b18e | |||
77eb83b128 | |||
ff7fcf2201 | |||
b0d525a980 | |||
aa1ffd5d8a | |||
5627e67bf7 | |||
29343369f3 | |||
427ed97678 | |||
b01fee3c86 | |||
949246821f | |||
60f2892acd | |||
0268685cfa | |||
dd4f31d9a1 |
@ -7,7 +7,7 @@ steps:
|
|||||||
commands:
|
commands:
|
||||||
- apt update
|
- apt update
|
||||||
- apt install -y shellcheck
|
- apt install -y shellcheck
|
||||||
- shellcheck abra installer
|
- shellcheck abra script.d/*
|
||||||
trigger:
|
trigger:
|
||||||
branch:
|
branch:
|
||||||
- main
|
- main
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
# abra 0.3.0 (2020-09-27)
|
||||||
|
|
||||||
|
- Add multilogs stack logs implementation ([#8](https://git.autonomic.zone/compose-stacks/abra/issues/8)
|
||||||
|
- Add beginnings of "monorepo" functionality
|
||||||
|
|
||||||
|
# abra 0.2.0 (2020-09-24)
|
||||||
|
|
||||||
|
- Prepare for swarm install script using script.d ([#12](https://git.autonomic.zone/compose-stacks/planning/issues/12))
|
||||||
|
|
||||||
# abra 0.1.2 (2020-09-22)
|
# abra 0.1.2 (2020-09-22)
|
||||||
|
|
||||||
- Add upgrade command ([#10](https://git.autonomic.zone/autonomic-cooperative/abra/issues/10))
|
- Add upgrade command ([#10](https://git.autonomic.zone/autonomic-cooperative/abra/issues/10))
|
||||||
|
@ -24,7 +24,7 @@ cd abra
|
|||||||
make dev_install
|
make dev_install
|
||||||
```
|
```
|
||||||
|
|
||||||
See [autonomic-cooperative/installer-scripts](https://git.autonomic.zone/autonomic-cooperative/installer-scripts) for the installer script deployment. To make a release, just add an entry to [CHANGELOG.md](./CHANGELOG.md) and the [installer](./installer) (following [semver](https://semver.org/) please) and then `git tag x.x.x && git push origin main --tags`. If you want the [installer-scripts](https://git.autonomic.zone/autonomic-cooperative/installer-scripts) deployment to pick that up, you'll need to change the version number in the [Makefile](https://git.autonomic.zone/autonomic-cooperative/installer-scripts/src/branch/main/Makefile) and run `make` in that repository and push the changes.
|
See [autonomic-cooperative/installer-scripts](https://git.autonomic.zone/autonomic-cooperative/installer-scripts) for the installer script deployment. To make a release, just add an entry to [CHANGELOG.md](./CHANGELOG.md) (following [semver](https://semver.org/) please) and then `git tag x.x.x && git push origin main --tags`. If you want the [installer-scripts](https://git.autonomic.zone/autonomic-cooperative/installer-scripts) deployment to pick that up, you'll need to change the version number in the [Makefile](https://git.autonomic.zone/autonomic-cooperative/installer-scripts/src/branch/main/Makefile) and run `make` in that repository and push the changes.
|
||||||
|
|
||||||
## Specify what to deploy where
|
## Specify what to deploy where
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ You can use `abra` in one of 2 ways:
|
|||||||
2. "Monorepo mode": keep all your `compose-stack`s in one directory and all your `env` files in
|
2. "Monorepo mode": keep all your `compose-stack`s in one directory and all your `env` files in
|
||||||
another, e.g.:
|
another, e.g.:
|
||||||
```
|
```
|
||||||
$ tree
|
$ tree
|
||||||
.
|
.
|
||||||
├── apps
|
├── apps
|
||||||
│ ├── mediawiki.demo.autonomic.zone.env
|
│ ├── mediawiki.demo.autonomic.zone.env
|
||||||
@ -48,8 +48,8 @@ You can use `abra` in one of 2 ways:
|
|||||||
├── swarmpit
|
├── swarmpit
|
||||||
├── traefik
|
├── traefik
|
||||||
└── wordpress
|
└── wordpress
|
||||||
$ abra -e apps/mediawiki.demo.autonomic.zone.env deploy
|
$ abra -e apps/mediawiki.demo.autonomic.zone.env deploy
|
||||||
```
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
|
90
abra
90
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")
|
||||||
|
|
||||||
@ -57,6 +53,10 @@ warning() {
|
|||||||
echo "$(tput setaf 3)WARNING: $*$(tput sgr0)"
|
echo "$(tput setaf 3)WARNING: $*$(tput sgr0)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
success() {
|
||||||
|
echo "$(tput setaf 2)$*$(tput sgr0)"
|
||||||
|
}
|
||||||
|
|
||||||
###### Top-level arguments
|
###### Top-level arguments
|
||||||
|
|
||||||
ABRA_CONFIG=abra.yml
|
ABRA_CONFIG=abra.yml
|
||||||
@ -78,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
|
||||||
@ -86,7 +88,7 @@ fi
|
|||||||
|
|
||||||
if [ -n "$ABRA_ENV" ]; then
|
if [ -n "$ABRA_ENV" ]; then
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$ABRA_ENV"
|
source "$ABRA_ENV" || error "Unable to load env from '$ABRA_ENV'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###### Default settings
|
###### Default settings
|
||||||
@ -102,12 +104,26 @@ fi
|
|||||||
load_context() {
|
load_context() {
|
||||||
if [ -z "$DOCKER_CONTEXT" ]; then
|
if [ -z "$DOCKER_CONTEXT" ]; then
|
||||||
warning "\$DOCKER_CONTEXT not set, (slowly) looking it up"
|
warning "\$DOCKER_CONTEXT not set, (slowly) looking it up"
|
||||||
|
# shellcheck disable=SC2063
|
||||||
DOCKER_CONTEXT=$(docker context ls | grep '*' | cut -d' ' -f1)
|
DOCKER_CONTEXT=$(docker context ls | grep '*' | cut -d' ' -f1)
|
||||||
|
# FIXME 3wc: make sure grep doesn't parse this, we're want a literal '*'
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
###### 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"
|
||||||
@ -141,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"
|
||||||
@ -155,28 +172,42 @@ sub_help() {
|
|||||||
###### Subcommand `secret`
|
###### Subcommand `secret`
|
||||||
|
|
||||||
sub_secret_help() {
|
sub_secret_help() {
|
||||||
echo "Usage: $PROGRAM_NAME [-a STACK_NAME] secret <subcommand> [options]"
|
echo "Usage: $PROGRAM_NAME [global opts] secret <subcommand> [sub opts]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Subcommands:"
|
echo "Subcommands:"
|
||||||
echo " generate SECRET VERSION [PW] generate & store secret"
|
echo " generate SECRET VERSION [PWGEN] generate & store secret"
|
||||||
|
echo " insert SECRET VERSION PW save PW in docker and pass"
|
||||||
}
|
}
|
||||||
|
|
||||||
sub_secret_generate(){
|
sub_secret_insert() {
|
||||||
require_stack
|
require_stack
|
||||||
load_context
|
load_context
|
||||||
|
|
||||||
SECRET=$1
|
SECRET=$1
|
||||||
VERSION=$2
|
VERSION=$2
|
||||||
PW=${3:-pwqgen}
|
PW=$3
|
||||||
|
|
||||||
if [ -z "$SECRET" ] || [ -z "$VERSION" ]; then
|
if [ -z "$SECRET" ] || [ -z "$VERSION" ] || [ -z "$PW" ]; then
|
||||||
echo "Usage: $PROGRAM_NAME secret_generate SECRET VERSION"
|
echo "Usage: $PROGRAM_NAME secret insert SECRET VERSION PW"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$PW | tee \
|
echo "$PW" | docker secret create "${STACK_NAME}_${SECRET}_${VERSION}" - > /dev/null
|
||||||
>(docker secret create "${STACK_NAME}_${SECRET}_${VERSION}" -) \
|
echo "$PW" | pass insert "hosts/$DOCKER_CONTEXT/${STACK_NAME}/${SECRET}" -m > /dev/null
|
||||||
>(pass insert "hosts/$DOCKER_CONTEXT/${STACK_NAME}/${SECRET}" -m)
|
}
|
||||||
|
|
||||||
|
sub_secret_generate(){
|
||||||
|
SECRET=$1
|
||||||
|
VERSION=$2
|
||||||
|
PWGEN=${3:-pwqgen}
|
||||||
|
|
||||||
|
PW=$($PWGEN)
|
||||||
|
|
||||||
|
success "Password: $PW"
|
||||||
|
|
||||||
|
echo "sub_secret_insert \"$SECRET\" \"$VERSION\" \"$PW\""
|
||||||
|
exit
|
||||||
|
sub_secret_insert "$SECRET" "$VERSION" "$PW"
|
||||||
}
|
}
|
||||||
|
|
||||||
sub_secret() {
|
sub_secret() {
|
||||||
@ -197,7 +228,7 @@ sub_run_args(){
|
|||||||
shift 2
|
shift 2
|
||||||
|
|
||||||
if [ -z "$SERVICE" ]; then
|
if [ -z "$SERVICE" ]; then
|
||||||
echo "Usage: $PROGRAM_NAME run SERVICE [CMD]"
|
echo "Usage: $PROGRAM_NAME run SERVICE DOCKER_ARGS [CMD]"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -251,9 +282,9 @@ sub_deploy (){
|
|||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
if docker stack deploy -c ${COMPOSE_FILE/:/ -c } "$STACK_NAME"; then
|
if docker stack deploy -c ${COMPOSE_FILE/:/ -c } "$STACK_NAME"; then
|
||||||
if [ -n "$DOMAIN" ]; then
|
if [ -n "$DOMAIN" ]; then
|
||||||
echo "$(tput setaf 2)Yay! App should be available at https://${DOMAIN}$(tput sgr0)"
|
success "Yay! App should be available at https://${DOMAIN}"
|
||||||
else
|
else
|
||||||
echo "$(tput setaf 2)Yay! That worked. No \$DOMAIN defined, check logs.(tput sgr0)"
|
success "Yay! That worked. No \$DOMAIN defined, check logs."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
error "Oh no! Something went wrong 😕 Check errors above"
|
error "Oh no! Something went wrong 😕 Check errors above"
|
||||||
@ -263,11 +294,34 @@ sub_deploy (){
|
|||||||
|
|
||||||
###### Subcommand `logs`
|
###### Subcommand `logs`
|
||||||
|
|
||||||
|
# Inspired by https://github.com/moby/moby/issues/31458#issuecomment-475411564
|
||||||
|
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
|
||||||
@ -320,7 +374,7 @@ sub_cp() {
|
|||||||
###### Subcommand `context`
|
###### Subcommand `context`
|
||||||
|
|
||||||
sub_context_help() {
|
sub_context_help() {
|
||||||
echo "Usage: $PROGRAM_NAME [-a STACK_NAME] context <subcommand> [options]"
|
echo "Usage: $PROGRAM_NAME [global opts] context <subcommand> [sub opts]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Subcommands:"
|
echo "Subcommands:"
|
||||||
echo " init HOST [USER] [PORT] set up remote Docker context"
|
echo " init HOST [USER] [PORT] set up remote Docker context"
|
||||||
|
16
script.d/swarm-installer
Executable file
16
script.d/swarm-installer
Executable file
@ -0,0 +1,16 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
install_docker() {
|
||||||
|
echo "install_docker: TODO"
|
||||||
|
}
|
||||||
|
init_swarm() {
|
||||||
|
echo "init_swarm: TODO"
|
||||||
|
}
|
||||||
|
|
||||||
|
run_installation() {
|
||||||
|
install_docker
|
||||||
|
init_swarm
|
||||||
|
}
|
||||||
|
|
||||||
|
run_installation
|
||||||
|
exit 0
|
Reference in New Issue
Block a user