Merge pull request #782 from progrium/simplified-config

Simplified config
This commit is contained in:
Jose Diaz-Gonzalez
2014-11-24 13:17:27 -05:00
5 changed files with 47 additions and 92 deletions

View File

@@ -39,7 +39,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
case "$1" in case "$1" in
hello) hello)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1 [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
[[ ! -d "$DOKKU_ROOT/$APP" ]] && echo "App $APP does not exist" && exit 1 [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
APP="$2"; APP="$2";
echo "Hello $APP" echo "Hello $APP"

View File

@@ -7,15 +7,9 @@ case "$1" in
;; ;;
logs) logs)
if [[ -z $2 ]]; then [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
echo "Please specify an app to run the command on" [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
exit 1
fi
APP="$2"; APP="$2";
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
echo "App $APP does not exist"
exit 1
fi
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then
CONTAINER=$(<$DOKKU_ROOT/$APP/CONTAINER) CONTAINER=$(<$DOKKU_ROOT/$APP/CONTAINER)
@@ -30,15 +24,10 @@ case "$1" in
;; ;;
run) run)
if [[ -z $2 ]]; then [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
echo "Please specify an app to run the command on" [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
exit 1
fi
APP="$2"; IMAGE="dokku/$APP" APP="$2"; IMAGE="dokku/$APP"
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
echo "App $APP does not exist"
exit 1
fi
shift 2 shift 2
DOCKER_ARGS=$(: | pluginhook docker-args $APP) DOCKER_ARGS=$(: | pluginhook docker-args $APP)
@@ -46,11 +35,9 @@ case "$1" in
;; ;;
url) url)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
APP="$2"; APP="$2";
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
echo "App $APP does not exist"
exit 1
fi
if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then if [[ -f "$DOKKU_ROOT/$APP/URL" ]]; then
echo $(< "$DOKKU_ROOT/$APP/URL") echo $(< "$DOKKU_ROOT/$APP/URL")

View File

@@ -8,35 +8,19 @@ case "$1" in
;; ;;
apps:create) apps:create)
if [[ -z $2 ]]; then [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
echo "Please specify an app to create" [[ -d "$DOKKU_ROOT/$APP" ]] && echo " ! Name is already taken" && exit 1
exit 1
fi
APP="$2" APP="$2"
if [[ -d "$DOKKU_ROOT/$APP" ]]; then
echo " ! Name is already taken"
exit 1
fi
mkdir -p "$DOKKU_ROOT/$APP" mkdir -p "$DOKKU_ROOT/$APP"
echo "Creating $APP... done" echo "Creating $APP... done"
;; ;;
apps:destroy) apps:destroy)
if [[ -z $2 ]]; then [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
echo "Please specify an app to delete" [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
exit 1 [[ "$2" == "tls" ]] && echo "Unable to destroy tls directory" && exit 1
fi
APP="$2"; IMAGE="dokku/$APP"; APP="$2"; IMAGE="dokku/$APP";
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
echo "App $APP does not exist"
exit 1
fi
if [[ "$APP" == "tls" ]]; then
echo "Unable to destroy tls directory"
exit 1
fi
echo " ! WARNING: Potentially Destructive Action" echo " ! WARNING: Potentially Destructive Action"
echo " ! This command will destroy $APP (including all add-ons)." echo " ! This command will destroy $APP (including all add-ons)."

View File

@@ -1,28 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# Check if name is specified ENV_FILE="$DOKKU_ROOT/$2/ENV"
if [[ $1 == config ]] || [[ $1 == config:* ]]; then ENV_FILE_TEMP="$DOKKU_ROOT/$2/ENV.tmp"
if [[ -z $2 ]]; then config_create () {
echo "You must specify an app name" [ -f $ENV_FILE ] || {
exit 1 echo "-----> Creating $ENV_FILE"
else touch $ENV_FILE
APP="$2" }
ENV_FILE="$DOKKU_ROOT/$APP/ENV" }
ENV_FILE_TEMP="$DOKKU_ROOT/$APP/ENV.tmp"
# Check if app exists with the same name
if [ ! -d "$DOKKU_ROOT/$APP" ]; then
echo "App $APP does not exist"
exit 1
fi
[ -f $ENV_FILE ] || {
echo "-----> Creating $ENV_FILE"
touch $ENV_FILE
}
fi
fi
config_styled_hash () { config_styled_hash () {
vars="$1" vars="$1"
@@ -76,12 +62,12 @@ config_write() {
case "$1" in case "$1" in
config) config)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
APP="$2" APP="$2"
if [ ! -f $ENV_FILE ] || [ ! -s $ENV_FILE ] ; then config_create
echo "$APP has no config vars" [[ ! -s $ENV_FILE ]] && echo "$APP has no config vars" && exit 1
exit 1
fi
VARS=`cat $ENV_FILE | grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" | cut -d" " -f2-` VARS=`cat $ENV_FILE | grep -Eo "export ([a-zA-Z_][a-zA-Z0-9_]*=.*)" | cut -d" " -f2-`
@@ -97,14 +83,19 @@ case "$1" in
;; ;;
config:get) config:get)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
APP="$2"
if [[ -z $3 ]]; then if [[ -z $3 ]]; then
echo "Usage: dokku config:get APP KEY" echo "Usage: dokku config:get APP KEY"
echo "Must specify KEY." echo "Must specify KEY."
exit 1 exit 1
fi fi
if [ ! -f $ENV_FILE ] || [ ! -s $ENV_FILE ] ; then config_create
exit 1 if [[ ! -s $ENV_FILE ]] ; then
exit 0
fi fi
KEY="$3" KEY="$3"
@@ -113,13 +104,17 @@ case "$1" in
;; ;;
config:set) config:set)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
APP="$2"
if [[ -z "${*:3}" ]]; then if [[ -z "${*:3}" ]]; then
echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]" echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]"
echo "Must specify KEY and VALUE to set." echo "Must specify KEY and VALUE to set."
exit 1 exit 1
fi fi
APP="$2"; APP_DIR="$DOKKU_ROOT/$APP" config_create
ENV_ADD="" ENV_ADD=""
ENV_TEMP=`cat "${ENV_FILE}"` ENV_TEMP=`cat "${ENV_FILE}"`
RESTART_APP=false RESTART_APP=false
@@ -157,13 +152,17 @@ ${var}"
;; ;;
config:unset) config:unset)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
[[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
APP="$2"
if [[ -z $3 ]]; then if [[ -z $3 ]]; then
echo "Usage: dokku config:unset APP KEY1 [KEY2 ...]" echo "Usage: dokku config:unset APP KEY1 [KEY2 ...]"
echo "Must specify KEY to unset." echo "Must specify KEY to unset."
exit 1 exit 1
fi fi
APP="$2"; APP_DIR="$DOKKU_ROOT/$APP" config_create
ENV_TEMP=`cat "${ENV_FILE}"` ENV_TEMP=`cat "${ENV_FILE}"`
VARS="${*:3}" VARS="${*:3}"

View File

@@ -3,31 +3,16 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
case "$1" in case "$1" in
nginx:import-ssl) nginx:import-ssl)
if [[ -z $2 ]]; then [[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
echo "Please specify an app to create" [[ ! -d "$DOKKU_ROOT/$2" ]] && echo "App $2 does not exist" && exit 1
exit 1 [[ -t 0 ]] && echo "Tar archive containing server.crt and server.key expected on stdin" && exit 1
fi
APP="$2" APP="$2"
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
echo "App $APP does not exist"
exit 1
fi
if [[ -t 0 ]]; then
echo "Tar archive containing server.crt and server.key expected on stdin"
exit 1
fi
TEMP_DIR=`mktemp -d` TEMP_DIR=`mktemp -d`
cd $TEMP_DIR cd $TEMP_DIR
tar xvf - <&0 tar xvf - <&0
if [[ -f "$TEMP_DIR/server.crt" ]]; then [[ -f "$TEMP_DIR/server.crt" ]] && echo "Tar archive missing server.crt" && exit 1
echo "Tar archive missing server.crt" [[ -f "$TEMP_DIR/server.key" ]] && echo "Tar archive missing server.key" && exit 1
exit 1
fi
if [[ -f "$TEMP_DIR/server.key" ]]; then
echo "Tar archive missing server.key"
exit 1
fi
mkdir -p "$DOKKU_ROOT/$APP/tls" mkdir -p "$DOKKU_ROOT/$APP/tls"
mv "$TEMP_DIR/server.crt" "$DOKKU_ROOT/$APP/tls/server.crt" mv "$TEMP_DIR/server.crt" "$DOKKU_ROOT/$APP/tls/server.crt"