feat: add support for git remotes with port specified inline
Closes #8093
This commit is contained in:
3 files changed
+107
-5
No files matched your search
+35
-2
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eo pipefail
|
||||
[[ $DOKKU_TRACE ]] && set -x
|
||||
export DOKKU_PORT=${DOKKU_PORT:=22}
|
||||
export DOKKU_PORT=${DOKKU_PORT:=}
|
||||
export DOKKU_HOST=${DOKKU_HOST:=}
|
||||
export DOKKU_APP_PATH=${DOKKU_APP_PATH:=}
|
||||
|
||||
@@ -62,6 +62,35 @@ fn-dokku-host() {
|
||||
echo "$DOKKU_HOST"
|
||||
}
|
||||
|
||||
fn-dokku-app() {
|
||||
declare DOKKU_GIT_REMOTE="$1" DOKKU_REMOTE_HOST="$2"
|
||||
remote_output="$(git remote -v 2>/dev/null | grep -Ei "^${DOKKU_GIT_REMOTE}\s" | head -n 1 | awk '{print $2}')"
|
||||
|
||||
# check if there is a scheme
|
||||
if echo "$remote_output" | grep -qEi "ssh://"; then
|
||||
echo "$remote_output" | grep -Ei "ssh://dokku@$DOKKU_REMOTE_HOST" | cut -f2 -d'@' | cut -f2 -d'/' 2>/dev/null
|
||||
else
|
||||
echo "$remote_output" | grep -Ei "dokku@$DOKKU_REMOTE_HOST" | cut -f2 -d'@' | cut -f2 -d':' 2>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
fn-dokku-port() {
|
||||
declare DOKKU_GIT_REMOTE="$1" DOKKU_REMOTE_HOST="$2"
|
||||
remote_output="$(git remote -v 2>/dev/null | grep -Ei "^${DOKKU_GIT_REMOTE}\s" | head -n 1 | awk '{print $2}')"
|
||||
|
||||
if echo "$remote_output" | grep -qEi "ssh://"; then
|
||||
local output="$(echo "$remote_output" | grep -Ei "ssh://dokku@$DOKKU_REMOTE_HOST" | cut -f2 -d'@' | cut -f1 -d'/' 2>/dev/null)"
|
||||
# check if output has a : and if so, get the port
|
||||
if echo "$output" | grep -qEi ":"; then
|
||||
echo "$output" | cut -f2 -d':' 2>/dev/null
|
||||
else
|
||||
echo "22"
|
||||
fi
|
||||
else
|
||||
echo "22"
|
||||
fi
|
||||
}
|
||||
|
||||
fn-get-remote() {
|
||||
git config dokku.remote 2>/dev/null || echo "dokku"
|
||||
}
|
||||
@@ -122,13 +151,17 @@ main() {
|
||||
if [[ -z "$APP" ]]; then
|
||||
if [[ -d .git ]] || git rev-parse --git-dir &>/dev/null; then
|
||||
set +e
|
||||
APP=$(git remote -v 2>/dev/null | grep -Ei "^${DOKKU_GIT_REMOTE}\s" | grep -Ei "dokku@$DOKKU_REMOTE_HOST" | head -n 1 | cut -f2 -d'@' | cut -f1 -d' ' | cut -f2 -d':' 2>/dev/null)
|
||||
APP="$(fn-dokku-app "$DOKKU_GIT_REMOTE" "$DOKKU_REMOTE_HOST")"
|
||||
set -e
|
||||
else
|
||||
echo " ! This is not a git repository" 1>&2
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -z "$DOKKU_PORT" ]]; then
|
||||
DOKKU_PORT="$(fn-dokku-port "$DOKKU_GIT_REMOTE" "$DOKKU_REMOTE_HOST")"
|
||||
fi
|
||||
|
||||
case "$CMD" in
|
||||
remote:show)
|
||||
echo "dokku-app: $APP"
|
||||
|
||||
Reference in new issue
Block a user