Merge pull request #2950 from adelq/disable-app-autocreation

Add configuration option to disable automatic app creation
This commit is contained in:
Jose Diaz-Gonzalez
2018-03-06 01:54:14 -05:00
committed by GitHub
5 changed files with 55 additions and 19 deletions

View File

@@ -104,6 +104,7 @@ The following list config variables have special meaning and can be set in a var
| `DOKKU_DEPLOY_BRANCH` | `master` | `dokku config:set` | Branch to deploy by default. |
| `DOKKU_DISABLE_PROXY` | none | `dokku proxy:disable` <br /> `dokku proxy:enable` | Disables the proxy in front of your application, resulting in publicly routing the docker container. |
| `DOKKU_DISABLE_ANSI_PREFIX_REMOVAL` | none | `dokku config:set` <br /> `/etc/environment` <br /> `~dokku/.dokkurc` <br /> `~dokku/.dokkurc/*` | Disables removal of the ANSI prefix during deploys. Can be used in cases where the client deployer does not understand ansi escape codes. |
| `DOKKU_DISABLE_APP_AUTOCREATION` | none | `dokku config:set` | Disables automatic creation of a non-existent app on deploy. |
| `DOKKU_DOCKER_STOP_TIMEOUT` | `10` | `dokku config:set` | Configurable grace period given to the `docker stop` command. If a container has not stopped by this time, a `kill -9` signal or equivalent is sent in order to force-terminate the container. Both the `ps:stop` and `apps:destroy` commands _also_ respect this value. If not specified, the docker defaults for the [docker stop command](https://docs.docker.com/engine/reference/commandline/stop/) will be used.|
| `DOKKU_DOCKERFILE_CMD` | dockerfile cmd | `dokku config:set` | |
| `DOKKU_DOCKERFILE_CACHE_BUILD` | none | `dokku config:set` | |
@@ -119,4 +120,4 @@ The following list config variables have special meaning and can be set in a var
| `DOKKU_SKIP_DEPLOY` | | `dokku config:set` | |
| `DOKKU_SYSTEM_GROUP` | `dokku` | `/etc/environment` <br /> `~dokku/.dokkurc` <br /> `~dokku/.dokkurc/*` | System group to chown files as. |
| `DOKKU_SYSTEM_USER` | `dokku` | `/etc/environment` <br /> `~dokku/.dokkurc` <br /> `~dokku/.dokkurc/*` | System user to chown files as. |
| `DOKKU_WAIT_TO_RETIRE` | `60` | `dokku config:set` | After a successful deploy, the grace period given to old containers before they are stopped/terminated. This is useful for ensuring completion of long-running http connections. |
| `DOKKU_WAIT_TO_RETIRE` | `60` | `dokku config:set` | After a successful deploy, the grace period given to old containers before they are stopped/terminated. This is useful for ensuring completion of long-running http connections. |

View File

@@ -11,7 +11,7 @@ apps_create() {
[[ -d "$DOKKU_ROOT/$APP" ]] && dokku_log_fail "Name is already taken"
mkdir -p "$DOKKU_ROOT/$APP"
echo "Creating $APP... done"
dokku_log_info1_quiet "Creating $APP... done"
plugn trigger post-create "$APP"
}
@@ -58,3 +58,18 @@ apps_exists() {
[[ -d "$DOKKU_ROOT/$APP" ]] || dokku_log_fail "App does not exist"
dokku_log_info1 "App already exists"
}
apps_maybe_create() {
declare desc="creates an app dir if allowed"
declare APP="$1"
if [[ ! -d "$DOKKU_ROOT/$APP" ]]; then
DOKKU_GLOBAL_DISABLE_AUTOCREATE="$(config_get --global DOKKU_DISABLE_APP_AUTOCREATION || true)"
if [[ "$DOKKU_GLOBAL_DISABLE_AUTOCREATE" == "true" ]]; then
dokku_log_warn "App auto-creation disabled."
dokku_log_fail " ! Re-enable app auto-creation or create an app with 'dokku apps:create ${APP}'"
else
suppress_output apps_create "$APP"
fi
fi
}

View File

@@ -1186,3 +1186,17 @@ release_app_deploy_lock() {
flock -u "$APP_DEPLOY_LOCK_FD" && rm -f "$APP_DEPLOY_LOCK_FILE" &> /dev/null
}
suppress_output() {
declare desc="suppress all output from a given command unless there is an error"
local TMP_COMMAND_OUTPUT
TMP_COMMAND_OUTPUT=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX")
trap 'rm -rf "$TMP_COMMAND_OUTPUT" > /dev/null' RETURN INT TERM EXIT
"$@" > "$TMP_COMMAND_OUTPUT" 2>&1 || {
local exit_code="$?"
cat "$TMP_COMMAND_OUTPUT"
return "$exit_code"
}
return 0
}

View File

@@ -23,8 +23,10 @@ use_git_worktree() {
git_build_app_repo() {
declare desc="builds local git app repo for app"
verify_app_name "$1"
local APP="$1"; local REV="$2"
declare APP="$1"; local REV="$2"
local DOKKU_GLOBAL_DISABLE_AUTOCREATE
verify_app_name "$APP"
# clean up after ourselves
local GIT_BUILD_APP_REPO_TMP_WORK_DIR=$(mktemp -d "/tmp/dokku_git.XXXX")
@@ -33,7 +35,8 @@ git_build_app_repo() {
local TMP_TAG="dokku/$REV"
chmod 755 "$GIT_BUILD_APP_REPO_TMP_WORK_DIR"
unset GIT_DIR GIT_WORK_TREE
[[ ! -d "$DOKKU_ROOT/$APP" ]] && apps_create "$APP"
[[ ! -d "$DOKKU_ROOT/$APP" ]] && apps_maybe_create "$APP"
if use_git_worktree; then
# git worktree - this method uses git worktree which was introduced in git 2.5
@@ -96,20 +99,6 @@ git_trigger_build() {
fi
}
suppress_output() {
declare desc="suppress all output from a given command unless there is an error"
local TMP_COMMAND_OUTPUT
TMP_COMMAND_OUTPUT=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX")
trap 'rm -rf "$TMP_COMMAND_OUTPUT" > /dev/null' RETURN INT TERM EXIT
"$@" > "$TMP_COMMAND_OUTPUT" 2>&1 || {
local exit_code="$?"
cat "$TMP_COMMAND_OUTPUT"
return "$exit_code"
}
return 0
}
git_deploy_branch() {
declare desc="retrieve the deploy branch for a given application"
local cmd="git-hook"
@@ -196,6 +185,8 @@ git_upload_pack_cmd() {
declare APP="$2"
APP="$(echo "$APP" | perl -pe 's/(?<!\\)'\''//g' | sed 's/\\'\''/'\''/g' | sed 's/^\///g')"
is_valid_app_name "$APP"
[[ ! -d "$DOKKU_ROOT/$APP" ]] && apps_maybe_create "$APP"
plugn trigger git-pre-pull "$APP"
cat | git-upload-pack "$DOKKU_ROOT/$APP"
plugn trigger git-post-pull "$APP"
@@ -209,6 +200,8 @@ git_glob_cmd() {
is_valid_app_name "$APP"
if [[ $1 == "git-receive-pack" && ! -d "$APP_PATH/refs" ]]; then
[[ ! -d "$DOKKU_ROOT/$APP" ]] && apps_maybe_create "$APP"
git init --bare "$APP_PATH" > /dev/null
local PRERECEIVE_HOOK="$APP_PATH/hooks/pre-receive"
cat > "$PRERECEIVE_HOOK" <<EOF

View File

@@ -53,6 +53,19 @@ teardown () {
destroy_app
}
@test "(apps) app autocreate disabled" {
run dokku config:set --no-restart --global DOKKU_DISABLE_APP_AUTOCREATION='true'
echo "output: "$output
echo "status: "$status
assert_success
run deploy_app
echo "output: "$output
echo "status: "$status
assert_failure
run dokku config:unset --no-restart --global DOKKU_DISABLE_APP_AUTOCREATION
}
@test "(apps) apps:destroy" {
create_app
run bash -c "dokku --force apps:destroy $TEST_APP"