subcommand restructure and bashstyle refactor. closes #1579
This commit is contained in:
committed by
Michael Hobbs
parent
76e27f0333
commit
89f289b433
@@ -1,65 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
[[ " tar-from tar:from tar-in tar:in tar-build tar-build-locked help tar:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||
[[ " help tar:help " == *" $1 "* ]] || exit "$DOKKU_NOT_IMPLEMENTED_EXIT"
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
case "$1" in
|
||||
tar-from|tar:from)
|
||||
verify_app_name "$2"
|
||||
APP=$2
|
||||
URL=$3
|
||||
shift 3
|
||||
curl -# --insecure -L "$URL" | dokku tar-in "$APP" "$@"
|
||||
;;
|
||||
|
||||
tar-in|tar:in)
|
||||
APP="$2"
|
||||
verify_app_name "$2"
|
||||
tee "$DOKKU_ROOT/$APP/src.tar" | wc -c
|
||||
plugn trigger receive-app "$APP"
|
||||
;;
|
||||
|
||||
tar-build)
|
||||
verify_app_name "$2"
|
||||
APP="$2"; APP_BUILD_LOCK="$DOKKU_ROOT/$APP/.build.lock"
|
||||
APP_BUILD_LOCK_MSG="$APP is currently being deployed or locked. Waiting..."
|
||||
[[ $(flock -n "$APP_BUILD_LOCK" true &>/dev/null ; echo $?) -ne 0 ]] && echo "$APP_BUILD_LOCK_MSG"
|
||||
|
||||
shift 1
|
||||
flock -o "$APP_BUILD_LOCK" dokku tar-build-locked "$@"
|
||||
;;
|
||||
|
||||
tar-build-locked)
|
||||
APP="$2"
|
||||
verify_app_name "$2"
|
||||
shift 2
|
||||
|
||||
# clean up after ourselves
|
||||
TMP_WORK_DIR=$(mktemp -d -t "dokku_tar.XXXX")
|
||||
trap 'rm -rf "$TMP_WORK_DIR" > /dev/null' INT TERM EXIT
|
||||
|
||||
# extract tar file
|
||||
chmod 755 "$TMP_WORK_DIR"
|
||||
pushd "$TMP_WORK_DIR" > /dev/null
|
||||
|
||||
# Detect a common prefix that all files in the tar have, and strip off each directory found in it
|
||||
COMMON_PREFIX=$(tar -tf "$DOKKU_ROOT/$APP/src.tar" | sed -e 'N;s/^\(.*\).*\n\1.*$/\1\n\1/;D')
|
||||
BOGUS_PARTS=$(echo "$COMMON_PREFIX " | awk 'BEGIN{FS="/"} {print NF-1}')
|
||||
|
||||
dokku_log_info1_quiet "Striping $BOGUS_PARTS worth of directories from tarball"
|
||||
|
||||
tar -x -C "$TMP_WORK_DIR" -f "$DOKKU_ROOT/$APP/src.tar" --strip-components="$BOGUS_PARTS"
|
||||
chmod -R u+r "$TMP_WORK_DIR"
|
||||
|
||||
if [[ -f Dockerfile ]] && [[ "$([[ -f .env ]] && grep -q BUILDPACK_URL .env; echo $?)" != "0" ]] && [[ ! -f ".buildpacks" ]]; then
|
||||
plugn trigger pre-receive-app "$APP" "dockerfile" "$TMP_WORK_DIR"
|
||||
dokku receive "$APP" "dockerfile" "$TMP_WORK_DIR" | sed -u "s/^/"$'\e[1G'"/"
|
||||
else
|
||||
plugn trigger pre-receive-app "$APP" "herokuish" "$TMP_WORK_DIR"
|
||||
dokku receive "$APP" "herokuish" "$TMP_WORK_DIR" | sed -u "s/^/"$'\e[1G'"/"
|
||||
fi
|
||||
;;
|
||||
|
||||
help | tar:help)
|
||||
cat<<EOF
|
||||
tar:in <app>, Reads an tarball containing the app from stdin
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
APP="$1"; REV="$2"
|
||||
tar_receive_app() {
|
||||
local desc="receives app tarball and calls tar:build"
|
||||
local APP="$1"; local REV="$2"
|
||||
|
||||
# Don't trigger tar build if there is no tarball.
|
||||
if [[ ! -f "$DOKKU_ROOT/$APP/src.tar" ]]; then
|
||||
true
|
||||
else
|
||||
dokku tar-build "$APP"
|
||||
fi
|
||||
# Don't trigger tar build if there is no tarball.
|
||||
if [[ ! -f "$DOKKU_ROOT/$APP/src.tar" ]]; then
|
||||
true
|
||||
else
|
||||
dokku tar:build "$APP"
|
||||
fi
|
||||
}
|
||||
|
||||
tar_receive_app "$@"
|
||||
|
||||
18
plugins/tar/subcommands/build
Executable file
18
plugins/tar/subcommands/build
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
tar_build_cmd() {
|
||||
local desc="calls tar:build-locked via command line"
|
||||
local cmd="tar:build"
|
||||
|
||||
verify_app_name "$2"
|
||||
local APP="$2"; local APP_BUILD_LOCK="$DOKKU_ROOT/$APP/.build.lock"
|
||||
local APP_BUILD_LOCK_MSG="$APP is currently being deployed or locked. Waiting..."
|
||||
[[ $(flock -n "$APP_BUILD_LOCK" true &>/dev/null ; echo $?) -ne 0 ]] && echo "$APP_BUILD_LOCK_MSG"
|
||||
|
||||
shift 1
|
||||
flock -o "$APP_BUILD_LOCK" dokku tar:build-locked "$@"
|
||||
}
|
||||
|
||||
tar_build_cmd "$@"
|
||||
39
plugins/tar/subcommands/build-locked
Executable file
39
plugins/tar/subcommands/build-locked
Executable file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
tar_build_locked_cmd() {
|
||||
local desc="builds apps from tarball via command line"
|
||||
local cmd="tar:build-locked"
|
||||
local APP="$2"
|
||||
|
||||
verify_app_name "$2"
|
||||
shift 2
|
||||
|
||||
# clean up after ourselves
|
||||
local TMP_WORK_DIR=$(mktemp -d -t "dokku_tar.XXXX")
|
||||
trap 'rm -rf "$TMP_WORK_DIR" > /dev/null' INT TERM EXIT
|
||||
|
||||
# extract tar file
|
||||
chmod 755 "$TMP_WORK_DIR"
|
||||
pushd "$TMP_WORK_DIR" > /dev/null
|
||||
|
||||
# Detect a common prefix that all files in the tar have, and strip off each directory found in it
|
||||
local COMMON_PREFIX=$(tar -tf "$DOKKU_ROOT/$APP/src.tar" | sed -e 'N;s/^\(.*\).*\n\1.*$/\1\n\1/;D')
|
||||
local BOGUS_PARTS=$(echo "$COMMON_PREFIX " | awk 'BEGIN{FS="/"} {print NF-1}')
|
||||
|
||||
dokku_log_info1_quiet "Striping $BOGUS_PARTS worth of directories from tarball"
|
||||
|
||||
tar -x -C "$TMP_WORK_DIR" -f "$DOKKU_ROOT/$APP/src.tar" --strip-components="$BOGUS_PARTS"
|
||||
chmod -R u+r "$TMP_WORK_DIR"
|
||||
|
||||
if [[ -f Dockerfile ]] && [[ "$([[ -f .env ]] && grep -q BUILDPACK_URL .env; echo $?)" != "0" ]] && [[ ! -f ".buildpacks" ]]; then
|
||||
plugn trigger pre-receive-app "$APP" "dockerfile" "$TMP_WORK_DIR"
|
||||
dokku receive "$APP" "dockerfile" "$TMP_WORK_DIR" | sed -u "s/^/"$'\e[1G'"/"
|
||||
else
|
||||
plugn trigger pre-receive-app "$APP" "herokuish" "$TMP_WORK_DIR"
|
||||
dokku receive "$APP" "herokuish" "$TMP_WORK_DIR" | sed -u "s/^/"$'\e[1G'"/"
|
||||
fi
|
||||
}
|
||||
|
||||
tar_build_locked_cmd "$@"
|
||||
15
plugins/tar/subcommands/from
Executable file
15
plugins/tar/subcommands/from
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
tar_from_cmd() {
|
||||
local desc="deploys app from tarball at URL via command line"
|
||||
local cmd="tar:from"
|
||||
verify_app_name "$2"
|
||||
local APP=$2
|
||||
local URL=$3
|
||||
shift 3
|
||||
curl -# --insecure -L "$URL" | dokku tar:in "$APP" "$@"
|
||||
}
|
||||
|
||||
tar_from_cmd "$@"
|
||||
15
plugins/tar/subcommands/in
Executable file
15
plugins/tar/subcommands/in
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
|
||||
tar_in_cmd() {
|
||||
local desc="deploys app from tarball on STDIN via command line"
|
||||
local cmd="tar:in"
|
||||
local APP="$2"
|
||||
|
||||
verify_app_name "$2"
|
||||
tee "$DOKKU_ROOT/$APP/src.tar" | wc -c
|
||||
plugn trigger receive-app "$APP"
|
||||
}
|
||||
|
||||
tar_in_cmd "$@"
|
||||
Reference in New Issue
Block a user