Compare commits

...

53 Commits
1.2.0 ... 1.4.7

Author SHA1 Message Date
Jose Diaz-Gonzalez
9fac5a4ad4 Release 1.4.7 2018-10-10 23:32:33 -04:00
Jose Diaz-Gonzalez
73a8ccc085 fix: ensure flags are properly represented in help output 2018-10-10 23:31:52 -04:00
Jose Diaz-Gonzalez
c05aa74a3e Release 1.4.6 2018-10-10 23:27:36 -04:00
Jose Diaz-Gonzalez
d112144293 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
30de0727ab Release 1.4.5 2018-10-10 23:18:41 -04:00
Jose Diaz-Gonzalez
8823baf480 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
d470ade7a7 fix: handle case where container being removed does not exist 2018-10-10 22:03:44 -04:00
Jose Diaz-Gonzalez
66e8279dca Release 1.4.4 2018-10-10 09:40:45 -04:00
Jose Diaz-Gonzalez
969a9cdcb0 Release 1.4.3 2018-10-10 09:40:27 -04:00
Jose Diaz-Gonzalez
5620147f89 Merge pull request #145 from dpoirier/use_if_exists_with_import
Use --if-exists with import
2018-10-10 09:20:54 -04:00
Jose Diaz-Gonzalez
dda9ed6d55 Release 1.4.2 2018-10-10 03:03:40 -04:00
Jose Diaz-Gonzalez
76e0d5fd87 fix: correct short-flag for image-version and custom-env 2018-10-10 03:02:56 -04:00
Jose Diaz-Gonzalez
7382058ecb Release 1.4.1 2018-10-10 03:01:17 -04:00
Jose Diaz-Gonzalez
0a8d599965 fix: correct name for upgrade flags in help output 2018-10-10 03:00:22 -04:00
Jose Diaz-Gonzalez
21cc07bd48 Release 1.4.0 2018-10-10 02:59:24 -04:00
Jose Diaz-Gonzalez
902545bdb4 chore: correct verbiage around upgrades 2018-10-10 02:54:34 -04:00
Jose Diaz-Gonzalez
ea3cd5ef30 fix: pass correct variable for upgrade command 2018-10-10 02:49:30 -04:00
Jose Diaz-Gonzalez
9010e1551f fix: correct check for existing image 2018-10-10 02:42:43 -04:00
Jose Diaz-Gonzalez
c05c47187a fix: do not force-set plugin image and version to existing image and version 2018-10-10 02:39:11 -04:00
Jose Diaz-Gonzalez
9ee6c3c5cf chore: remove unnecessary call 2018-10-10 02:32:59 -04:00
Jose Diaz-Gonzalez
a391fa88dc Merge pull request #158 from dokku/upgrade-service-image-version
feat: add ability to upgrade service image and image-version
2018-10-10 02:15:07 -04:00
Jose Diaz-Gonzalez
59d285f2f1 feat: add ability to upgrade service image and image-version 2018-10-10 00:14:08 -04:00
Jose Diaz-Gonzalez
3eaa1dc5cd Release 1.3.1 2018-08-23 11:39:46 -04:00
Jose Diaz-Gonzalez
6de1077806 Merge pull request #149 from Friss/postgres-10.4
Update to use PostgreSQL 10.4 by default
2018-08-23 10:56:03 -04:00
Jose Diaz-Gonzalez
3020346caa Release 1.3.0 2018-07-21 16:34:21 -04:00
Jose Diaz-Gonzalez
57554f6288 feat: add command to list linked services for a given app 2018-07-21 16:32:00 -04:00
Zachary Friss
eb8ea7d8a6 Revert - to * read me change 2018-07-05 15:20:55 -04:00
Zachary
b94af2bf3a Update to use postgres 10.4 by default 2018-07-05 01:46:13 -04:00
Dan Poirier
d143bb48b0 Update test to expect --if-exists on import 2018-04-30 14:29:30 -04:00
Jose Diaz-Gonzalez
e78cc9bd36 Use --if-exists with import
To resolve https://github.com/dokku/dokku-postgres/issues/142
2018-04-30 13:55:58 -04:00
Jose Diaz-Gonzalez
f30db928fb fix: properly set SERVICE_ALIAS 2018-04-24 15:05:55 -04:00
Jose Diaz-Gonzalez
b15dcbf1c4 fix: add tests for custom link aliases 2018-04-24 13:21:37 -04:00
Jose Diaz-Gonzalez
0cb8bd5f9a feat: properly handle custom aliases and error states for alias usage when calling link subcommand. Refs dokku/dokku-redis#64 2018-04-24 03:22:02 -04:00
Jose Diaz-Gonzalez
603a0c6e80 fix: correct test 2018-04-24 03:03:55 -04:00
Jose Diaz-Gonzalez
ad62febd59 refactor: make variable as dns hostname more clear 2018-04-24 02:54:52 -04:00
Jose Diaz-Gonzalez
7b5ed48a5f fix: remove an infinite loop. Refs dokku/dokku-redis#64 2018-04-24 02:18:32 -04:00
Jose Diaz-Gonzalez
527b3bc54b feat: implement link querystring flags. Refs dokku/dokku-redis#64 2018-04-24 01:40:27 -04:00
Jose Diaz-Gonzalez
a66c040cbc feat: implement clone flags. Closes dokku/dokku-redis#105 2018-04-24 00:57:22 -04:00
Jose Diaz-Gonzalez
a2b1fbb737 refactor: move unimplemented command detection into config file 2018-04-24 00:27:22 -04:00
Jose Diaz-Gonzalez
d28412ee32 Release 1.2.7 2018-04-23 18:25:56 -04:00
Jose Diaz-Gonzalez
8bb81a3084 fix: use assert_contains 2018-04-23 18:25:56 -04:00
Jose Diaz-Gonzalez
c897ff488d Release 1.2.6 2018-04-23 18:14:38 -04:00
Jose Diaz-Gonzalez
106acfb75b feat: plugins are no longer beta 2018-04-23 18:14:38 -04:00
Jose Diaz-Gonzalez
193462a47f Release 1.2.5 2018-04-23 18:11:35 -04:00
Jose Diaz-Gonzalez
0750d93858 fix: set SERVICE_ROOT variable for backups 2018-04-23 18:11:35 -04:00
Jose Diaz-Gonzalez
bd5412aaff Release 1.2.4 2018-04-23 18:08:40 -04:00
Jose Diaz-Gonzalez
55ccf14e62 fix: set ID variable for backups 2018-04-23 18:08:40 -04:00
Jose Diaz-Gonzalez
4d6105d61b Release 1.2.3 2018-04-23 17:36:58 -04:00
Jose Diaz-Gonzalez
fe9cd93736 chore: standardize on single method of setting backup root. Refs dokku/dokku-redis#91 2018-04-23 17:36:58 -04:00
Jose Diaz-Gonzalez
059fdc7589 Release 1.2.2 2018-04-23 17:11:50 -04:00
Jose Diaz-Gonzalez
6a32161049 fix: properly handle use-iam flag. Closes dokku/dokku-redis#88 2018-04-23 17:11:50 -04:00
Jose Diaz-Gonzalez
ba523dc5ac Release 1.2.1 2018-04-23 15:52:17 -04:00
Jose Diaz-Gonzalez
a29039ecd2 fix: silence errors when a container does not exist. Closes dokku/dokku-redis#85 2018-04-23 15:52:17 -04:00
28 changed files with 309 additions and 114 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: 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,6 +1,6 @@
# dokku postgres (beta) [![Build Status](https://img.shields.io/travis/dokku/dokku-postgres.svg?branch=master "Build Status")](https://travis-ci.org/dokku/dokku-postgres) [![IRC Network](https://img.shields.io/badge/irc-freenode-blue.svg "IRC Freenode")](https://webchat.freenode.net/?channels=dokku) # dokku postgres [![Build Status](https://img.shields.io/travis/dokku/dokku-postgres.svg?branch=master "Build Status")](https://travis-ci.org/dokku/dokku-postgres) [![IRC Network](https://img.shields.io/badge/irc-freenode-blue.svg "IRC Freenode")](https://webchat.freenode.net/?channels=dokku)
Official postgres plugin for dokku. Currently defaults to installing [postgres 10.2](https://hub.docker.com/_/postgres/). Official postgres plugin for dokku. Currently defaults to installing [postgres 10.4](https://hub.docker.com/_/postgres/).
## requirements ## requirements
@@ -17,6 +17,7 @@ sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git postgres
## commands ## commands
``` ```
postgres:app-links <app> List all postgres service links for a given app
postgres:backup <name> <bucket> (--use-iam) Create a backup of the postgres service to an existing s3 bucket postgres:backup <name> <bucket> (--use-iam) Create a backup of the postgres service to an existing s3 bucket
postgres: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 postgres service postgres: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 postgres service
postgres:backup-deauth <name> Removes backup authentication for the postgres service postgres:backup-deauth <name> Removes backup authentication for the postgres service
@@ -45,6 +46,7 @@ postgres:start <name> Start a previously stopped postgres service
postgres:stop <name> Stop a running postgres service postgres:stop <name> Stop a running postgres service
postgres:unexpose <name> Unexpose a previously exposed postgres service postgres:unexpose <name> Unexpose a previously exposed postgres service
postgres:unlink <name> <app> Unlink the postgres service from the app postgres:unlink <name> <app> Unlink the postgres service from the app
postgres:upgrade <name> Upgrade service <service> to the specified version
``` ```
## usage ## usage
@@ -58,7 +60,7 @@ dokku postgres:create lolipop
# it *must* be compatible with the # it *must* be compatible with the
# official postgres image # official postgres image
export POSTGRES_IMAGE="postgres" export POSTGRES_IMAGE="postgres"
export POSTGRES_IMAGE_VERSION="10.2" export POSTGRES_IMAGE_VERSION="10.4"
dokku postgres:create lolipop dokku postgres:create lolipop
# you can also specify custom environment # you can also specify custom environment
@@ -183,7 +185,7 @@ OR
## upgrade/downgrade ## upgrade/downgrade
At the moment a database cant be upgraded (or downgraded) inplace. Instead a clone has to be made, like this: At the moment a database cant be upgraded (or downgraded) inplace. Instead a clone has to be made, like this:
```shell ```shell
# Our original DB using PG 9.5 # Our original DB using PG 9.5
@@ -206,7 +208,7 @@ $ dokku postgres:destroy db9.5
If you wish to tune the postgres instances various .conf files, you can find them by using the postgres:info command. If you wish to tune the postgres instances various .conf files, you can find them by using the postgres:info command.
```shell ```shell
dokku postgres:info lolipop dokku postgres:info lolipop
# or # or
dokku postgres:info lolipop --data-dir dokku postgres:info lolipop --data-dir
``` ```
@@ -243,14 +245,14 @@ dokku postgres:backup-unschedule lolipop
``` ```
Backup auth can also be set up for different regions, signature versions and endpoints (e.g. for minio): Backup auth can also be set up for different regions, signature versions and endpoints (e.g. for minio):
``` ```
# setup s3 backup authentication with different region # setup s3 backup authentication with different region
dokku postgres:backup-auth lolipop AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION dokku postgres:backup-auth lolipop AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION
# setup s3 backup authentication with different signature version and endpoint # setup s3 backup authentication with different signature version and endpoint
dokku postgres:backup-auth lolipop AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION AWS_SIGNATURE_VERSION ENDPOINT_URL dokku postgres:backup-auth lolipop AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION AWS_SIGNATURE_VERSION ENDPOINT_URL
# more specific example for minio auth # more specific example for minio auth
dokku postgres:backup-auth lolipop MINIO_ACCESS_KEY_ID MINIO_SECRET_ACCESS_KEY us-east-1 s3v4 https://YOURMINIOSERVICE dokku postgres:backup-auth lolipop MINIO_ACCESS_KEY_ID MINIO_SECRET_ACCESS_KEY us-east-1 s3v4 https://YOURMINIOSERVICE
``` ```
@@ -266,7 +268,7 @@ dokku postgres:connect db < ./dump.sql
## Security ## Security
The connection to the database is done over SSL. A self-signed certificate is The connection to the database is done over SSL. A self-signed certificate is
automatically generated when creating the service. It can be replaced by a automatically generated when creating the service. It can be replaced by a
custom certificate by overwriting the `server.crt` and `server.key` files in custom certificate by overwriting the `server.crt` and `server.key` files in
`/var/lib/dokku/services/postgres/<DB_NAME>/data`. `/var/lib/dokku/services/postgres/<DB_NAME>/data`.
The `server.key` must be chmoded to 600 and must be owned by the postgres user The `server.key` must be chmoded to 600 and must be owned by the postgres user

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 desc="Returns 0 or 1 depending upon whether a given container has a certain status"
declare CID="$1" STATUS="$2" declare CID="$1" STATUS="$2"
local TEMPLATE="{{.State.$STATUS}}" 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 if [[ "$CONTAINER_STATUS" == "true" ]]; then
return 0 return 0
@@ -67,6 +67,22 @@ is_container_status() {
return 1 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() { remove_from_links_file() {
declare desc="Removes an app from the service link file" declare desc="Removes an app from the service link file"
declare SERVICE="$1" APP="$2" declare SERVICE="$1" APP="$2"
@@ -79,7 +95,7 @@ remove_from_links_file() {
sort "$LINKS_FILE" -u -o "$LINKS_FILE" sort "$LINKS_FILE" -u -o "$LINKS_FILE"
} }
service_alias() { service_dns_hostname() {
declare desc="Retrieves the alias of a service" declare desc="Retrieves the alias of a service"
declare SERVICE="$1" declare SERVICE="$1"
local SERVICE_NAME="$(get_service_name "$SERVICE")" 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 COLORS=(AQUA BLACK BLUE FUCHSIA GRAY GREEN LIME MAROON NAVY OLIVE PURPLE RED SILVER TEAL WHITE YELLOW)
local ALIAS; local ALIAS;
while [[ -z $ALIAS ]]; do for COLOR in "${COLORS[@]}"; do
local IDX=$((RANDOM % ${#COLORS[*]}))
local COLOR=${COLORS[IDX]}
ALIAS="${PLUGIN_ALT_ALIAS}_${COLOR}" ALIAS="${PLUGIN_ALT_ALIAS}_${COLOR}"
local IN_USE=$(echo "$EXISTING_CONFIG" | grep "${ALIAS}_URL") local IN_USE=$(echo "$EXISTING_CONFIG" | grep "${ALIAS}_URL")
if [[ -n $IN_USE ]]; then if [[ -n $IN_USE ]]; then
@@ -104,26 +118,47 @@ service_alternative_alias() {
echo "$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() { service_backup() {
declare desc="Creates a backup of a service to an existing s3 bucket" declare desc="Creates a backup of a service to an existing s3 bucket"
declare SERVICE="$1" BUCKET_NAME="$2" USE_IAM_OPTIONAL_FLAG="$3" 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 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_ACCESS_KEY_ID_FILE="$SERVICE_BACKUP_ROOT/AWS_ACCESS_KEY_ID"
local AWS_SECRET_ACCESS_KEY_FILE="$BACKUP_CONFIG_ROOT/AWS_SECRET_ACCESS_KEY" 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="" 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_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" [[ ! -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")" 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" dokku_log_fail "Provide AWS credentials or use the --use-iam flag"
fi fi
TMPDIR=$(mktemp -d) TMPDIR=$(mktemp -d)
trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT 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") (service_export "$SERVICE" > "${TMPDIR}/export")
# Build parameter list for s3backup tool # 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 -e BACKUP_NAME=${PLUGIN_COMMAND_PREFIX}-${SERVICE}"
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -v ${TMPDIR}:/backup" BACKUP_PARAMETERS="$BACKUP_PARAMETERS -v ${TMPDIR}:/backup"
if [[ -f "$BACKUP_CONFIG_ROOT/AWS_DEFAULT_REGION" ]]; then if [[ -f "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_DEFAULT_REGION=$(cat "$BACKUP_CONFIG_ROOT/AWS_DEFAULT_REGION")" BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_DEFAULT_REGION=$(cat "$SERVICE_BACKUP_ROOT/AWS_DEFAULT_REGION")"
fi fi
if [[ -f "$BACKUP_CONFIG_ROOT/AWS_SIGNATURE_VERSION" ]]; then if [[ -f "$SERVICE_BACKUP_ROOT/AWS_SIGNATURE_VERSION" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_SIGNATURE_VERSION=$(cat "$BACKUP_CONFIG_ROOT/AWS_SIGNATURE_VERSION")" BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e AWS_SIGNATURE_VERSION=$(cat "$SERVICE_BACKUP_ROOT/AWS_SIGNATURE_VERSION")"
fi fi
if [[ -f "$BACKUP_CONFIG_ROOT/ENDPOINT_URL" ]]; then if [[ -f "$SERVICE_BACKUP_ROOT/ENDPOINT_URL" ]]; then
BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e ENDPOINT_URL=$(cat "$BACKUP_CONFIG_ROOT/ENDPOINT_URL")" BACKUP_PARAMETERS="$BACKUP_PARAMETERS -e ENDPOINT_URL=$(cat "$SERVICE_BACKUP_ROOT/ENDPOINT_URL")"
fi fi
if [[ -f "$BACKUP_ENCRYPTION_CONFIG_ROOT/ENCRYPTION_KEY" ]]; then if [[ -f "$BACKUP_ENCRYPTION_CONFIG_ROOT/ENCRYPTION_KEY" ]]; then
@@ -154,23 +189,22 @@ service_backup() {
service_backup_auth() { service_backup_auth() {
declare desc="Sets up authentication" 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" 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="$PLUGIN_DATA_ROOT/$SERVICE/backup"
local SERVICE_BACKUP_ROOT="${SERVICE_ROOT}/backup/"
mkdir -p "$SERVICE_BACKUP_ROOT" mkdir -p "$SERVICE_BACKUP_ROOT"
echo "$AWS_ACCESS_KEY_ID" > "${SERVICE_BACKUP_ROOT}/AWS_ACCESS_KEY_ID" 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_SECRET_ACCESS_KEY" > "$SERVICE_BACKUP_ROOT/AWS_SECRET_ACCESS_KEY"
if [[ -n "$AWS_DEFAULT_REGION" ]]; then 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 fi
if [[ -n "$AWS_SIGNATURE_VERSION" ]]; then 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 fi
if [[ -n "$ENDPOINT_URL" ]]; then if [[ -n "$ENDPOINT_URL" ]]; then
echo "$ENDPOINT_URL" > "${SERVICE_BACKUP_ROOT}/ENDPOINT_URL" echo "$ENDPOINT_URL" > "$SERVICE_BACKUP_ROOT/ENDPOINT_URL"
fi fi
} }
@@ -185,12 +219,16 @@ service_backup_deauth() {
service_backup_schedule() { service_backup_schedule() {
declare desc="schedules a backup of the service" 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 DOKKU_BIN="$(which dokku)"
local CRON_FILE="/etc/cron.d/dokku-${PLUGIN_COMMAND_PREFIX}-${SERVICE}" local CRON_FILE="/etc/cron.d/dokku-${PLUGIN_COMMAND_PREFIX}-${SERVICE}"
local TMP_CRON_FILE="${PLUGIN_DATA_ROOT}/.TMP_CRON_FILE" 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/mv "$TMP_CRON_FILE" "$CRON_FILE"
sudo /bin/chown root:root "$CRON_FILE" sudo /bin/chown root:root "$CRON_FILE"
sudo /bin/chmod 644 "$CRON_FILE" sudo /bin/chmod 644 "$CRON_FILE"
@@ -235,14 +273,29 @@ service_backup_unset_encryption() {
rm -rf "$SERVICE_BACKUP_ENCRYPTION_ROOT" 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"
if ! docker rm "$SERVICE_NAME" > /dev/null 2>&1; then
dokku_log_fail "Unable to remove container for service $SERVICE"
fi
}
service_enter() { service_enter() {
declare desc="enters running app container of specified proc type" declare desc="enters running app container of specified proc type"
declare SERVICE="$1" && shift 1 declare SERVICE="$1" && shift 1
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID="$(cat "$SERVICE_ROOT/ID")" local ID="$(cat "$SERVICE_ROOT/ID")"
docker inspect "$ID" &> /dev/null || dokku_log_fail "Container does not exist" docker inspect "$ID" &> /dev/null || dokku_log_fail "Service container does not exist"
is_container_status "$ID" "Running" || dokku_log_fail "Container is not running" is_container_status "$ID" "Running" || dokku_log_fail "Service container is not running"
local EXEC_CMD="" local EXEC_CMD=""
has_tty && local DOKKU_RUN_OPTS+=" -i -t" has_tty && local DOKKU_RUN_OPTS+=" -i -t"
@@ -262,6 +315,17 @@ service_exposed_ports() {
done 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() { service_info() {
declare desc="Retrieves information about a given service" declare desc="Retrieves information about a given service"
declare SERVICE="$1" INFO_FLAG="$2" declare SERVICE="$1" INFO_FLAG="$2"
@@ -324,9 +388,22 @@ service_link() {
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local EXISTING_CONFIG=$(config_all "$APP") local EXISTING_CONFIG=$(config_all "$APP")
local LINK=$(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1) || true 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_DNS_HOSTNAME=$(service_dns_hostname "$SERVICE")
local SERVICE_ALIAS=$(service_alias "$SERVICE")
local LINKS_FILE="$SERVICE_ROOT/LINKS" 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" [[ -n $LINK ]] && dokku_log_fail "Already linked as $LINK"
mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory" mkdir -p "$SERVICE_ROOT" || dokku_log_fail "Unable to create service directory"
@@ -334,18 +411,14 @@ service_link() {
echo "$APP" >> "$LINKS_FILE" echo "$APP" >> "$LINKS_FILE"
sort "$LINKS_FILE" -u -o "$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 if declare -f -F add_passed_docker_option > /dev/null; then
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local passed_phases=(build deploy run) 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 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 fi
[[ -n "$SERVICE_QUERYSTRING" ]] && SERVICE_URL="${SERVICE_URL}?${SERVICE_QUERYSTRING}"
config_set "$APP" "${ALIAS}_URL=$SERVICE_URL" config_set "$APP" "${ALIAS}_URL=$SERVICE_URL"
} }
@@ -387,8 +460,11 @@ service_logs() {
DOKKU_LOGS_ARGS="--follow" DOKKU_LOGS_ARGS="--follow"
fi 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 # shellcheck disable=SC2086
docker logs $DOKKU_LOGS_ARGS "$ID" docker logs $DOKKU_LOGS_ARGS "$ID" 2> /dev/null
} }
service_parse_args() { service_parse_args() {
@@ -398,26 +474,27 @@ service_parse_args() {
for arg in "$@"; do for arg in "$@"; do
shift shift
case "$arg" in case "$arg" in
"--config-options") set -- "$@" "-c" ;; "--alias") set -- "$@" "-a" ;;
"--custom-env") set -- "$@" "-C" ;; "--config-options") set -- "$@" "-c" ;;
"--image") set -- "$@" "-i" ;; "--custom-env") set -- "$@" "-C" ;;
"--image-version") set -- "$@" "-I" ;; "--database") set -- "$@" "-d" ;;
"--password") set -- "$@" "-p" ;; "--image-version") set -- "$@" "-I" ;;
"--root-password") set -- "$@" "-r" ;; "--image") set -- "$@" "-i" ;;
"--memory") set -- "$@" "-m" ;;
"--alias") set -- "$@" "-a" ;; "--password") set -- "$@" "-p" ;;
"--database") set -- "$@" "-d" ;; "--querystring") set -- "$@" "-q" ;;
"--memory") set -- "$@" "-m" ;; "--restart-apps") set -- "$@" "-R" ;;
"--querystring") set -- "$@" "-q" ;; "--root-password") set -- "$@" "-r" ;;
"--user") set -- "$@" "-u" ;; "--user") set -- "$@" "-u" ;;
*) set -- "$@" "$arg" *) set -- "$@" "$arg"
esac esac
done done
OPTIND=1 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 case "$opt" in
a) export SERVICE_ALIAS=$OPTARG a)
SERVICE_ALIAS="${OPTARG^^}"; export SERVICE_ALIAS="${SERVICE_ALIAS%_URL}"
;; ;;
c) export PLUGIN_CONFIG_OPTIONS=$OPTARG c) export PLUGIN_CONFIG_OPTIONS=$OPTARG
;; ;;
@@ -433,7 +510,9 @@ service_parse_args() {
;; ;;
p) export SERVICE_PASSWORD=$OPTARG 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 r) export SERVICE_ROOT_PASSWORD=$OPTARG
;; ;;
@@ -565,13 +644,17 @@ service_status() {
declare SERVICE="$1" declare SERVICE="$1"
local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE"
local ID="$(cat "$SERVICE_ROOT/ID")" local ID="$(cat "$SERVICE_ROOT/ID")"
local CONTAINER_STATUS
is_container_status "$ID" "Dead" && echo "dead" && return 0 is_container_status "$ID" "Dead" && echo "dead" && return 0
is_container_status "$ID" "OOMKilled" && echo "oomkilled" && return 0 is_container_status "$ID" "OOMKilled" && echo "oomkilled" && return 0
is_container_status "$ID" "Paused" && echo "paused" && return 0 is_container_status "$ID" "Paused" && echo "paused" && return 0
is_container_status "$ID" "Restarting" && echo "restarting" && return 0 is_container_status "$ID" "Restarting" && echo "restarting" && return 0
is_container_status "$ID" "Running" && echo "running" && 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() { service_stop() {
@@ -583,10 +666,10 @@ service_stop() {
[[ -z $ID ]] && dokku_log_warn "Service is already stopped" && return 0 [[ -z $ID ]] && dokku_log_warn "Service is already stopped" && return 0
if [[ -n $ID ]]; then if [[ -n $ID ]]; then
dokku_log_info1_quiet "Stopping container" dokku_log_info2_quiet "Stopping container"
docker stop "$SERVICE_NAME" > /dev/null docker stop "$SERVICE_NAME" > /dev/null
service_port_pause "$SERVICE" service_port_pause "$SERVICE"
dokku_log_info2 "Container stopped" dokku_log_verbose_quiet "Container stopped"
else else
dokku_log_verbose_quiet "No container exists for $SERVICE" dokku_log_verbose_quiet "No container exists for $SERVICE"
fi fi
@@ -599,7 +682,7 @@ service_unlink() {
local SERVICE_URL=$(service_url "$SERVICE") local SERVICE_URL=$(service_url "$SERVICE")
local SERVICE_NAME="$(get_service_name "$SERVICE")" local SERVICE_NAME="$(get_service_name "$SERVICE")"
local EXISTING_CONFIG=$(config_all "$APP") 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 local LINK=($(echo "$EXISTING_CONFIG" | grep "$SERVICE_URL" | cut -d: -f1)) || true
remove_from_links_file "$SERVICE" "$APP" remove_from_links_file "$SERVICE" "$APP"
@@ -607,9 +690,9 @@ service_unlink() {
if declare -f -F add_passed_docker_option > /dev/null; then if declare -f -F add_passed_docker_option > /dev/null; then
# shellcheck disable=SC2034 # shellcheck disable=SC2034
local passed_phases=(build deploy run) 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 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 fi
[[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP" [[ -z ${LINK[*]} ]] && dokku_log_fail "Not linked to app $APP"
@@ -620,7 +703,7 @@ service_version() {
declare desc="Displays the running version for an image" declare desc="Displays the running version for an image"
declare SERVICE="$1" declare SERVICE="$1"
local SERVICE_NAME="$(get_service_name "$SERVICE")" 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() { update_plugin_scheme_for_app() {

3
config
View File

@@ -1,9 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
export POSTGRES_IMAGE=${POSTGRES_IMAGE:="postgres"} export POSTGRES_IMAGE=${POSTGRES_IMAGE:="postgres"}
export POSTGRES_IMAGE_VERSION=${POSTGRES_IMAGE_VERSION:="10.2"} export POSTGRES_IMAGE_VERSION=${POSTGRES_IMAGE_VERSION:="10.4"}
export POSTGRES_ROOT=${POSTGRES_ROOT:="/var/lib/dokku/services/postgres"} export POSTGRES_ROOT=${POSTGRES_ROOT:="/var/lib/dokku/services/postgres"}
export POSTGRES_HOST_ROOT=${POSTGRES_HOST_ROOT:=$POSTGRES_ROOT} export POSTGRES_HOST_ROOT=${POSTGRES_HOST_ROOT:=$POSTGRES_ROOT}
export PLUGIN_UNIMPLEMENTED_SUBCOMMANDS=()
export PLUGIN_COMMAND_PREFIX="postgres" export PLUGIN_COMMAND_PREFIX="postgres"
export PLUGIN_CONFIG_ROOT=${PLUGIN_CONFIG_ROOT:="$DOKKU_LIB_ROOT/config/$PLUGIN_COMMAND_PREFIX"} export PLUGIN_CONFIG_ROOT=${PLUGIN_CONFIG_ROOT:="$DOKKU_LIB_ROOT/config/$PLUGIN_COMMAND_PREFIX"}
export PLUGIN_DATA_ROOT=$POSTGRES_ROOT export PLUGIN_DATA_ROOT=$POSTGRES_ROOT

View File

@@ -29,7 +29,7 @@ service_create() {
service_parse_args "${@:2}" 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 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 "${PLUGIN_DISABLE_PULL_VARIABLE} environment variable detected. Not running pull command." 1>&2
dokku_log_warn " docker pull ${IMAGE}" 1>&2 dokku_log_warn " docker pull ${IMAGE}" 1>&2
@@ -75,7 +75,7 @@ service_create_container() {
dokku_log_verbose_quiet "Creating container database" dokku_log_verbose_quiet "Creating container database"
DATABASE_NAME="$(get_database_name "$SERVICE")" DATABASE_NAME="$(get_database_name "$SERVICE")"
docker exec "$SERVICE_NAME" su - postgres -c "createdb -E utf8 $DATABASE_NAME" 2> /dev/null || echo 'Already exists' docker exec "$SERVICE_NAME" su - postgres -c "createdb -E utf8 $DATABASE_NAME" 2> /dev/null || dokku_log_verbose_quiet 'Already exists'
dokku_log_verbose_quiet "Securing connection to database" dokku_log_verbose_quiet "Securing connection to database"
service_stop "$SERVICE" > /dev/null service_stop "$SERVICE" > /dev/null
@@ -114,7 +114,7 @@ service_import() {
if [[ -t 0 ]]; then if [[ -t 0 ]]; then
dokku_log_fail "No data provided on stdin." dokku_log_fail "No data provided on stdin."
fi fi
docker exec -i "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_restore -h localhost -cO -d "$DATABASE_NAME" -U postgres -w docker exec -i "$SERVICE_NAME" env PGPASSWORD="$PASSWORD" pg_restore -h localhost -cO --if-exists -d "$DATABASE_NAME" -U postgres -w
} }
service_start() { service_start() {
@@ -128,16 +128,15 @@ service_start() {
return 0 return 0
fi fi
dokku_log_info1_quiet "Starting container" dokku_log_info2_quiet "Starting container"
local PREVIOUS_ID=$(docker ps -f status=exited | grep -e "$SERVICE_NAME$" | awk '{print $1}') || true 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)
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")" local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
if [[ -n $PREVIOUS_ID ]]; then if [[ -n $PREVIOUS_ID ]]; then
docker start "$PREVIOUS_ID" > /dev/null docker start "$PREVIOUS_ID" > /dev/null
service_port_unpause "$SERVICE" service_port_unpause "$SERVICE"
dokku_log_info2 "Container started" dokku_log_info2 "Container started"
elif $IMAGE_EXISTS && [[ -n "$PASSWORD" ]]; then elif service_image_exists "$SERVICE" && [[ -n "$PASSWORD" ]]; then
service_create_container "$SERVICE" service_create_container "$SERVICE"
else else
dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE" dokku_log_verbose_quiet "Neither container nor valid configuration exists for $SERVICE"
@@ -150,6 +149,6 @@ service_url() {
local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")" local PASSWORD="$(cat "$SERVICE_ROOT/PASSWORD")"
local DATABASE_NAME="$(get_database_name "$SERVICE")" local DATABASE_NAME="$(get_database_name "$SERVICE")"
local SERVICE_ALIAS="$(service_alias "$SERVICE")" local SERVICE_DNS_HOSTNAME="$(service_dns_hostname "$SERVICE")"
echo "$PLUGIN_SCHEME://postgres:$PASSWORD@$SERVICE_ALIAS:${PLUGIN_DATASTORE_PORTS[0]}/$DATABASE_NAME" echo "$PLUGIN_SCHEME://postgres:$PASSWORD@$SERVICE_DNS_HOSTNAME:${PLUGIN_DATASTORE_PORTS[0]}/$DATABASE_NAME"
} }

View File

@@ -1,6 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x 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" export SUBCOMMAND_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/subcommands"
fn-help() { fn-help() {
@@ -75,7 +76,7 @@ fn-help-contents() {
fn-help-contents-subcommand() { fn-help-contents-subcommand() {
declare SUBCOMMAND="$1" FULL_OUTPUT="$2" declare SUBCOMMAND="$1" FULL_OUTPUT="$2"
local TMPDIR=$(mktemp -d) 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 local BOLD CMD_OUTPUT CYAN EXAMPLE LIGHT_GRAY NORMAL
trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT trap 'rm -rf "$TMPDIR" > /dev/null' RETURN INT TERM EXIT
@@ -83,7 +84,7 @@ fn-help-contents-subcommand() {
cat "$SUBCOMMAND_ROOT/$SUBCOMMAND" > "$UNCLEAN_FILE" cat "$SUBCOMMAND_ROOT/$SUBCOMMAND" > "$UNCLEAN_FILE"
fn-help-subcommand-sanitize "$UNCLEAN_FILE" "$CLEAN_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 return 1
fi fi
@@ -138,18 +139,6 @@ fn-help-contents-subcommand() {
return 0 return 0
} }
fn-help-is-subcommand-unimplemented() {
declare FUNC_FILE="$1"
local UNIMPLEMENTED
UNIMPLEMENTED="$(grep "Not yet implemented" "$FUNC_FILE" | head -1 || true)"
if [[ -n "$UNIMPLEMENTED" ]]; then
echo true
else
echo false
fi
}
fn-help-list-example() { fn-help-list-example() {
# shellcheck disable=SC2034 # shellcheck disable=SC2034
declare desc="return $PLUGIN_COMMAND_PREFIX plugin help content" declare desc="return $PLUGIN_COMMAND_PREFIX plugin help content"

View File

@@ -1,4 +1,4 @@
[plugin] [plugin]
description = "dokku postgres service plugin" description = "dokku postgres service plugin"
version = "1.2.0" version = "1.4.7"
[plugin.config] [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() { service-backup-cmd() {
#E backup the 'lolipop' service to the 'my-s3-bucket' bucket on AWS #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 #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 service, service to run command against
#A bucket-name, name of the s3 bucket to upload backups to #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" 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 local cmd="$PLUGIN_COMMAND_PREFIX:backup" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" BUCKET_NAME="$2" USE_IAM_OPTIONAL_FLAG="$3" 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 "$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" [[ -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" 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 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" 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 "$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" [[ -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" declare desc="removes backup authentication for the $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-deauth" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 local cmd="$PLUGIN_COMMAND_PREFIX:backup-deauth" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$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" [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$SERVICE" verify_service_name "$SERVICE"

View File

@@ -7,19 +7,23 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
service-backup-schedule-cmd() { service-backup-schedule-cmd() {
#E schedule a backup #E schedule a backup
#E > 'schedule' is a crontab expression, eg. "0 3 * * *" for each day at 3am #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 service, service to run command against
#A schedule, a cron schedule to run backups on #A schedule, a cron schedule to run backups on
#A bucket-name, name of the s3 bucket to upload backups to #A bucket-name, name of the s3 bucket to upload backups to
declare desc="schedules a backup of the $PLUGIN_SERVICE service" declare desc="schedules a backup of the $PLUGIN_SERVICE service"
local cmd="$PLUGIN_COMMAND_PREFIX:backup-schedule" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 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 "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
[[ -z "$SCHEDULE" ]] && dokku_log_fail "Please specify a schedule for the backup" [[ -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" [[ -z "$BUCKET_NAME" ]] && dokku_log_fail "Please specify an aws bucket for the backup"
verify_service_name "$SERVICE" 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 "$@" service-backup-schedule-cmd "$@"

View File

@@ -12,6 +12,7 @@ service-backup-set-encryption-cmd() {
declare desc="sets encryption for all future backups of $PLUGIN_SERVICE service" 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 local cmd="$PLUGIN_COMMAND_PREFIX:backup-set-encryption" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" ENCRYPTION_KEY="$2" declare SERVICE="$1" ENCRYPTION_KEY="$2"
is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented"
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" [[ -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 "$ENCRYPTION_KEY" ]] && dokku_log_fail "Please specify a GPG encryption key"

View File

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

View File

@@ -9,21 +9,34 @@ service-clone-cmd() {
#E dokku $PLUGIN_COMMAND_PREFIX:clone lolipop lolipop-2 #E dokku $PLUGIN_COMMAND_PREFIX:clone lolipop lolipop-2
#A service, service to run command against #A service, service to run command against
#A new-service, name of new service #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>" 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 local cmd="$PLUGIN_COMMAND_PREFIX:clone" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" NEW_SERVICE="$2" CLONE_FLAGS_LIST="${@:3}" 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 "$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" [[ -z "$NEW_SERVICE" ]] && dokku_log_fail "Please specify a name for the new service"
verify_service_name "$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=$(service_version "$SERVICE" | grep -o "^.*:" | sed -r "s/://g")
PLUGIN_IMAGE_VERSION=$(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}" service_create "$NEW_SERVICE" "${@:3}"
dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE" dokku_log_info1 "Copying data from $SERVICE to $NEW_SERVICE"
service_export "$SERVICE" | service_import "$NEW_SERVICE" > /dev/null 2>&1 || true service_export "$SERVICE" | service_import "$NEW_SERVICE" > /dev/null 2>&1 || true
dokku_log_info1 "Done" dokku_log_info2 "Done"
} }
service-clone-cmd "$@" 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 connect to the service via the $PLUGIN_COMMAND_PREFIX connection tool
#E dokku $PLUGIN_COMMAND_PREFIX:connect lolipop #E dokku $PLUGIN_COMMAND_PREFIX:connect lolipop
#A service, service to run command against #A service, service to run command against
declare desc="connect via psql 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 local cmd="$PLUGIN_COMMAND_PREFIX:connect" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$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" [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$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 export ${PLUGIN_DEFAULT_ALIAS}_CUSTOM_ENV="USER=alpha;HOST=beta"
#E dokku $PLUGIN_COMMAND_PREFIX:create lolipop #E dokku $PLUGIN_COMMAND_PREFIX:create lolipop
#A service, service to run command against #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 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 -p|--password PASSWORD, override the user-level service password
#F -r|--root-password PASSWORD, override the root-level service password #F -r|--root-password PASSWORD, override the root-level service password
declare desc="create a $PLUGIN_SERVICE service" declare desc="create a $PLUGIN_SERVICE service"

View File

@@ -37,7 +37,7 @@ service-destroy-cmd() {
fi fi
fi fi
dokku_log_info1 "Deleting $SERVICE" dokku_log_info2_quiet "Deleting $SERVICE"
if [[ -n $(docker ps -aq -f name="$SERVICE_NAME") ]]; then if [[ -n $(docker ps -aq -f name="$SERVICE_NAME") ]]; then
dokku_log_verbose_quiet "Deleting container data" dokku_log_verbose_quiet "Deleting container data"
service_stop "$SERVICE" service_stop "$SERVICE"
@@ -51,7 +51,7 @@ service-destroy-cmd() {
fi fi
dokku_log_verbose_quiet "Removing data" 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" rm -rf "$SERVICE_ROOT"
dokku_log_info2 "$PLUGIN_SERVICE container deleted: $SERVICE" 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" declare desc="export a dump of the $PLUGIN_SERVICE service database"
local cmd="$PLUGIN_COMMAND_PREFIX:export" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 local cmd="$PLUGIN_COMMAND_PREFIX:export" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$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" [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$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" declare desc="import a dump into the $PLUGIN_SERVICE service database"
local cmd="$PLUGIN_COMMAND_PREFIX:import" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 local cmd="$PLUGIN_COMMAND_PREFIX:import" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$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" [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service"
verify_service_name "$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 #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 service, service to run command against
#A app, app 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" declare desc="link the $PLUGIN_SERVICE service to the app"
local cmd="$PLUGIN_COMMAND_PREFIX:link" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 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"} APP=${APP:="$DOKKU_APP_NAME"}
[[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a name for the service" [[ -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" [[ -z "$APP" ]] && dokku_log_fail "Please specify an app to run the command on"
verify_app_name "$APP" verify_app_name "$APP"
verify_service_name "$SERVICE" verify_service_name "$SERVICE"
service_parse_args "${@:3}"
service_link "$SERVICE" "$APP" service_link "$SERVICE" "$APP"
} }

55
subcommands/upgrade Executable file
View File

@@ -0,0 +1,55 @@
#!/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"
local ID="$(cat "$SERVICE_ROOT/ID")"
is_container_status "$ID" "Running" || dokku_log_fail "Service ${SERVICE} container is not running"
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
dokku_log_info2 "Upgrading $SERVICE to $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION"
if [[ "$SERVICE_RESTART_APPS" == "true" ]]; then
dokku_log_info2 "Stopping all linked services"
for app in $(service_linked_apps "$SERVICE"); do
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
ps_start "$app"
done
fi
dokku_log_info2 "Done"
}
service-upgrade-cmd "$@"

View File

@@ -22,7 +22,7 @@ case "$1" in
echo "mongo 3.2.9 12eadb136159 2 days ago 291.1 MB" echo "mongo 3.2.9 12eadb136159 2 days ago 291.1 MB"
echo "mysql 5.7.12 57d56ac47bed 2 days ago 321.3 MB" echo "mysql 5.7.12 57d56ac47bed 2 days ago 321.3 MB"
echo "nats 0.9.4 9216d5a4eec8 2 days ago 109.3 MB" echo "nats 0.9.4 9216d5a4eec8 2 days ago 109.3 MB"
echo "postgres 10.2 6412eb70175e 2 days ago 265.7 MB" echo "postgres 10.4 6412eb70175e 2 days ago 265.7 MB"
echo "rabbitmq 3.6.5-management 327b803301e9 2 days ago 143.5 MB" echo "rabbitmq 3.6.5-management 327b803301e9 2 days ago 143.5 MB"
echo "redis 3.2.3 9216d5a4eec8 2 days ago 109.3 MB" echo "redis 3.2.3 9216d5a4eec8 2 days ago 109.3 MB"
echo "rethinkdb 2.3.4 f27010a550ec 2 days ago 196.3 MB" echo "rethinkdb 2.3.4 f27010a550ec 2 days ago 196.3 MB"
@@ -71,7 +71,7 @@ case "$1" in
echo 'c0f74fc90377 mongo:3.2.9 "/entrypoint.sh mong" 11 seconds ago Up 10 seconds 27017/tcp dokku.mongo.l' echo 'c0f74fc90377 mongo:3.2.9 "/entrypoint.sh mong" 11 seconds ago Up 10 seconds 27017/tcp dokku.mongo.l'
echo '0f33b1c86da9 mysql:5.7.12 "/entrypoint.sh mysq" 11 seconds ago Up 10 seconds 3306/tcp dokku.mysql.l' echo '0f33b1c86da9 mysql:5.7.12 "/entrypoint.sh mysq" 11 seconds ago Up 10 seconds 3306/tcp dokku.mysql.l'
echo '9f10b6dc12d5 nats:0.9.4 "/entrypoint.sh redi" 11 seconds ago Up 10 seconds 4222/tcp dokku.nats.l' echo '9f10b6dc12d5 nats:0.9.4 "/entrypoint.sh redi" 11 seconds ago Up 10 seconds 4222/tcp dokku.nats.l'
echo '7f899b723c08 postgres:10.2 "/docker-entrypoint." 11 seconds ago Up 10 seconds 5432/tcp dokku.postgres.l' echo '7f899b723c08 postgres:10.4 "/docker-entrypoint." 11 seconds ago Up 10 seconds 5432/tcp dokku.postgres.l'
echo '5e50a462661e rabbitmq:3.6.5-management "/docker-entrypoint." 11 seconds ago Up 10 seconds 5672/tcp, 15672/tcp dokku.rabbitmq.l' echo '5e50a462661e rabbitmq:3.6.5-management "/docker-entrypoint." 11 seconds ago Up 10 seconds 5672/tcp, 15672/tcp dokku.rabbitmq.l'
echo 'c39ca00fa3c6 redis:3.2.3 "/entrypoint.sh redi" 11 seconds ago Up 10 seconds 6379/tcp dokku.redis.l' echo 'c39ca00fa3c6 redis:3.2.3 "/entrypoint.sh redi" 11 seconds ago Up 10 seconds 6379/tcp dokku.redis.l'
echo 'dc98c2939a80 rethinkdb:2.3.4 "rethinkdb --bind al" 11 seconds ago Up 10 seconds 8080/tcp, 28015/tcp, 29015/tcp dokku.rethinkdb.l' echo 'dc98c2939a80 rethinkdb:2.3.4 "rethinkdb --bind al" 11 seconds ago Up 10 seconds 8080/tcp, 28015/tcp, 29015/tcp dokku.rethinkdb.l'

View File

@@ -32,6 +32,6 @@ teardown() {
export ECHO_DOCKER_COMMAND="true" export ECHO_DOCKER_COMMAND="true"
run dokku "$PLUGIN_COMMAND_PREFIX:import" l < "$PLUGIN_DATA_ROOT/fake.dump" run dokku "$PLUGIN_COMMAND_PREFIX:import" l < "$PLUGIN_DATA_ROOT/fake.dump"
password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")" password="$(cat "$PLUGIN_DATA_ROOT/l/PASSWORD")"
assert_output "docker exec -i dokku.postgres.l env PGPASSWORD=$password pg_restore -h localhost -cO -d l -U postgres -w" assert_output "docker exec -i dokku.postgres.l env PGPASSWORD=$password pg_restore -h localhost -cO --if-exists -d l -U postgres -w"
} }

View File

@@ -68,3 +68,18 @@ teardown() {
assert_contains "$url" "postgres2://postgres:$password@dokku-postgres-l:5432/l" assert_contains "$url" "postgres2://postgres:$password@dokku-postgres-l:5432/l"
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app 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" "postgres://postgres:$password@dokku-postgres-l:5432/l"
dokku "$PLUGIN_COMMAND_PREFIX:unlink" l my_app
}

View File

@@ -11,20 +11,20 @@ teardown() {
@test "($PLUGIN_COMMAND_PREFIX:list) with no exposed ports, no linked apps" { @test "($PLUGIN_COMMAND_PREFIX:list) with no exposed ports, no linked apps" {
run dokku "$PLUGIN_COMMAND_PREFIX:list" run dokku "$PLUGIN_COMMAND_PREFIX:list"
assert_contains "${lines[*]}" "l postgres:10.2 running - -" assert_contains "${lines[*]}" "l postgres:10.4 running - -"
} }
@test "($PLUGIN_COMMAND_PREFIX:list) with exposed ports" { @test "($PLUGIN_COMMAND_PREFIX:list) with exposed ports" {
dokku "$PLUGIN_COMMAND_PREFIX:expose" l 4242 dokku "$PLUGIN_COMMAND_PREFIX:expose" l 4242
run dokku "$PLUGIN_COMMAND_PREFIX:list" run dokku "$PLUGIN_COMMAND_PREFIX:list"
assert_contains "${lines[*]}" "l postgres:10.2 running 5432->4242 -" assert_contains "${lines[*]}" "l postgres:10.4 running 5432->4242 -"
} }
@test "($PLUGIN_COMMAND_PREFIX:list) with linked app" { @test "($PLUGIN_COMMAND_PREFIX:list) with linked app" {
dokku apps:create my_app dokku apps:create my_app
dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app dokku "$PLUGIN_COMMAND_PREFIX:link" l my_app
run dokku "$PLUGIN_COMMAND_PREFIX:list" run dokku "$PLUGIN_COMMAND_PREFIX:list"
assert_contains "${lines[*]}" "l postgres:10.2 running - my_app" assert_contains "${lines[*]}" "l postgres:10.4 running - my_app"
dokku --force apps:destroy my_app dokku --force apps:destroy my_app
} }

View File

@@ -24,11 +24,11 @@ teardown() {
@test "($PLUGIN_COMMAND_PREFIX:logs) success when not tailing" { @test "($PLUGIN_COMMAND_PREFIX:logs) success when not tailing" {
export ECHO_DOCKER_COMMAND="true" export ECHO_DOCKER_COMMAND="true"
run dokku "$PLUGIN_COMMAND_PREFIX:logs" l 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" { @test "($PLUGIN_COMMAND_PREFIX:logs) success when tailing" {
export ECHO_DOCKER_COMMAND="true" export ECHO_DOCKER_COMMAND="true"
run dokku "$PLUGIN_COMMAND_PREFIX:logs" l -t run dokku "$PLUGIN_COMMAND_PREFIX:logs" l -t
assert_output "docker logs --follow testid" assert_contains "docker logs --follow testid"
} }