Compare commits

...

22 Commits

Author SHA1 Message Date
Jose Diaz-Gonzalez
4948e2b91d Release 1.4.10 2018-10-11 00:05:32 -04:00
Jose Diaz-Gonzalez
621e018999 feat: skip upgrade if service is already up to date 2018-10-11 00:04:52 -04:00
Jose Diaz-Gonzalez
3641c2dc76 Release 1.4.9 2018-10-10 23:54:46 -04:00
Jose Diaz-Gonzalez
86a032a32f feat: allow removal of header from :list subcommand 2018-10-10 23:54:08 -04:00
Jose Diaz-Gonzalez
b68ae2d0bd Release 1.4.8 2018-10-10 23:48:52 -04:00
Jose Diaz-Gonzalez
30b033ee9d 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
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
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
8 changed files with 103 additions and 51 deletions

View File

@@ -279,9 +279,12 @@ service_container_rm() {
local SERVICE_NAME="$(get_service_name "$SERVICE")" local SERVICE_NAME="$(get_service_name "$SERVICE")"
service_stop "$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" dokku_log_verbose_quiet "Removing container"
if ! docker rm "$SERVICE_NAME" > /dev/null 2>&1; then if ! docker rm "$SERVICE_NAME" > /dev/null 2>&1; then
dokku_log_fail "Unable to remove container for service $SERVICE" dokku_log_fail "Unable to remove container for service $SERVICE"
fi fi
} }
@@ -437,7 +440,11 @@ service_list() {
if [[ -z $SERVICES ]]; then if [[ -z $SERVICES ]]; then
dokku_log_warn "There are no $PLUGIN_SERVICE services" dokku_log_warn "There are no $PLUGIN_SERVICE services"
else 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 for SERVICE in $SERVICES; do
LIST+="$SERVICE,$(service_version "$SERVICE"),$(service_status "$SERVICE"),$(service_exposed_ports "$SERVICE"),$(service_linked_apps "$SERVICE")\n" LIST+="$SERVICE,$(service_version "$SERVICE"),$(service_status "$SERVICE"),$(service_exposed_ports "$SERVICE"),$(service_linked_apps "$SERVICE")\n"
done done
@@ -471,24 +478,24 @@ 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) a)
SERVICE_ALIAS="${OPTARG^^}"; export SERVICE_ALIAS="${SERVICE_ALIAS%_URL}" SERVICE_ALIAS="${OPTARG^^}"; export SERVICE_ALIAS="${SERVICE_ALIAS%_URL}"
@@ -509,6 +516,8 @@ service_parse_args() {
;; ;;
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
;; ;;
u) export SERVICE_USER=$OPTARG u) export SERVICE_USER=$OPTARG

View File

@@ -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() {

View File

@@ -28,14 +28,14 @@ fn-help() {
fn-help-all() { fn-help-all() {
declare CMD="$1" SUBCOMMAND="$2" declare CMD="$1" SUBCOMMAND="$2"
local CMD_OUTPUT BLUE BOLD FULL_OUTPUT NORMAL local CMD_OUTPUT BLUE BOLD FULL_OUTPUT NORMAL
FULL_OUTPUT=true FULL_OUTPUT=true
if [[ "$CMD" = "$PLUGIN_COMMAND_PREFIX:help" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX:default" ]] ; then if [[ "$CMD" = "$PLUGIN_COMMAND_PREFIX:help" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX" ]] || [[ "$CMD" == "$PLUGIN_COMMAND_PREFIX:default" ]] ; then
BOLD="$(tput bold)" BOLD="$(fn-help-fancy-tput bold)"
NORMAL="\033[m" NORMAL="$(fn-help-fancy-color "\033[m")"
BLUE="\033[0;34m" BLUE="$(fn-help-fancy-color "\033[0;34m")"
CYAN="\033[1;36m" CYAN="$(fn-help-fancy-color "\033[1;36m")"
if [[ -n "$SUBCOMMAND" ]] && [[ "$SUBCOMMAND" != "--all" ]]; then if [[ -n "$SUBCOMMAND" ]] && [[ "$SUBCOMMAND" != "--all" ]]; then
fn-help-contents-subcommand "$SUBCOMMAND" "$FULL_OUTPUT" fn-help-contents-subcommand "$SUBCOMMAND" "$FULL_OUTPUT"
return "$?" return "$?"
@@ -76,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
@@ -95,12 +95,12 @@ fn-help-contents-subcommand() {
desc="$(grep desc "$CLEAN_FILE" | head -1)" desc="$(grep desc "$CLEAN_FILE" | head -1)"
eval "$desc" eval "$desc"
BLUE="\033[0;34m" BLUE="$(fn-help-fancy-color "\033[0;34m")"
BOLD="$(tput bold)" BOLD="$(fn-help-fancy-tput bold)"
CYAN="\033[1;36m" CYAN="$(fn-help-fancy-color "\033[1;36m")"
NORMAL="\033[m" NORMAL="$(fn-help-fancy-color "\033[m")"
LIGHT_GRAY="\033[2;37m" LIGHT_GRAY="$(fn-help-fancy-color "\033[2;37m")"
LIGHT_RED="\033[1;31m" LIGHT_RED="$(fn-help-fancy-color "\033[1;31m")"
CMD_OUTPUT="$(echo -e " ${PLUGIN_COMMAND_PREFIX}${cmd_line}, ${LIGHT_GRAY}${desc}${NORMAL}")" CMD_OUTPUT="$(echo -e " ${PLUGIN_COMMAND_PREFIX}${cmd_line}, ${LIGHT_GRAY}${desc}${NORMAL}")"
if [[ "$FULL_OUTPUT" != "true" ]]; then if [[ "$FULL_OUTPUT" != "true" ]]; then
echo "$CMD_OUTPUT" echo "$CMD_OUTPUT"
@@ -139,6 +139,26 @@ fn-help-contents-subcommand() {
return 0 return 0
} }
fn-help-fancy-tput() {
declare desc="A wrapper around tput"
if [[ -z "$DOKKU_NO_COLOR" ]] || [[ "$TERM" = "unknown" ]] || [[ "$TERM" == "dumb" ]]; then
return
fi
tput "$@"
}
fn-help-fancy-color() {
declare desc="A wrapper around colors"
if [[ -z "$DOKKU_NO_COLOR" ]] || [[ "$TERM" = "unknown" ]] || [[ "$TERM" == "dumb" ]]; then
return
fi
echo "$@"
}
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"
@@ -153,8 +173,8 @@ fn-help-subcommand-args() {
local argline arglist args argpos BLUE NORMAL local argline arglist args argpos BLUE NORMAL
if [[ "$FULL_OUTPUT" == "true" ]]; then if [[ "$FULL_OUTPUT" == "true" ]]; then
BLUE="\033[0;34m" BLUE="$(fn-help-fancy-color "\033[0;34m")"
NORMAL="\033[m" NORMAL="$(fn-help-fancy-color "\033[m")"
fi fi
argline=$(grep declare "$FUNC_FILE" | grep -v "declare desc" | head -1 || true) argline=$(grep declare "$FUNC_FILE" | grep -v "declare desc" | head -1 || true)
arglist=($(echo -e "${argline// /"\n"}" | awk -F= '/=/{print ""$1""}')) arglist=($(echo -e "${argline// /"\n"}" | awk -F= '/=/{print ""$1""}'))
@@ -199,12 +219,12 @@ fn-help-subcommand-example() {
return 0 return 0
fi fi
BOLD="$(tput bold)" BOLD="$(fn-help-fancy-tput bold)"
LAST_LINE="" LAST_LINE=""
LIGHT_GRAY="\033[2;37m" LIGHT_GRAY="$(fn-help-fancy-color "\033[2;37m")"
OTHER_GRAY="\033[7;37m" OTHER_GRAY="$(fn-help-fancy-color "\033[7;37m")"
NEWLINE="" NEWLINE=""
NORMAL="\033[m" NORMAL="$(fn-help-fancy-color "\033[m")"
_fn-help-apply-shell-expansion "$EXAMPLE" | while read -r line; do _fn-help-apply-shell-expansion "$EXAMPLE" | while read -r line; do
line="$(echo "$line" | cut -c 4-)" line="$(echo "$line" | cut -c 4-)"
if [[ "$line" == export* ]] || [[ "$line" == dokku* ]]; then if [[ "$line" == export* ]] || [[ "$line" == dokku* ]]; then
@@ -234,10 +254,10 @@ fn-help-subcommand-list-args() {
return 0 return 0
fi fi
NORMAL="\033[m" NORMAL="$(fn-help-fancy-color "\033[m")"
LIGHT_GRAY="\033[2;37m" 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}" echo -e "$(echo "$line" | cut -d',' -f1),${LIGHT_GRAY}$(echo "$line" | cut -d',' -f2-)${NORMAL}"
done done
} }
@@ -251,10 +271,10 @@ fn-help-subcommand-list-flags() {
return 0 return 0
fi fi
NORMAL="\033[m" NORMAL="$(fn-help-fancy-color "\033[m")"
LIGHT_GRAY="\033[2;37m" 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}" echo -e "$(echo "$line" | cut -d',' -f1),${LIGHT_GRAY}$(echo "$line" | cut -d',' -f2-)${NORMAL}"
done done
} }

View File

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

View File

@@ -9,9 +9,9 @@ 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 -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 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>"

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

@@ -3,17 +3,19 @@ source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config"
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_BASE_PATH/common/functions" source "$PLUGIN_BASE_PATH/common/functions"
source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions"
source "$PLUGIN_AVAILABLE_PATH/ps/functions"
service-upgrade-cmd() { service-upgrade-cmd() {
#E you can upgrade an existing service to a new image or image-version #E you can upgrade an existing service to a new image or image-version
#E dokku $PLUGIN_COMMAND_PREFIX:upgrade lolipop #E dokku $PLUGIN_COMMAND_PREFIX:upgrade 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 -R|--restart-apps "true", whether to force an app restart
declare desc="upgrade service <service> to the specified versions" declare desc="upgrade service <service> to the specified versions"
local cmd="$PLUGIN_COMMAND_PREFIX:upgrade" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 local cmd="$PLUGIN_COMMAND_PREFIX:upgrade" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1
declare SERVICE="$1" CLONE_FLAGS_LIST="${@:2}" declare SERVICE="$1" UPGRADE_FLAGS_LIST="${@:2}"
[[ -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"
@@ -28,10 +30,31 @@ service-upgrade-cmd() {
dokku_log_fail "Unable to proceed with upgrade, image ${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION} does not exist" dokku_log_fail "Unable to proceed with upgrade, image ${PLUGIN_IMAGE}:${PLUGIN_IMAGE_VERSION} does not exist"
fi fi
dokku_log_info2 "Upgrading $SERVICE to $PLUGIN_IMAGE:$PLUGIN_IMAGE_VERSION" 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
ps_stop "$app"
done
fi
dokku_log_info2 "Stopping $SERVICE" dokku_log_info2 "Stopping $SERVICE"
service_container_rm "$SERVICE" service_container_rm "$SERVICE"
service_start "$SERVICE" "${@:2}" 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" dokku_log_info2 "Done"
} }

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"
} }