- Clone Juggler
git clone https://github.com/daniel-lerch/juggler.git /opt/juggler - Configure environment variables
sudo cp /opt/juggler/res/juggler.sh /etc/profile.d/ - Copy Systemd unit files
sudo cp /opt/juggler/res/juggler.timer /opt/juggler/res/juggler.service /etc/systemd/system/ - Enable Systemd timer
sudo systemctl enable --now juggler.timer - Copy Systemd user files
cp /opt/juggler/res/juggler.user.timer /opt/juggler/res/juggler.user.service /home/USER/.config/systemd/user - Adjust paths in service
vi /home/USER/.config/systemd/user/juggler.user.service - Enable Systemd user timer
systemctl --user enable --now juggler.user.timer
Juggler simpfies management of Docker Compose services by using common patterns and providing tools.
Applications are split into groups which reside in /opt/<group-name>.
Within its group, each application is located in its own subfolder with a docker-compose.yml or juggler.sh file.
Juggler can manage manage backups for arbitrary applications but we will focus on Docker Compose here.
To use an existing Compose file with Juggler, no changes are required.
Just run app up and Juggler will take care of Docker Compose settings and provide you a simple backup mechanism.
With a juggler.sh file you can add custom commands as functions with a cmd_ prefix.
Any variables you set will be available in the Compose file with the ${BASH_VARIABLE_NAME} syntax.
Technically, Juggler scans a Compose file for variable names and adds them from Bash to a generated .env file.
Juggler consists out of four main components:
bin/appthe bootstrapper executablelib/core.shthe core modulelib/compose.shthe Docker Compose modulelib/backup.shthe Borg Backup module
Major challenges with Bash for a complex framework like Juggler
- Parse variables from
docker-compose.ymlfiles. Solution: Implemented in an external Python script. - Juggler cannot iterate through multiple apps because of dangling variables. Solution: Start an own Juggler process for each app.
- Creating a good help overview requires lots of additional functions. Solution: Only show compose commands and backup module.
- For multiple apps it is hard to determine whether a command is available. Solution: Only allow certain command for batch execution.
Exposed variables:
PROJECT_DIRe.g. /opt/global/nginxPROJECT_DIR_UIDe.g. rootPROJECT_DIR_GIDe.g. rootPROJECT_NAMEe.g. nginxPROJECT_GROUPe.g. globalPROJECT_TITLEe.g. global/nginxPROJECT_FULLNAMEe.g. global-nginx
Optional variables:
JUGGLER_CONFIG_FILEJUGGLER_PROJECT_PATHdefaults to ~/apps
Exposed variables:
COMPOSE_PROJECT_NAMEalias for PROJECT_FULLNAMECOMPOSE_FILEe.g. /opt/global/nginx/docker-compose.ymlAPP_CONTAINER_NAMEe.g. global-nginx-app
Optional variables (for execdb command):
MYSQL_DATABASEMYSQL_USERMYSQL_PASSWORD
Other optional variables:
DOCKER_CONTEXT
Exposed functions:
invoke_compose()Invokes docker-compose with all required options
Optional callbacks:
update_images()(optional callback) Builds custom images and pull images
Exposed variables (change to customize behavior):
BACKUP_DIRSe.g. /opt/global/nginxBACKUP_EXCLUDEe.g. /opt/global/nginx/log /opt/global/nginx/.envBACKUP_PRUNEe.g. --keep-within=7d --keep-weekly=4 --keep-monthly=12BACKUP_CRONJOBe.g. 0 (disabled) or 1 (enabled)
Optional variables (for automatic MySQL dumps to /var/opt/backup):
MYSQL_DATABASEMYSQL_ROOT_PASSWORD
Optional callbacks:
prepare_backup()Exports data before Borg backup starts
Nextcloud (located in /opt/church/nextcloud)
juggler.shCustom functions and environment variables
APP_IMAGE=nextcloud:latest
DB_IMAGE=mariadb:latest
DB_CONTAINER_NAME=$COMPOSE_PROJECT_NAME-db
MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
MYSQL_PASSWORD=password
function cmd_execw() {
invoke_composer exec -u www-data app bash
}.envEnvironment file generated by Jugglerdocker-compose.ymlCompose file template using variables
version: '2.1'
services:
app:
image: ${APP_IMAGE}
container_name: ${APP_CONTAINER_NAME}
environment:
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_HOST=db
db:
image: ${DB_IMAGE}
container_name: ${DB_CONTAINER_NAME}
environment:
- MYSQL_ROOT_PASSWORD
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD- $JUGGLER_CONFIG_FILE Global Juggler config file
ENABLE_PROJECT_GROUPS=1
# Change this variable to set custom default backup target
BACKUP_TARGET_DEFAULT="/var/opt/backup"
BACKUP_TARGET_DEFAULT_ENCRYPTION="none"
BACKUP_TARGET_DEFAULT_PASSPHRASE=""
# Add additional targets that can be selected manually
BACKUP_TARGET_REMOTE="backup@example.com:/var/opt/backup"
BACKUP_TARGET_REMOTE_ENCRYPTION="repokey"
BACKUP_TARGET_REMOTE_PASSPHRASE="password"