Compare commits

..

61 Commits

Author SHA1 Message Date
Jose Diaz-Gonzalez
f3ba0d51f6 Release 1.4.10 2018-12-02 16:17:52 -05:00
Jose Diaz-Gonzalez
39a7864022 fix: correct issues where docker ps is truncated
This should actually be refactored to avoid the grep call completely, but the current fix will correct the issue for now.

Refs dokku/dokku-postgres#131
2018-12-02 14:29:24 -05:00
Jose Diaz-Gonzalez
8061f0c50a fix: correct issues where docker ps is truncated
This should actually be refactored to avoid the grep call completely, but the current fix will correct the issue for now.

Refs dokku/dokku-postgres#131
2018-12-02 05:21:10 -05:00
Jose Diaz-Gonzalez
aa1a23d5a1 fix: ensure any backup cron files are deleted when the service is destroyed
Closes dokku/dokku-redis#118
2018-12-02 05:10:06 -05:00
Jose Diaz-Gonzalez
5e5ad6d472 fix: clean up backup containers after use
Closes dokku/dokku#104
2018-12-02 04:46:52 -05:00
Jose Diaz-Gonzalez
733e14ee73 fix: correct documentation around the passphrase parameter
Closes dokku/dokku-mysql#101
2018-12-02 04:33:58 -05:00
Jose Diaz-Gonzalez
fc018c65f1 Release 1.4.9 2018-10-11 14:53:12 -04:00
Jose Diaz-Gonzalez
598ea1f526 fix: correct issue where help output isnt colorized by default 2018-10-11 14:20:03 -04:00
Jose Diaz-Gonzalez
b7724b826c fix: correct issues in upgrade and fix tests 2018-10-11 14:16:47 -04:00
Jose Diaz-Gonzalez
0cee8bd31a Release 1.4.8 2018-10-11 00:05:24 -04:00
Jose Diaz-Gonzalez
765f44dcfe feat: skip upgrade if service is already up to date 2018-10-11 00:04:52 -04:00
Jose Diaz-Gonzalez
c9ea129035 Release 1.4.7 2018-10-10 23:54:38 -04:00
Jose Diaz-Gonzalez
00b290346e feat: allow removal of header from :list subcommand 2018-10-10 23:54:08 -04:00
Jose Diaz-Gonzalez
d40e5bbb35 Release 1.4.6 2018-10-10 23:48:44 -04:00
Jose Diaz-Gonzalez
4689d223b6 fix: respect various ways of not wanting 'fancy' output.
Closes dokku/dokku-daemon#19
Closes dokku/dokku-daemon#22
2018-10-10 23:47:46 -04:00
Jose Diaz-Gonzalez
0a7f86a21b Release 1.4.5 2018-10-10 23:32:25 -04:00
Jose Diaz-Gonzalez
c96d25706b fix: ensure flags are properly represented in help output 2018-10-10 23:31:52 -04:00
Jose Diaz-Gonzalez
4624d5a790 Release 1.4.4 2018-10-10 23:27:27 -04:00
Jose Diaz-Gonzalez
5887a018d0 fix: correct issue where temp help output files were being placed in incorrect directory 2018-10-10 23:23:10 -04:00
Jose Diaz-Gonzalez
bbe8fee561 Release 1.4.3 2018-10-10 23:18:32 -04:00
Jose Diaz-Gonzalez
5f2e184d68 feat: add support for restarting containers to ensure links continue to work properly when the application has resolved dns of the link 2018-10-10 23:14:45 -04:00
Jose Diaz-Gonzalez
8a8857374c fix: handle case where container being removed does not exist 2018-10-10 22:03:44 -04:00
Jose Diaz-Gonzalez
2176ab836e Release 1.4.2 2018-10-10 03:03:32 -04:00
Jose Diaz-Gonzalez
1c35653e7e fix: correct short-flag for image-version and custom-env 2018-10-10 03:02:56 -04:00
Jose Diaz-Gonzalez
7c17773fb2 Release 1.4.1 2018-10-10 03:01:09 -04:00
Jose Diaz-Gonzalez
980e7d1650 fix: correct name for upgrade flags in help output 2018-10-10 03:00:22 -04:00
Jose Diaz-Gonzalez
64394619b5 Release 1.4.0 2018-10-10 02:59:16 -04:00
Jose Diaz-Gonzalez
a39ade3161 chore: correct verbiage around upgrades 2018-10-10 02:54:34 -04:00
Jose Diaz-Gonzalez
20dd893a77 fix: pass correct variable for upgrade command 2018-10-10 02:49:30 -04:00
Jose Diaz-Gonzalez
e089d0d03d fix: correct check for existing image 2018-10-10 02:42:43 -04:00
Jose Diaz-Gonzalez
ab9da6349e fix: do not force-set plugin image and version to existing image and version 2018-10-10 02:39:10 -04:00
Jose Diaz-Gonzalez
c2ed798db0 chore: remove unnecessary call 2018-10-10 02:32:59 -04:00
Jose Diaz-Gonzalez
63fc31807c Merge pull request #100 from dokku/upgrade-service-image-version
feat: add ability to upgrade service image and image-version
2018-10-10 02:10:39 -04:00
Jose Diaz-Gonzalez
284ffa3177 feat: add ability to upgrade service image and image-version 2018-10-10 00:13:59 -04:00
Jose Diaz-Gonzalez
265410e5e5 Release 1.3.0 2018-07-21 16:34:13 -04:00
Jose Diaz-Gonzalez
e07b387d86 feat: add command to list linked services for a given app 2018-07-21 16:31:55 -04:00
Jose Diaz-Gonzalez
a5d5b4a22d fix: properly set SERVICE_ALIAS 2018-04-24 15:05:50 -04:00
Jose Diaz-Gonzalez
e10ab542af fix: add tests for custom link aliases 2018-04-24 13:21:30 -04:00
Jose Diaz-Gonzalez
57956e0dad feat: properly handle custom aliases and error states for alias usage when calling link subcommand. Refs dokku/dokku-redis#64 2018-04-24 03:21:55 -04:00
Jose Diaz-Gonzalez
0b44cd050b fix: correct test 2018-04-24 03:03:48 -04:00
Jose Diaz-Gonzalez
c83e0a56d2 refactor: make variable as dns hostname more clear 2018-04-24 02:54:46 -04:00
Jose Diaz-Gonzalez
0bcd62459d fix: remove an infinite loop. Refs dokku/dokku-redis#64 2018-04-24 02:18:26 -04:00
Jose Diaz-Gonzalez
4b8b0c4bd5 feat: implement link querystring flags. Refs dokku/dokku-redis#64 2018-04-24 01:40:21 -04:00
Jose Diaz-Gonzalez
7ec808d9f6 feat: implement clone flags. Closes dokku/dokku-redis#105 2018-04-24 00:57:16 -04:00
Jose Diaz-Gonzalez
02b0c1c7f9 refactor: move unimplemented command detection into config file 2018-04-24 00:27:17 -04:00
Jose Diaz-Gonzalez
84b62938da Release 1.2.7 2018-04-23 18:25:47 -04:00
Jose Diaz-Gonzalez
6b25da8d43 fix: use assert_contains 2018-04-23 18:25:47 -04:00
Jose Diaz-Gonzalez
2405f5f687 Release 1.2.6 2018-04-23 18:14:29 -04:00
Jose Diaz-Gonzalez
25dc385f6b feat: plugins are no longer beta 2018-04-23 18:14:29 -04:00
Jose Diaz-Gonzalez
6a35b0881b Release 1.2.5 2018-04-23 18:11:26 -04:00
Jose Diaz-Gonzalez
9d09589942 fix: set SERVICE_ROOT variable for backups 2018-04-23 18:11:26 -04:00
Jose Diaz-Gonzalez
e05ea7c0bb Release 1.2.4 2018-04-23 18:08:31 -04:00
Jose Diaz-Gonzalez
6fe4c6527e fix: set ID variable for backups 2018-04-23 18:08:31 -04:00
Jose Diaz-Gonzalez
0c1b33bd8e Release 1.2.3 2018-04-23 17:36:48 -04:00
Jose Diaz-Gonzalez
2de0a04ba8 chore: standardize on single method of setting backup root. Refs dokku/dokku-redis#91 2018-04-23 17:36:48 -04:00
Jose Diaz-Gonzalez
22d0b5bd8b Release 1.2.2 2018-04-23 17:11:37 -04:00
Jose Diaz-Gonzalez
46d1ac785c fix: properly handle use-iam flag. Closes dokku/dokku-redis#88 2018-04-23 17:11:37 -04:00
Jose Diaz-Gonzalez
6b6f635386 Release 1.2.1 2018-04-23 15:52:07 -04:00
Jose Diaz-Gonzalez
cfb9e508da fix: silence errors when a container does not exist. Closes dokku/dokku-redis#85 2018-04-23 15:52:07 -04:00
Jose Diaz-Gonzalez
1d25c671bb Release 1.2.0 2018-04-23 14:39:27 -04:00
Jose Diaz-Gonzalez
77c64b4045 feat: create backup-schedule-cat subcommand 2018-04-23 14:39:26 -04:00
28 changed files with 392 additions and 130 deletions

View File

@@ -1,4 +1,4 @@
Copyright (C) 2015 Jose Diaz-Gonzalez
Copyright (C) 2018 Jose Diaz-Gonzalez
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View File

@@ -1,4 +1,4 @@
# dokku mysql (beta) [![Build Status](https://img.shields.io/travis/dokku/dokku-mysql.svg?branch=master "Build Status")](https://travis-ci.org/dokku/dokku-mysql) [![IRC Network](https://img.shields.io/badge/irc-freenode-blue.svg "IRC Freenode")](https://webchat.freenode.net/?channels=dokku)
# dokku mysql [![Build Status](https://img.shields.io/travis/dokku/dokku-mysql.svg?branch=master "Build Status")](https://travis-ci.org/dokku/dokku-mysql) [![IRC Network](https://img.shields.io/badge/irc-freenode-blue.svg "IRC Freenode")](https://webchat.freenode.net/?channels=dokku)
Official mysql plugin for dokku. Currently defaults to installing [mysql 5.7.12](https://hub.docker.com/_/mysql/).
@@ -17,13 +17,15 @@ sudo dokku plugin:install https://github.com/dokku/dokku-mysql.git mysql
## commands
```
mysql:app-links <app> List all mysql service links for a given app
mysql:backup <name> <bucket> (--use-iam) Create a backup of the mysql service to an existing s3 bucket
mysql:backup-auth <name> <aws_access_key_id> <aws_secret_access_key> (<aws_default_region>) (<aws_signature_version>) (<endpoint_url>) Sets up authentication for backups on the mysql service
mysql:backup-deauth <name> Removes backup authentication for the mysql service
mysql:backup-schedule <name> <schedule> <bucket> Schedules a backup of the mysql service
mysql:backup-set-encryption <name> <encryption_key>, Sets up GPG encryption for future backups of the mysql service
mysql:backup-schedule-cat <name> Cat the contents of the configured backup cronfile for the service
mysql:backup-set-encryption <name> <passphrase> Set a GPG passphrase for backups
mysql:backup-unschedule <name> Unschedules the backup of the mysql service
mysql:backup-unset-encryption <name>, Removes backup encryption for future backups of the mysql service
mysql:backup-unset-encryption <name> Removes backup encryption for future backups of the mysql service
mysql:clone <name> <new-name> Create container <new-name> then copy data from <name> into <new-name>
mysql:connect <name> Connect via mysql to a mysql service
mysql:create <name> Create a mysql service with environment variables
@@ -44,6 +46,7 @@ mysql:start <name> Start a previously stopped mysql service
mysql:stop <name> Stop a running mysql service
mysql:unexpose <name> Unexpose a previously exposed mysql service
mysql:unlink <name> <app> Unlink the mysql service from the app
mysql:upgrade <name> Upgrade service <service> to the specified version
```
## usage
@@ -217,6 +220,9 @@ dokku mysql:backup lolipop BUCKET_NAME
# CRON_SCHEDULE is a crontab expression, eg. "0 3 * * *" for each day at 3am
dokku mysql:backup-schedule lolipop CRON_SCHEDULE BUCKET_NAME
# cat the contents of the configured backup cronfile for the service
dokku mysql:backup-schedule-cat lolipop
# remove the scheduled backup from cron
dokku mysql:backup-unschedule lolipop
```

View File

@@ -59,7 +59,7 @@ is_container_status() {
declare desc="Returns 0 or 1 depending upon whether a given container has a certain status"
declare CID="$1" STATUS="$2"
local TEMPLATE="{{.State.$STATUS}}"
local CONTAINER_STATUS=$(docker inspect -f "$TEMPLATE" "$CID" || true)
local CONTAINER_STATUS=$(docker inspect -f "$TEMPLATE" "$CID" 2> /dev/null || true)
if [[ "$CONTAINER_STATUS" == "true" ]]; then
return 0
@@ -67,6 +67,22 @@ is_container_status() {
return 1
}
is_implemented_command() {
declare desc="return true if value ($1) is in list (all other arguments)"
declare CMD="$1"
CMD="$(echo "$CMD" | cut -d ':' -f2)"
if [[ ${#PLUGIN_UNIMPLEMENTED_SUBCOMMANDS[@]} -eq 0 ]]; then
return 0
fi
local e
for e in "${PLUGIN_UNIMPLEMENTED_SUBCOMMANDS[@]}"; do
[[ "$e" == "$CMD" ]] && return 1
done
return 0
}
remove_from_links_file() {
declare desc="Removes an app from the service link file"
declare SERVICE="$1" APP="$2"
@@ -79,7 +95,7 @@ remove_from_links_file() {
sort "$LINKS_FILE" -u -o "$LINKS_FILE"
}
service_alias() {
service_dns_hostname() {
declare desc="Retrieves the alias of a service"
declare SERVICE="$1"
local SERVICE_NAME="$(get_service_name "$SERVICE")"
@@ -92,9 +108,7 @@ service_alternative_alias() {
local COLORS=(AQUA BLACK BLUE FUCHSIA GRAY GREEN LIME MAROON NAVY OLIVE PURPLE RED SILVER TEAL WHITE YELLOW)
local ALIAS;
while [[ -z $ALIAS ]]; do
local IDX=$((RANDOM % ${#COLORS[*]}))
local COLOR=${COLORS[IDX]}
for COLOR in "${COLORS[@]}"; do
ALIAS="${PLUGIN_ALT_ALIAS}_${COLOR}"
local IN_USE=$(echo "$EXISTING_CONFIG" | grep "${ALIAS}_URL")
if [[ -n $IN_USE ]]; then
@@ -104,26 +118,47 @@ service_alternative_alias() {
echo "$ALIAS"
}
service_app_links() {
declare desc="Outputs all service links for a given app"
declare APP="$1"
local SERVICE LINKED_APP
pushd "$PLUGIN_DATA_ROOT" > /dev/null
for SERVICE in *; do
[[ -f "$SERVICE/LINKS" ]] || continue
for LINKED_APP in $(<"$SERVICE/LINKS"); do
if [[ "$LINKED_APP" == "$APP" ]] ; then
echo "$SERVICE"
fi
done
done
}
service_backup() {
declare desc="Creates a backup of a service to an existing s3 bucket"
declare SERVICE="$1" BUCKET_NAME="$2" USE_IAM_OPTIONAL_FLAG="$3"
local BACKUP_CONFIG_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup"
local SERVICE_BACKUP_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup"
local BACKUP_ENCRYPTION_CONFIG_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup-encryption"
local AWS_ACCESS_KEY_ID_FILE="$BACKUP_CONFIG_ROOT/AWS_ACCESS_KEY_ID"
local AWS_SECRET_ACCESS_KEY_FILE="$BACKUP_CONFIG_ROOT/AWS_SECRET_ACCESS_KEY"
local AWS_ACCESS_KEY_ID_FILE="$SERVICE_BACKUP_ROOT/AWS_ACCESS_KEY_ID"
local AWS_SECRET_ACCESS_KEY_FILE="$SERVICE_BACKUP_ROOT/AWS_SECRET_ACCESS_KEY"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID="$(cat "$SERVICE_ROOT/ID")"
local BACKUP_PARAMETERS=""
if [[ "$USE_IAM_OPTIONAL_FLAG" != "--use-iam" ]] && [[ "$USE_IAM_OPTIONAL_FLAG" != "-u" ]]; then
if [[ -z "$USE_IAM_OPTIONAL_FLAG" ]]; then
[[ ! -f "$AWS_ACCESS_KEY_ID_FILE" ]] && dokku_log_fail "Missing AWS_ACCESS_KEY_ID file"
[[ ! -f "$AWS_SECRET_ACCESS_KEY_FILE" ]] && dokku_log_fail "Missing AWS_SECRET_ACCESS_KEY file"
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_ACCESS_KEY_ID=$(cat "$AWS_ACCESS_KEY_ID_FILE") -e AWS_SECRET_ACCESS_KEY=$(cat "$AWS_SECRET_ACCESS_KEY_FILE")"
else
elif [[ "$USE_IAM_OPTIONAL_FLAG" != "--use-iam" ]] && [[ "$USE_IAM_OPTIONAL_FLAG" != "-u" ]]; then
dokku_log_fail "Provide AWS credentials or use the --use-iam flag"
fi
TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT
docker inspect "$ID" &> /dev/null || dokku_log_fail "Service container does not exist"
is_container_status "$ID" "Running" || dokku_log_fail "Service container is not running"
(service_export "$SERVICE" > "${TMPDIR}/export")
# Build parameter list for s3backup tool
@@ -131,16 +166,16 @@ service_backup() {
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e BACKUP_NAME=${PLUGIN_COMMAND_PREFIX}-${SERVICE}"
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -v ${TMPDIR}:/backup"
if [[ -f "$BACKUP_CONFIG_ROOT/AWS_DEFAULT_REGION" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_DEFAULT_REGION=$(cat "$BACKUP_CONFIG_ROOT/AWS_DEFAULT_REGION")"
if [[ -f "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_DEFAULT_REGION=$(cat "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION")"
fi
if [[ -f "$BACKUP_CONFIG_ROOT/AWS_SIGNATURE_VERSION" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_SIGNATURE_VERSION=$(cat "$BACKUP_CONFIG_ROOT/AWS_SIGNATURE_VERSION")"
if [[ -f "$SERVICE_BACKUP_ROOT/AWS_SIGNATURE_VERSION" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_SIGNATURE_VERSION=$(cat "$SERVICE_BACKUP_ROOT/AWS_SIGNATURE_VERSION")"
fi
if [[ -f "$BACKUP_CONFIG_ROOT/ENDPOINT_URL" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e ENDPOINT_URL=$(cat "$BACKUP_CONFIG_ROOT/ENDPOINT_URL")"
if [[ -f "$SERVICE_BACKUP_ROOT/ENDPOINT_URL" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e ENDPOINT_URL=$(cat "$SERVICE_BACKUP_ROOT/ENDPOINT_URL")"
fi
if [[ -f "$BACKUP_ENCRYPTION_CONFIG_ROOT/ENCRYPTION_KEY" ]]; then
@@ -148,29 +183,28 @@ service_backup() {
fi
# shellcheck disable=SC2086
docker run $BACKUP_PARAMETERS dokkupaas/s3backup:0.8.0
docker run --rm $BACKUP_PARAMETERS dokkupaas/s3backup:0.8.0
}
service_backup_auth() {
declare desc="Sets up authentication"
declare SERVICE="$1" AWS_ACCESS_KEY_ID="$2" AWS_SECRET_ACCESS_KEY="$3" AWS_DEFAULT_REGION="$4" AWS_SIGNATURE_VERSION="$5" ENDPOINT_URL="$6"
local SERVICE_ROOT="${PLUGIN_DATA_ROOT}/${SERVICE}"
local SERVICE_BACKUP_ROOT="${SERVICE_ROOT}/backup/"
local SERVICE_BACKUP_ROOT="$PLUGIN_DATA_ROOT/$SERVICE/backup"
mkdir -p "$SERVICE_BACKUP_ROOT"
echo "$AWS_ACCESS_KEY_ID" > "${SERVICE_BACKUP_ROOT}/AWS_ACCESS_KEY_ID"
echo "$AWS_SECRET_ACCESS_KEY" > "${SERVICE_BACKUP_ROOT}/AWS_SECRET_ACCESS_KEY"
echo "$AWS_ACCESS_KEY_ID" > "$SERVICE_BACKUP_ROOT/AWS_ACCESS_KEY_ID"
echo "$AWS_SECRET_ACCESS_KEY" > "$SERVICE_BACKUP_ROOT/AWS_SECRET_ACCESS_KEY"
if [[ -n "$AWS_DEFAULT_REGION" ]]; then
echo "$AWS_DEFAULT_REGION" > "${SERVICE_BACKUP_ROOT}/AWS_DEFAULT_REGION"
echo "$AWS_DEFAULT_REGION" > "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION"
fi
if [[ -n "$AWS_SIGNATURE_VERSION" ]]; then
echo "$AWS_SIGNATURE_VERSION" > "${SERVICE_BACKUP_ROOT}/AWS_SIGNATURE_VERSION"
echo "$AWS_SIGNATURE_VERSION" > "$SERVICE_BACKUP_ROOT/AWS_SIGNATURE_VERSION"
fi
if [[ -n "$ENDPOINT_URL" ]]; then
echo "$ENDPOINT_URL" > "${SERVICE_BACKUP_ROOT}/ENDPOINT_URL"
echo "$ENDPOINT_URL" > "$SERVICE_BACKUP_ROOT/ENDPOINT_URL"
fi
}
@@ -185,17 +219,33 @@ service_backup_deauth() {
service_backup_schedule() {
declare desc="schedules a backup of the service"
declare SERVICE="$1" SCHEDULE="$2" BUCKET_NAME="$3"
declare SERVICE="$1" SCHEDULE="$2" BUCKET_NAME="$3" USE_IAM_OPTIONAL_FLAG="$4"
local DOKKU_BIN="$(which dokku)"
local CRON_FILE="/etc/cron.d/dokku-${PLUGIN_COMMAND_PREFIX}-${SERVICE}"
local TMP_CRON_FILE="${PLUGIN_DATA_ROOT}/.TMP_CRON_FILE"
echo "${SCHEDULE} dokku ${DOKKU_BIN} ${PLUGIN_COMMAND_PREFIX}:backup ${SERVICE} ${BUCKET_NAME}" > "$TMP_CRON_FILE"
if [[ -n "$USE_IAM_OPTIONAL_FLAG" ]] && [[ "$USE_IAM_OPTIONAL_FLAG" != "--use-iam" ]] && [[ "$USE_IAM_OPTIONAL_FLAG" != "-u" ]]; then
dokku_log_fail "Invalid flag provided, only '--use-iam' allowed"
fi
echo "${SCHEDULE} dokku ${DOKKU_BIN} ${PLUGIN_COMMAND_PREFIX}:backup ${SERVICE} ${BUCKET_NAME} ${USE_IAM_OPTIONAL_FLAG}" > "$TMP_CRON_FILE"
sudo /bin/mv "$TMP_CRON_FILE" "$CRON_FILE"
sudo /bin/chown root:root "$CRON_FILE"
sudo /bin/chmod 644 "$CRON_FILE"
}
service_backup_schedule_cat() {
declare desc="cat the contents of the configured backup cronfile for the service"
declare SERVICE="$1"
local CRON_FILE="/etc/cron.d/dokku-${PLUGIN_COMMAND_PREFIX}-${SERVICE}"
if [[ ! -f "$CRON_FILE" ]]; then
dokku_log_fail "There is no scheduled backup for ${SERVICE}."
fi
cat "$CRON_FILE"
}
service_backup_unschedule() {
declare desc="unschedules the backup of the service"
declare SERVICE="$1"
@@ -223,14 +273,30 @@ service_backup_unset_encryption() {
rm -rf "$SERVICE_BACKUP_ENCRYPTION_ROOT"
}
service_container_rm() {
declare desc="Stops a service and removes the running container"
declare SERVICE="$1"
local SERVICE_NAME="$(get_service_name "$SERVICE")"
service_stop "$SERVICE"
local ID=$(docker inspect "$SERVICE_NAME" -f '{{ .ID }}' 2> /dev/null || true)
[[ -z "$ID" ]] && return 0
dokku_log_verbose_quiet "Removing container"
docker update --restart=no "$SERVICE_NAME" > /dev/null 2>&1
if ! docker rm "$SERVICE_NAME" > /dev/null 2>&1; then
dokku_log_fail "Unable to remove container for service $SERVICE"
fi
}
service_enter() {
declare desc="enters running app container of specified proc type"
declare SERVICE="$1" && shift 1
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID="$(cat "$SERVICE_ROOT/ID")"
docker inspect "$ID" &> /dev/null || dokku_log_fail "Container does not exist"
is_container_status "$ID" "Running" || dokku_log_fail "Container is not running"
docker inspect "$ID" &> /dev/null || dokku_log_fail "Service container does not exist"
is_container_status "$ID" "Running" || dokku_log_fail "Service container is not running"
local EXEC_CMD=""
has_tty && local DOKKU_RUN_OPTS+=" -i -t"
@@ -250,6 +316,17 @@ service_exposed_ports() {
done
}
service_image_exists() {
declare desc="Checks if the current image exists"
local IMAGE="$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
if [[ "$(docker images -q "$IMAGE" 2> /dev/null)" == "" ]]; then
return 1
fi
return 0
}
service_info() {
declare desc="Retrieves information about a given service"
declare SERVICE="$1" INFO_FLAG="$2"
@@ -312,9 +389,22 @@ service_link() {
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local EXISTING_CONFIG=$(config_all "$APP")
local LINK=$(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1) || true
local DEFAULT_ALIAS=$(echo "$EXISTING_CONFIG" | grep "${PLUGIN_DEFAULT_ALIAS}_URL") || true
local SERVICE_ALIAS=$(service_alias "$SERVICE")
local SERVICE_DNS_HOSTNAME=$(service_dns_hostname "$SERVICE")
local LINKS_FILE="$SERVICE_ROOT/LINKS"
local ALIAS="$PLUGIN_DEFAULT_ALIAS"
local DEFAULT_ALIAS
if [[ -n "$SERVICE_ALIAS" ]]; then
ALIAS="$SERVICE_ALIAS"
ALIAS_IN_USE=$(echo "$EXISTING_CONFIG" | grep "${ALIAS}_URL") || true
[[ -n "$ALIAS_IN_USE" ]] && dokku_log_fail "Specified alias $ALIAS already in use"
else
DEFAULT_ALIAS=$(echo "$EXISTING_CONFIG" | grep "${PLUGIN_DEFAULT_ALIAS}_URL") || true
if [[ -n "$DEFAULT_ALIAS" ]]; then
ALIAS=$(service_alternative_alias "$EXISTING_CONFIG")
fi
[[ -z "$ALIAS" ]] && dokku_log_fail "Unable to use default or generated URL alias"
fi
[[ -n $LINK ]] && dokku_log_fail "Already linked as $LINK"
mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory"
@@ -322,18 +412,14 @@ service_link() {
echo "$APP" >> "$LINKS_FILE"
sort "$LINKS_FILE" -u -o "$LINKS_FILE"
local ALIAS="$PLUGIN_DEFAULT_ALIAS"
if [[ -n $DEFAULT_ALIAS ]]; then
ALIAS=$(service_alternative_alias "$EXISTING_CONFIG")
fi
if declare -f -F add_passed_docker_option > /dev/null; then
# shellcheck disable=SC2034
local passed_phases=(build deploy run)
add_passed_docker_option passed_phases[@] "--link $SERVICE_NAME:$SERVICE_ALIAS"
add_passed_docker_option passed_phases[@] "--link $SERVICE_NAME:$SERVICE_DNS_HOSTNAME"
else
dokku docker-options:add "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_ALIAS"
dokku docker-options:add "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_DNS_HOSTNAME"
fi
[[ -n "$SERVICE_QUERYSTRING" ]] && SERVICE_URL="${SERVICE_URL}?${SERVICE_QUERYSTRING}"
config_set "$APP" "${ALIAS}_URL=$SERVICE_URL"
}
@@ -355,7 +441,11 @@ service_list() {
if [[ -z $SERVICES ]]; then
dokku_log_warn "There are no $PLUGIN_SERVICE services"
else
LIST="NAME,VERSION,STATUS,EXPOSED PORTS,LINKS\n"
LIST=""
if [[ -z "$DOKKU_QUIET_OUTPUT" ]]; then
LIST="NAME,VERSION,STATUS,EXPOSED PORTS,LINKS\n"
fi
for SERVICE in $SERVICES; do
LIST+="$SERVICE,$(service_version "$SERVICE"),$(service_status "$SERVICE"),$(service_exposed_ports "$SERVICE"),$(service_linked_apps "$SERVICE")\n"
done
@@ -375,8 +465,11 @@ service_logs() {
DOKKU_LOGS_ARGS="--follow"
fi
docker inspect "$ID" &> /dev/null || dokku_log_fail "Service container does not exist"
is_container_status "$ID" "Running" || dokku_log_warn "Service logs may not be output as service is not running"
# shellcheck disable=SC2086
docker logs $DOKKU_LOGS_ARGS "$ID"
docker logs $DOKKU_LOGS_ARGS "$ID" 2> /dev/null
}
service_parse_args() {
@@ -386,26 +479,27 @@ service_parse_args() {
for arg in "$@"; do
shift
case "$arg" in
"--config-options") set -- "$@" "-c" ;;
"--custom-env") set -- "$@" "-C" ;;
"--image") set -- "$@" "-i" ;;
"--image-version") set -- "$@" "-I" ;;
"--password") set -- "$@" "-p" ;;
"--root-password") set -- "$@" "-r" ;;
"--alias") set -- "$@" "-a" ;;
"--database") set -- "$@" "-d" ;;
"--memory") set -- "$@" "-m" ;;
"--querystring") set -- "$@" "-q" ;;
"--user") set -- "$@" "-u" ;;
*) set -- "$@" "$arg"
"--alias") set -- "$@" "-a" ;;
"--config-options") set -- "$@" "-c" ;;
"--custom-env") set -- "$@" "-C" ;;
"--database") set -- "$@" "-d" ;;
"--image-version") set -- "$@" "-I" ;;
"--image") set -- "$@" "-i" ;;
"--memory") set -- "$@" "-m" ;;
"--password") set -- "$@" "-p" ;;
"--querystring") set -- "$@" "-q" ;;
"--restart-apps") set -- "$@" "-R" ;;
"--root-password") set -- "$@" "-r" ;;
"--user") set -- "$@" "-u" ;;
*) set -- "$@" "$arg"
esac
done
OPTIND=1
while getopts "a:c:C:d:i:I:m:p:q:r:u:" opt; do
while getopts "a:c:C:d:i:I:m:p:q:R:r:u:" opt; do
case "$opt" in
a) export SERVICE_ALIAS=$OPTARG
a)
SERVICE_ALIAS="${OPTARG^^}"; export SERVICE_ALIAS="${SERVICE_ALIAS%_URL}"
;;
c) export PLUGIN_CONFIG_OPTIONS=$OPTARG
;;
@@ -421,7 +515,9 @@ service_parse_args() {
;;
p) export SERVICE_PASSWORD=$OPTARG
;;
q) export SERVICE_QUERYSTRING=$OPTARG
q) export SERVICE_QUERYSTRING=${OPTARG#"?"}
;;
R) export SERVICE_RESTART_APPS=$OPTARG
;;
r) export SERVICE_ROOT_PASSWORD=$OPTARG
;;
@@ -553,13 +649,17 @@ service_status() {
declare SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID="$(cat "$SERVICE_ROOT/ID")"
local CONTAINER_STATUS
is_container_status "$ID" "Dead" && echo "dead" && return 0
is_container_status "$ID" "OOMKilled" && echo "oomkilled" && return 0
is_container_status "$ID" "Paused" && echo "paused" && return 0
is_container_status "$ID" "Restarting" && echo "restarting" && return 0
is_container_status "$ID" "Running" && echo "running" && return 0
echo "stopped" && return 0
CONTAINER_STATUS=$(docker inspect -f "{{.State.Status}}" "$CID" 2> /dev/null || true)
[[ -n "$CONTAINER_STATUS" ]] && echo "$CONTAINER_STATUS" && return 0
echo "missing" && return 0
}
service_stop() {
@@ -567,14 +667,14 @@ service_stop() {
declare SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE";
local SERVICE_NAME="$(get_service_name "$SERVICE")"
local ID=$(docker ps -f status=running | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
local ID=$(docker ps -f status=running --no-trunc | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
[[ -z $ID ]] && dokku_log_warn "Service is already stopped" && return 0
if [[ -n $ID ]]; then
dokku_log_info1_quiet "Stopping container"
dokku_log_info2_quiet "Stopping container"
docker stop "$SERVICE_NAME" > /dev/null
service_port_pause "$SERVICE"
dokku_log_info2 "Container stopped"
dokku_log_verbose_quiet "Container stopped"
else
dokku_log_verbose_quiet "No container exists for $SERVICE"
fi
@@ -587,7 +687,7 @@ service_unlink() {
local SERVICE_URL=$(service_url "$SERVICE")
local SERVICE_NAME="$(get_service_name "$SERVICE")"
local EXISTING_CONFIG=$(config_all "$APP")
local SERVICE_ALIAS=$(service_alias "$SERVICE")
local SERVICE_DNS_HOSTNAME=$(service_dns_hostname "$SERVICE")
local LINK=($(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1)) || true
remove_from_links_file "$SERVICE" "$APP"
@@ -595,9 +695,9 @@ service_unlink() {
if declare -f -F add_passed_docker_option > /dev/null; then
# shellcheck disable=SC2034
local passed_phases=(build deploy run)
remove_passed_docker_option passed_phases[@] "--link $SERVICE_NAME:$SERVICE_ALIAS"
remove_passed_docker_option passed_phases[@] "--link $SERVICE_NAME:$SERVICE_DNS_HOSTNAME"
else
dokku docker-options:remove "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_ALIAS"
dokku docker-options:remove "$APP" build,deploy,run "--link $SERVICE_NAME:$SERVICE_DNS_HOSTNAME"
fi
[[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP"
@@ -608,7 +708,7 @@ service_version() {
declare desc="Displays the running version for an image"
declare SERVICE="$1"
local SERVICE_NAME="$(get_service_name "$SERVICE")"
docker inspect -f '{{.Config.Image}}' "$SERVICE_NAME"
docker inspect -f '{{.Config.Image}}' "$SERVICE_NAME" 2> /dev/null || true
}
update_plugin_scheme_for_app() {

1
config
View File

@@ -4,6 +4,7 @@ export MYSQL_IMAGE_VERSION=${MYSQL_IMAGE_VERSION:="5.7.12"}
export MYSQL_ROOT=${MYSQL_ROOT:="/var/lib/dokku/services/mysql"}
export MYSQL_HOST_ROOT=${MYSQL_HOST_ROOT:=$MYSQL_ROOT}
export PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=()
export PLUGIN_COMMAND_PREFIX="mysql"
export PLUGIN_CONFIG_ROOT=${PLUGIN_CONFIG_ROOT:="$DOKKU_LIB_ROOT/config/$PLUGIN_COMMAND_PREFIX"}
export PLUGIN_DATA_ROOT=$MYSQL_ROOT

View File

@@ -29,7 +29,7 @@ service_create() {
service_parse_args "${@:2}"
if ! docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " ; then
if ! service_image_exists "$SERVICE"; then
if [[ "$PLUGIN_DISABLE_PULL" == "true" ]]; then
dokku_log_warn "${PLUGIN_DISABLE_PULL_VARIABLE} environment variable detected. Not running pull command." 1>&2
dokku_log_warn " docker pull ${IMAGE}" 1>&2
@@ -119,15 +119,14 @@ service_start() {
local QUIET="$2"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local SERVICE_NAME="$(get_service_name "$SERVICE")"
local ID=$(docker ps -f status=running | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
local ID=$(docker ps -f status=running --no-trunc | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
if [[ -n $ID ]]; then
[[ -z $QUIET ]] && dokku_log_warn "Service is already started"
return 0
fi
dokku_log_info1_quiet "Starting container"
local PREVIOUS_ID=$(docker ps -f status=exited | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
local IMAGE_EXISTS=$(docker images | grep -e "^$PLUGIN_IMAGE " | grep -q " $PLUGIN_IMAGE_VERSION " && true)
dokku_log_info2_quiet "Starting container"
local PREVIOUS_ID=$(docker ps -f status=exited --no-trunc | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true
local ROOTPASSWORD="$(cat "$SERVICE_ROOT/ROOTPASSWORD")"
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
@@ -135,7 +134,7 @@ service_start() {
docker start "$PREVIOUS_ID" > /dev/null
service_port_unpause "$SERVICE"
dokku_log_info2 "Container started"
elif $IMAGE_EXISTS && [[ -n "$ROOTPASSWORD" ]] && [[ -n "$PASSWORD" ]]; then
elif service_image_exists "$SERVICE" && [[ -n "$ROOTPASSWORD" ]] && [[ -n "$PASSWORD" ]]; then
service_create_container "$SERVICE"
else
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
@@ -146,6 +145,6 @@ service_url() {
local SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
local SERVICE_ALIAS="$(service_alias "$SERVICE")"
echo "$PLUGIN_SCHEME://mysql:$PASSWORD@$SERVICE_ALIAS:${PLUGIN_DATASTORE_PORTS[0]}/$SERVICE"
local SERVICE_DNS_HOSTNAME="$(service_dns_hostname "$SERVICE")"
echo "$PLUGIN_SCHEME://mysql:$PASSWORD@$SERVICE_DNS_HOSTNAME:${PLUGIN_DATASTORE_PORTS[0]}/$SERVICE"
}

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common-functions"
export SUBCOMMAND_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands"
fn-help() {
@@ -27,14 +28,14 @@ fn-help() {
fn-help-all() {
declare CMD="$1" SUBCOMMAND="$2"
local CMD_OUTPUT BLUE BOLD FULL_OUTPUT NORMAL
local CMD_OUTPUT BLUE BOLD FULL_OUTPUT NORMAL
FULL_OUTPUT=true
if [[ "$CMD" = "$PLUGIN_COMMAND_PREFIX:help" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX:default" ]] ; then
BOLD="$(tput bold)"
NORMAL="\033[m"
BLUE="\033[0;34m"
CYAN="\033[1;36m"
BOLD="$(fn-help-fancy-tput bold)"
NORMAL="$(fn-help-fancy-color "\033[m")"
BLUE="$(fn-help-fancy-color "\033[0;34m")"
CYAN="$(fn-help-fancy-color "\033[1;36m")"
if [[ -n "$SUBCOMMAND" ]] && [[ "$SUBCOMMAND" != "--all" ]]; then
fn-help-contents-subcommand "$SUBCOMMAND" "$FULL_OUTPUT"
return "$?"
@@ -75,7 +76,7 @@ fn-help-contents() {
fn-help-contents-subcommand() {
declare SUBCOMMAND="$1" FULL_OUTPUT="$2"
local TMPDIR=$(mktemp -d)
local UNCLEAN_FILE="${TMPDIR}cmd-unclean" CLEAN_FILE="${TMPDIR}cmd-clean"
local UNCLEAN_FILE="${TMPDIR}/cmd-unclean" CLEAN_FILE="${TMPDIR}/cmd-clean"
local BOLD CMD_OUTPUT CYAN EXAMPLE LIGHT_GRAY NORMAL
trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT
@@ -83,7 +84,7 @@ fn-help-contents-subcommand() {
cat "$SUBCOMMAND_ROOT/$SUBCOMMAND" > "$UNCLEAN_FILE"
fn-help-subcommand-sanitize "$UNCLEAN_FILE" "$CLEAN_FILE"
if [[ "$(fn-help-is-subcommand-unimplemented "$CLEAN_FILE")" == true ]]; then
if ! is_implemented_command "$SUBCOMMAND"; then
return 1
fi
@@ -94,12 +95,12 @@ fn-help-contents-subcommand() {
desc="$(grep desc "$CLEAN_FILE" | head -1)"
eval "$desc"
BLUE="\033[0;34m"
BOLD="$(tput bold)"
CYAN="\033[1;36m"
NORMAL="\033[m"
LIGHT_GRAY="\033[2;37m"
LIGHT_RED="\033[1;31m"
BLUE="$(fn-help-fancy-color "\033[0;34m")"
BOLD="$(fn-help-fancy-tput bold)"
CYAN="$(fn-help-fancy-color "\033[1;36m")"
NORMAL="$(fn-help-fancy-color "\033[m")"
LIGHT_GRAY="$(fn-help-fancy-color "\033[2;37m")"
LIGHT_RED="$(fn-help-fancy-color "\033[1;31m")"
CMD_OUTPUT="$(echo -e " ${PLUGIN_COMMAND_PREFIX}${cmd_line}, ${LIGHT_GRAY}${desc}${NORMAL}")"
if [[ "$FULL_OUTPUT" != "true" ]]; then
echo "$CMD_OUTPUT"
@@ -138,16 +139,24 @@ fn-help-contents-subcommand() {
return 0
}
fn-help-is-subcommand-unimplemented() {
declare FUNC_FILE="$1"
local UNIMPLEMENTED
fn-help-fancy-tput() {
declare desc="A wrapper around tput"
UNIMPLEMENTED="$(grep "Not yet implemented" "$FUNC_FILE" | head -1 || true)"
if [[ -n "$UNIMPLEMENTED" ]]; then
echo true
else
echo false
if [[ -n "$DOKKU_NO_COLOR" ]] || [[ "$TERM" = "unknown" ]] || [[ "$TERM" == "dumb" ]]; then
return
fi
tput "$@"
}
fn-help-fancy-color() {
declare desc="A wrapper around colors"
if [[ -n "$DOKKU_NO_COLOR" ]] || [[ "$TERM" = "unknown" ]] || [[ "$TERM" == "dumb" ]]; then
return
fi
echo "$@"
}
fn-help-list-example() {
@@ -164,8 +173,8 @@ fn-help-subcommand-args() {
local argline arglist args argpos BLUE NORMAL
if [[ "$FULL_OUTPUT" == "true" ]]; then
BLUE="\033[0;34m"
NORMAL="\033[m"
BLUE="$(fn-help-fancy-color "\033[0;34m")"
NORMAL="$(fn-help-fancy-color "\033[m")"
fi
argline=$(grep declare "$FUNC_FILE" | grep -v "declare desc" | head -1 || true)
arglist=($(echo -e "${argline// /"\n"}" | awk -F= '/=/{print ""$1""}'))
@@ -210,12 +219,12 @@ fn-help-subcommand-example() {
return 0
fi
BOLD="$(tput bold)"
BOLD="$(fn-help-fancy-tput bold)"
LAST_LINE=""
LIGHT_GRAY="\033[2;37m"
OTHER_GRAY="\033[7;37m"
LIGHT_GRAY="$(fn-help-fancy-color "\033[2;37m")"
OTHER_GRAY="$(fn-help-fancy-color "\033[7;37m")"
NEWLINE=""
NORMAL="\033[m"
NORMAL="$(fn-help-fancy-color "\033[m")"
_fn-help-apply-shell-expansion "$EXAMPLE" | while read -r line; do
line="$(echo "$line" | cut -c 4-)"
if [[ "$line" == export* ]] || [[ "$line" == dokku* ]]; then
@@ -245,10 +254,10 @@ fn-help-subcommand-list-args() {
return 0
fi
NORMAL="\033[m"
LIGHT_GRAY="\033[2;37m"
NORMAL="$(fn-help-fancy-color "\033[m")"
LIGHT_GRAY="$(fn-help-fancy-color "\033[2;37m")"
_fn-help-apply-shell-expansion "$FLAGS" | while read -r line; do
_fn-help-apply-shell-expansion "$FLAGS" | while read -r line; do
echo -e "$(echo "$line" | cut -d',' -f1),${LIGHT_GRAY}$(echo "$line" | cut -d',' -f2-)${NORMAL}"
done
}
@@ -262,10 +271,10 @@ fn-help-subcommand-list-flags() {
return 0
fi
NORMAL="\033[m"
LIGHT_GRAY="\033[2;37m"
NORMAL="$(fn-help-fancy-color "\033[m")"
LIGHT_GRAY="$(fn-help-fancy-color "\033[2;37m")"
_fn-help-apply-shell-expansion "$FLAGS" | while read -r line; do
_fn-help-apply-shell-expansion "$FLAGS" | while read -r line; do
echo -e "$(echo "$line" | cut -d',' -f1),${LIGHT_GRAY}$(echo "$line" | cut -d',' -f2-)${NORMAL}"
done
}

View File

@@ -1,4 +1,4 @@
[plugin]
description = "dokku mysql service plugin"
version = "1.1.1"
version = "1.4.10"
[plugin.config]

21
subcommands/app-links Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-app-links-cmd() {
#E list all $PLUGIN_COMMAND_PREFIX services that are linked to the 'playground' app.
#E dokku $PLUGIN_COMMAND_PREFIX:app-links playground
#A app, app to run command against
declare desc="list all $PLUGIN_SERVICE service links for a given app"
local cmd="$PLUGIN_COMMAND_PREFIX:app-links" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare APP="$1"
APP=${APP:="$DOKKU_APP_NAME"}
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
verify_app_name "$APP"
service_app_links "$APP"
}
service-app-links-cmd "$@"

View File

@@ -7,12 +7,13 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-backup-cmd() {
#E backup the 'lolipop' service to the 'my-s3-bucket' bucket on AWS
#E dokku $PLUGIN_COMMAND_PREFIX:backup lolipop my-s3-bucket --use-iam
#F -i|--use-iam, use the IAM profile associated with the current server
#F -u|--use-iam, use the IAM profile associated with the current server
#A service, service to run command against
#A bucket-name, name of the s3 bucket to upload backups to
declare desc="creates a backup of the $PLUGIN_SERVICE service to an existing s3 bucket"
local cmd="$PLUGIN_COMMAND_PREFIX:backup" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" BUCKET_NAME="$2" USE_IAM_OPTIONAL_FLAG="$3"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ -z "$BUCKET_NAME" ]] && dokku_log_fail "Please specify an aws bucket for the backup"

View File

@@ -22,6 +22,7 @@ service-backup-auth-cmd() {
declare desc="sets up authentication for backups on the $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-auth" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" AWS_ACCESS_KEY_ID="$2" AWS_SECRET_ACCESS_KEY="$3" AWS_DEFAULT_REGION="$4" AWS_SIGNATURE_VERSION="$5" ENDPOINT_URL="$6"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ -z "$AWS_ACCESS_KEY_ID" ]] && dokku_log_fail "Please specify an aws access key id"

View File

@@ -11,6 +11,7 @@ service-backup-deauth-cmd() {
declare desc="removes backup authentication for the $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-deauth" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"

View File

@@ -7,19 +7,23 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-backup-schedule-cmd() {
#E schedule a backup
#E > 'schedule' is a crontab expression, eg. "0 3 * * *" for each day at 3am
#E dokku $PLUGIN_COMMAND_PREFIX:backup-deauth lolipop "0 3 * * *" my-s3-bucket
#E dokku $PLUGIN_COMMAND_PREFIX:backup-schedule lolipop "0 3 * * *" my-s3-bucket
#E schedule a backup and authenticate via iam
#E dokku $PLUGIN_COMMAND_PREFIX:backup-schedule lolipop "0 3 * * *" my-s3-bucket --use-iam
#F -u|--use-iam, use the IAM profile associated with the current server
#A service, service to run command against
#A schedule, a cron schedule to run backups on
#A bucket-name, name of the s3 bucket to upload backups to
declare desc="schedules a backup of the $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-schedule" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" SCHEDULE="$2" BUCKET_NAME="$3"
declare SERVICE="$1" SCHEDULE="$2" BUCKET_NAME="$3" USE_IAM_OPTIONAL_FLAG="$4"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ -z "$SCHEDULE" ]] && dokku_log_fail "Please specify a schedule for the backup"
[[ -z "$BUCKET_NAME" ]] && dokku_log_fail "Please specify an aws bucket for the backup"
verify_service_name "$SERVICE"
service_backup_schedule "$SERVICE" "$SCHEDULE" "$BUCKET_NAME"
service_backup_schedule "$SERVICE" "$SCHEDULE" "$BUCKET_NAME" "$USE_IAM_OPTIONAL_FLAG"
}
service-backup-schedule-cmd "$@"

20
subcommands/backup-schedule-cat Executable file
View File

@@ -0,0 +1,20 @@
#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-backup-schedule-cat-cmd() {
#E cat the contents of the configured backup cronfile for the service
#E dokku $PLUGIN_COMMAND_PREFIX:backup-schedule-cat lolipop
#A service, service to run command against
declare desc="cat the contents of the configured backup cronfile for the service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-schedule-cat" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"
service_backup_schedule_cat "$SERVICE"
}
service-backup-schedule-cat-cmd "$@"

View File

@@ -5,18 +5,19 @@ source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-backup-set-encryption-cmd() {
#E set a GPG encryption key for backups
#E set a GPG passphrase for backups
#E dokku $PLUGIN_COMMAND_PREFIX:backup-set-encryption lolipop
#A service, service to run command against
#A encryption-key, a GPG encryption key
#A passphrase, a GPG-compatible passphrase
declare desc="sets encryption for all future backups of $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-set-encryption" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" ENCRYPTION_KEY="$2"
declare SERVICE="$1" PASSPHRASE="$2"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ -z "$ENCRYPTION_KEY" ]] && dokku_log_fail "Please specify a GPG encryption key"
[[ -z "$PASSPHRASE" ]] && dokku_log_fail "Please specify a GPG backup passphrase"
verify_service_name "$SERVICE"
service_backup_set_encryption "$SERVICE" "$ENCRYPTION_KEY"
service_backup_set_encryption "$SERVICE" "$PASSPHRASE"
}
service-backup-set-encryption-cmd "$@"

View File

@@ -11,6 +11,7 @@ service-backup-unschedule-cmd() {
declare desc="unschedules the backup of the $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-unschedule" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"

View File

@@ -11,6 +11,7 @@ service-backup-unset-encryption-cmd() {
declare desc="unsets encryption for future backups of the $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-unset-encryption" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"

View File

@@ -9,21 +9,34 @@ service-clone-cmd() {
#E dokku $PLUGIN_COMMAND_PREFIX:clone lolipop lolipop-2
#A service, service to run command against
#A new-service, name of new service
#F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
#F -i|--image IMAGE, the image name to start the service with
#F -I|--image-version IMAGE_VERSION, the image version to start the service with
#F -p|--password PASSWORD, override the user-level service password
#F -r|--root-password PASSWORD, override the root-level service password
declare desc="create container <new-name> then copy data from <name> into <new-name>"
local cmd="$PLUGIN_COMMAND_PREFIX:clone" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" NEW_SERVICE="$2" CLONE_FLAGS_LIST="${@:3}"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ -z "$NEW_SERVICE" ]] && dokku_log_fail "Please specify a name for the new service"
verify_service_name "$SERVICE"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID="$(cat "$SERVICE_ROOT/ID")"
is_container_status "$ID" "Running" || dokku_log_fail "Service ${SERVICE} container is not running"
PLUGIN_IMAGE=$(service_version "$SERVICE" | grep -o "^.*:" | sed -r "s/://g")
PLUGIN_IMAGE_VERSION=$(service_version "$SERVICE" | grep -o ":.*$" | sed -r "s/://g")
service_parse_args "${@:3}"
dokku_log_info2 "Cloning $SERVICE to $NEW_SERVICE @ $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
service_create "$NEW_SERVICE" "${@:3}"
dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE"
service_export "$SERVICE" | service_import "$NEW_SERVICE" > /dev/null 2>&1 || true
dokku_log_info1 "Done"
dokku_log_info2 "Done"
}
service-clone-cmd "$@"

View File

@@ -8,9 +8,10 @@ service-connect-cmd() {
#E connect to the service via the $PLUGIN_COMMAND_PREFIX connection tool
#E dokku $PLUGIN_COMMAND_PREFIX:connect lolipop
#A service, service to run command against
declare desc="connect via mysql to a $PLUGIN_SERVICE service"
declare desc="connect to the service via the $PLUGIN_COMMAND_PREFIX connection tool"
local cmd="$PLUGIN_COMMAND_PREFIX:connect" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"

View File

@@ -17,9 +17,9 @@ service-create-cmd() {
#E export ${PLUGIN_DEFAULT_ALIAS}_CUSTOM_ENV="USER=alpha;HOST=beta"
#E dokku $PLUGIN_COMMAND_PREFIX:create lolipop
#A service, service to run command against
#F -c|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
#F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
#F -i|--image IMAGE, the image name to start the service with
#F -i|--image-version IMAGE_VERSION, the image version to start the service with
#F -I|--image-version IMAGE_VERSION, the image version to start the service with
#F -p|--password PASSWORD, override the user-level service password
#F -r|--root-password PASSWORD, override the root-level service password
declare desc="create a $PLUGIN_SERVICE service"

View File

@@ -37,7 +37,8 @@ service-destroy-cmd() {
fi
fi
dokku_log_info1 "Deleting $SERVICE"
dokku_log_info2_quiet "Deleting $SERVICE"
service_backup_unschedule "$SERVICE"
if [[ -n $(docker ps -aq -f name="$SERVICE_NAME") ]]; then
dokku_log_verbose_quiet "Deleting container data"
service_stop "$SERVICE"
@@ -51,7 +52,7 @@ service-destroy-cmd() {
fi
dokku_log_verbose_quiet "Removing data"
docker run --rm -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/config:/config" "$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" chmod 777 -R /config /data
docker run --rm -v "$SERVICE_HOST_ROOT/data:/data" -v "$SERVICE_HOST_ROOT/config:/config" busybox chmod 777 -R /config /data
rm -rf "$SERVICE_ROOT"
dokku_log_info2 "$PLUGIN_SERVICE container deleted: $SERVICE"

View File

@@ -13,6 +13,7 @@ service-export-cmd() {
declare desc="export a dump of the $PLUGIN_SERVICE service database"
local cmd="$PLUGIN_COMMAND_PREFIX:export" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"

View File

@@ -11,6 +11,7 @@ service-import-cmd() {
declare desc="import a dump into the $PLUGIN_SERVICE service database"
local cmd="$PLUGIN_COMMAND_PREFIX:import" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"

View File

@@ -39,15 +39,19 @@ service-link-cmd() {
#E ${PLUGIN_SCHEME}2://lolipop:SOME_PASSWORD@dokku-${PLUGIN_COMMAND_PREFIX}-lolipop:${PLUGIN_DATASTORE_PORTS[0]}/lolipop
#A service, service to run command against
#A app, app to run command against
#F -a|--alias "BLUE_DATABASE", an alternative alias to use for linking to an app via environment variable
#F -q|--querystring "pool=5", ampersand delimited querystring arguments to append to the service link
declare desc="link the $PLUGIN_SERVICE service to the app"
local cmd="$PLUGIN_COMMAND_PREFIX:link" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" APP="$2"
declare SERVICE="$1" APP="$2" LINK_FLAGS_LIST="${@:3}"
APP=${APP:="$DOKKU_APP_NAME"}
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
verify_app_name "$APP"
verify_service_name "$SERVICE"
service_parse_args "${@:3}"
service_link "$SERVICE" "$APP"
}

61
subcommands/upgrade Executable file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
service-upgrade-cmd() {
#E you can upgrade an existing service to a new image or image-version
#E dokku $PLUGIN_COMMAND_PREFIX:upgrade lolipop
#A service, service to run command against
#F -C|--custom-env "USER=alpha;HOST=beta", semi-colon delimited environment variables to start the service with
#F -i|--image IMAGE, the image name to start the service with
#F -I|--image-version IMAGE_VERSION, the image version to start the service with
#F -R|--restart-apps "true", whether to force an app restart
declare desc="upgrade service <service> to the specified versions"
local cmd="$PLUGIN_COMMAND_PREFIX:upgrade" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" UPGRADE_FLAGS_LIST="${@:2}"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
service_parse_args "${@:2}"
if ! service_image_exists "$SERVICE"; then
dokku_log_fail "Unable to proceed with upgrade, image ${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION} does not exist"
fi
local NEW_PLUGIN_IMAGE_TAG="$PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
if [[ "$(service_version "$SERVICE")" == "$NEW_PLUGIN_IMAGE_TAG" ]]; then
dokku_log_info1 "Service $SERVICE already running $NEW_PLUGIN_IMAGE_TAG"
return
fi
dokku_log_info2 "Upgrading $SERVICE to $NEW_PLUGIN_IMAGE_TAG"
if [[ "$SERVICE_RESTART_APPS" == "true" ]]; then
dokku_log_info2 "Stopping all linked services"
for app in $(service_linked_apps "$SERVICE"); do
[[ "$app" == "-" ]] && continue
ps_stop "$app"
done
fi
dokku_log_info2 "Stopping $SERVICE"
service_container_rm "$SERVICE"
service_start "$SERVICE" "${@:2}"
if [[ "$SERVICE_RESTART_APPS" == "true" ]]; then
dokku_log_info2 "Starting all linked services"
for app in $(service_linked_apps "$SERVICE"); do
[[ "$app" == "-" ]] && continue
ps_start "$app"
done
fi
dokku_log_info2 "Done"
}
service-upgrade-cmd "$@"

View File

@@ -68,3 +68,18 @@ teardown() {
assert_contains "$url" "mysql2://mysql:$password@dokku-mysql-l:3306/l"
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app
}
@test "($PLUGIN_COMMAND_PREFIX:link) adds a querystring" {
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app --querystring "pool=5"
url=$(dokku config:get my_app DATABASE_URL)
assert_contains "$url" "?pool=5"
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app
}
@test "($PLUGIN_COMMAND_PREFIX:link) uses a specified config url when alias is specified" {
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app --alias "ALIAS"
url=$(dokku config:get my_app ALIAS_URL)
password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
assert_contains "$url" "mysql://mysql:$password@dokku-mysql-l:3306/l"
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app
}

View File

@@ -24,11 +24,11 @@ teardown() {
@test "($PLUGIN_COMMAND_PREFIX:logs) success when not tailing" {
export ECHO_DOCKER_COMMAND="true"
run dokku "$PLUGIN_COMMAND_PREFIX:logs" l
assert_output "docker logs --tail 100 testid"
assert_contains "docker logs --tail 100 testid"
}
@test "($PLUGIN_COMMAND_PREFIX:logs) success when tailing" {
export ECHO_DOCKER_COMMAND="true"
run dokku "$PLUGIN_COMMAND_PREFIX:logs" l -t
assert_output "docker logs --follow testid"
assert_contains "docker logs --follow testid"
}

View File

@@ -52,7 +52,7 @@ teardown() {
check_value="Deploy options: --restart=on-failure:10"
fi
options=$(dokku $report_action my_app | xargs)
options=$(dokku --quiet $report_action my_app | xargs)
assert_equal "$options" "$check_value"
}

1
tests/test_helper.bash Normal file → Executable file
View File

@@ -1,5 +1,4 @@
#!/usr/bin/env bash
export DOKKU_QUIET_OUTPUT=1
export DOKKU_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/dokku"
export DOKKU_VERSION=${DOKKU_VERSION:-"master"}
export PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/bin:$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/dokku:$PATH"