From b3ddbe7f4c06bb0aa59bcec696ea39b0a5998076 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Thu, 11 Jun 2020 19:01:04 +0200 Subject: [PATCH 01/19] feat: allow cloning via ssh --- posix/clone | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/posix/clone b/posix/clone index dc18d69..8666951 100755 --- a/posix/clone +++ b/posix/clone @@ -19,14 +19,19 @@ fi # the ssh key and add the netrc machine to the # known hosts file. -if [[ ! -z "${SSH_KEY}" ]]; then +if [[ -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" ]]; then mkdir /root/.ssh - echo -n "$SSH_KEY" > /root/.ssh/id_rsa + echo -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" > /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts - ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null + if [[ -n "${SSH_HOST_KEYS:-$PLUGIN_SSH_HOST_KEYS}" ]]; then + echo -n "${SSH_HOST_KEYS:-$PLUGIN_SSH_HOST_KEYS}" > /root/.ssh/known_hosts + else + ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null + fi + export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi # configure git global behavior and parameters via the From a07e4b37c1b90c40f3ad4f30367f3e472fa0b171 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Thu, 18 Jun 2020 01:50:28 +0200 Subject: [PATCH 02/19] debug output --- posix/clone | 1 + 1 file changed, 1 insertion(+) diff --git a/posix/clone b/posix/clone index 8666951..6bd719a 100755 --- a/posix/clone +++ b/posix/clone @@ -32,6 +32,7 @@ if [[ -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" ]]; then ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" + echo "DRONE_REMOTE_URL=$DRONE_REMOTE_URL" fi # configure git global behavior and parameters via the From d49b20d920b7ccd737cb1c1fd5809e65ee8859f4 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Fri, 17 Jul 2020 12:15:17 +0200 Subject: [PATCH 03/19] doc: add fork info --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 879119a..9a83821 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +Fork from https://github.com/drone/drone-git to allow cloning via ssh. + # drone-git Drone plugin to clone `git` repositories. From d6c8bfba393c4a05fd6ed1adbe9a9d6920d3141b Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Sat, 18 Jul 2020 16:49:40 +0200 Subject: [PATCH 04/19] remove debug output --- posix/clone | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/posix/clone b/posix/clone index 6bd719a..85f84c0 100755 --- a/posix/clone +++ b/posix/clone @@ -21,7 +21,7 @@ fi if [[ -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" ]]; then mkdir /root/.ssh - echo -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" > /root/.ssh/id_rsa + printf "${SSH_KEY:-$PLUGIN_SSH_KEY}" > /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa touch /root/.ssh/known_hosts @@ -32,7 +32,6 @@ if [[ -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" ]]; then ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" - echo "DRONE_REMOTE_URL=$DRONE_REMOTE_URL" fi # configure git global behavior and parameters via the From a80cf9b8b93c81d65f067285b25f6d3ee7c7117a Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 19:52:07 +0200 Subject: [PATCH 05/19] add debug output --- posix/clone | 1 + 1 file changed, 1 insertion(+) diff --git a/posix/clone b/posix/clone index 85f84c0..356019e 100755 --- a/posix/clone +++ b/posix/clone @@ -19,6 +19,7 @@ fi # the ssh key and add the netrc machine to the # known hosts file. +printenv if [[ -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" ]]; then mkdir /root/.ssh printf "${SSH_KEY:-$PLUGIN_SSH_KEY}" > /root/.ssh/id_rsa From 11b2ed2df4adbbd3579015abfbb612babf34a9a5 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 20:01:34 +0200 Subject: [PATCH 06/19] add log message --- posix/clone | 1 + 1 file changed, 1 insertion(+) diff --git a/posix/clone b/posix/clone index 356019e..f1c3950 100755 --- a/posix/clone +++ b/posix/clone @@ -33,6 +33,7 @@ if [[ -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" ]]; then ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" + echo DRONE_REMOTE_URL=$DRONE_REMOTE_URL fi # configure git global behavior and parameters via the From d1731a2b8ddab2ad6e7ff9e76b45c9a84235ba5c Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 20:07:16 +0200 Subject: [PATCH 07/19] remove debug output --- posix/clone | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/posix/clone b/posix/clone index f1c3950..bfbe50c 100755 --- a/posix/clone +++ b/posix/clone @@ -19,21 +19,19 @@ fi # the ssh key and add the netrc machine to the # known hosts file. -printenv -if [[ -n "${SSH_KEY:-$PLUGIN_SSH_KEY}" ]]; then +if [[ ! -z "${SSH_KEY}" ]]; then mkdir /root/.ssh - printf "${SSH_KEY:-$PLUGIN_SSH_KEY}" > /root/.ssh/id_rsa + printf "${SSH_KEY}" > /root/.ssh/id_rsa chmod 600 /root/.ssh/id_rsa touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts - if [[ -n "${SSH_HOST_KEYS:-$PLUGIN_SSH_HOST_KEYS}" ]]; then - echo -n "${SSH_HOST_KEYS:-$PLUGIN_SSH_HOST_KEYS}" > /root/.ssh/known_hosts + if [[ -n "${SSH_HOST_KEYS}" ]]; then + echo -n "${SSH_HOST_KEYS}" > /root/.ssh/known_hosts else ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" - echo DRONE_REMOTE_URL=$DRONE_REMOTE_URL fi # configure git global behavior and parameters via the From 90bf1ce8d298a8d6a65f1d589fe2f096d8f1efc0 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 20:12:53 +0200 Subject: [PATCH 08/19] add debug output --- posix/clone | 2 ++ 1 file changed, 2 insertions(+) diff --git a/posix/clone b/posix/clone index bfbe50c..b467b58 100755 --- a/posix/clone +++ b/posix/clone @@ -19,6 +19,7 @@ fi # the ssh key and add the netrc machine to the # known hosts file. +printf "${SSH_KEY}" if [[ ! -z "${SSH_KEY}" ]]; then mkdir /root/.ssh printf "${SSH_KEY}" > /root/.ssh/id_rsa @@ -33,6 +34,7 @@ if [[ ! -z "${SSH_KEY}" ]]; then fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi +echo DRONE_REMOTE_URL="$DRONE_REMOTE_URL" # configure git global behavior and parameters via the # following environment variables: From 0050f30895ef9d99ed512f6a344f6c379b8a9e72 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 22:14:17 +0200 Subject: [PATCH 09/19] debug output --- posix/clone | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/posix/clone b/posix/clone index b467b58..6a06284 100755 --- a/posix/clone +++ b/posix/clone @@ -19,7 +19,6 @@ fi # the ssh key and add the netrc machine to the # known hosts file. -printf "${SSH_KEY}" if [[ ! -z "${SSH_KEY}" ]]; then mkdir /root/.ssh printf "${SSH_KEY}" > /root/.ssh/id_rsa @@ -30,11 +29,12 @@ if [[ ! -z "${SSH_KEY}" ]]; then if [[ -n "${SSH_HOST_KEYS}" ]]; then echo -n "${SSH_HOST_KEYS}" > /root/.ssh/known_hosts else - ssh-keyscan -H ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null + ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" + echo DRONE_NETRC_MACHINE=$DRONE_NETRC_MACHINE + echo DRONE_REMOTE_URL="$DRONE_REMOTE_URL" fi -echo DRONE_REMOTE_URL="$DRONE_REMOTE_URL" # configure git global behavior and parameters via the # following environment variables: From ea97b12db172e3f120377480a939affd6c314fd0 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 22:17:09 +0200 Subject: [PATCH 10/19] fix: empty string test --- posix/clone | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/posix/clone b/posix/clone index 6a06284..74e644f 100755 --- a/posix/clone +++ b/posix/clone @@ -26,12 +26,13 @@ if [[ ! -z "${SSH_KEY}" ]]; then touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts - if [[ -n "${SSH_HOST_KEYS}" ]]; then + if [[ ! -z "${SSH_HOST_KEYS}" ]]; then echo -n "${SSH_HOST_KEYS}" > /root/.ssh/known_hosts else ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" + echo SSH_HOST_KEYS=$SSH_HOST_KEYS echo DRONE_NETRC_MACHINE=$DRONE_NETRC_MACHINE echo DRONE_REMOTE_URL="$DRONE_REMOTE_URL" fi From fbaf418eeb90da67b6bd632a22cce53e2a8ae2cc Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 22:19:37 +0200 Subject: [PATCH 11/19] remove debug output --- posix/clone | 3 --- 1 file changed, 3 deletions(-) diff --git a/posix/clone b/posix/clone index 74e644f..479b559 100755 --- a/posix/clone +++ b/posix/clone @@ -32,9 +32,6 @@ if [[ ! -z "${SSH_KEY}" ]]; then ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" - echo SSH_HOST_KEYS=$SSH_HOST_KEYS - echo DRONE_NETRC_MACHINE=$DRONE_NETRC_MACHINE - echo DRONE_REMOTE_URL="$DRONE_REMOTE_URL" fi # configure git global behavior and parameters via the From 121bf280231c2e04a4d32178b06b7154f9f5b891 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 22:25:30 +0200 Subject: [PATCH 12/19] remove host key addition --- posix/clone | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/posix/clone b/posix/clone index 479b559..7977ffb 100755 --- a/posix/clone +++ b/posix/clone @@ -26,11 +26,7 @@ if [[ ! -z "${SSH_KEY}" ]]; then touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts - if [[ ! -z "${SSH_HOST_KEYS}" ]]; then - echo -n "${SSH_HOST_KEYS}" > /root/.ssh/known_hosts - else - ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null - fi + ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi From 6135bfae564565a574354b12c7e712a42e3fb2d5 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 22:34:30 +0200 Subject: [PATCH 13/19] test DRONE_NETRC_MACHINE --- posix/clone | 1 + 1 file changed, 1 insertion(+) diff --git a/posix/clone b/posix/clone index 7977ffb..a4efff3 100755 --- a/posix/clone +++ b/posix/clone @@ -26,6 +26,7 @@ if [[ ! -z "${SSH_KEY}" ]]; then touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts + echo DRONE_NETRC_MACHINE=$DRONE_NETRC_MACHINE ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi From 7206530b26bd398d11f8258c6a7323f8332e5d67 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 22:40:39 +0200 Subject: [PATCH 14/19] try DRONE_NETRC_MACHINE --- posix/clone | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/posix/clone b/posix/clone index a4efff3..32aac85 100755 --- a/posix/clone +++ b/posix/clone @@ -26,8 +26,7 @@ if [[ ! -z "${SSH_KEY}" ]]; then touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts - echo DRONE_NETRC_MACHINE=$DRONE_NETRC_MACHINE - ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts 2> /dev/null + ssh-keyscan ${DRONE_NETRC_MACHINE:?err} 1> /etc/ssh/ssh_known_hosts export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi From 4f01dba2e8008601449d68745da0a038b24b4628 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 22:45:02 +0200 Subject: [PATCH 15/19] output ssh_known_hosts --- posix/clone | 1 + 1 file changed, 1 insertion(+) diff --git a/posix/clone b/posix/clone index 32aac85..d44370d 100755 --- a/posix/clone +++ b/posix/clone @@ -27,6 +27,7 @@ if [[ ! -z "${SSH_KEY}" ]]; then touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts ssh-keyscan ${DRONE_NETRC_MACHINE:?err} 1> /etc/ssh/ssh_known_hosts + cat /etc/ssh/ssh_known_hosts export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi From 1727e0f20bccd0e4b4f00349f860d4619bcd6346 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 22:52:02 +0200 Subject: [PATCH 16/19] more debug --- posix/clone | 3 +-- posix/clone-commit | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/posix/clone b/posix/clone index d44370d..970d814 100755 --- a/posix/clone +++ b/posix/clone @@ -26,8 +26,7 @@ if [[ ! -z "${SSH_KEY}" ]]; then touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts - ssh-keyscan ${DRONE_NETRC_MACHINE:?err} 1> /etc/ssh/ssh_known_hosts - cat /etc/ssh/ssh_known_hosts + ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi diff --git a/posix/clone-commit b/posix/clone-commit index 358ecaf..28462f3 100755 --- a/posix/clone-commit +++ b/posix/clone-commit @@ -6,8 +6,10 @@ if [[ ! -z "${PLUGIN_DEPTH}" ]]; then fi if [ ! -d .git ]; then + set -x git init git remote add origin ${DRONE_REMOTE_URL} + echo DRONE_REMOTE_URL=$DRONE_REMOTE_URL fi # the branch may be empty for certain event types, From 0cc882c406404ecc1d4efc86913e7db03c857599 Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 23:54:55 +0200 Subject: [PATCH 17/19] fix: missing git ssh port --- posix/clone | 8 +++++++- posix/clone-commit | 2 -- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/posix/clone b/posix/clone index 970d814..ca71cd9 100755 --- a/posix/clone +++ b/posix/clone @@ -26,7 +26,13 @@ if [[ ! -z "${SSH_KEY}" ]]; then touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts - ssh-keyscan ${DRONE_NETRC_MACHINE} > /etc/ssh/ssh_known_hosts + + PORT=$(echo $DRONE_GIT_SSH_URL | sed 's/.*:\(\d*\).*/\1/') + if [[ -z "$PORT" ]]; then + ssh-keyscan $DRONE_NETRC_MACHINE > /root/.ssh/known_hosts 2> /dev/null + else + ssh-keyscan -p $PORT $DRONE_NETRC_MACHINE > /root/.ssh/known_hosts 2> /dev/null + fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi diff --git a/posix/clone-commit b/posix/clone-commit index 28462f3..358ecaf 100755 --- a/posix/clone-commit +++ b/posix/clone-commit @@ -6,10 +6,8 @@ if [[ ! -z "${PLUGIN_DEPTH}" ]]; then fi if [ ! -d .git ]; then - set -x git init git remote add origin ${DRONE_REMOTE_URL} - echo DRONE_REMOTE_URL=$DRONE_REMOTE_URL fi # the branch may be empty for certain event types, From 7a29a6e9d277c884265182f81e1f0480d859706b Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Mon, 20 Jul 2020 23:56:07 +0200 Subject: [PATCH 18/19] reverse README --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 9a83821..879119a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -Fork from https://github.com/drone/drone-git to allow cloning via ssh. - # drone-git Drone plugin to clone `git` repositories. From 44b23776a82978938523b65a20c318e0fd8c1e4c Mon Sep 17 00:00:00 2001 From: Sven Linstaedt Date: Wed, 22 Jul 2020 14:05:19 +0200 Subject: [PATCH 19/19] fix: get ssh clone host from DRONE_GIT_SSH_URL --- posix/clone | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/posix/clone b/posix/clone index ca71cd9..418828e 100755 --- a/posix/clone +++ b/posix/clone @@ -27,11 +27,14 @@ if [[ ! -z "${SSH_KEY}" ]]; then touch /root/.ssh/known_hosts chmod 600 /root/.ssh/known_hosts - PORT=$(echo $DRONE_GIT_SSH_URL | sed 's/.*:\(\d*\).*/\1/') - if [[ -z "$PORT" ]]; then - ssh-keyscan $DRONE_NETRC_MACHINE > /root/.ssh/known_hosts 2> /dev/null + # DRONE_GIT_SSH_URL=git@github.com:slinstaedt/drone-plugin-base.git + # DRONE_GIT_SSH_URL=ssh://git@stash.integra.local:7999/eproc/eproc-api.git + HOST=$(echo $DRONE_GIT_SSH_URL | sed 's/.*[\/@]\(.*\):.*/\1/') + PORT=$(echo $DRONE_GIT_SSH_URL | sed 's/.*:\(\d*\)\/.*/\1/') + if [[ "$PORT" = "$DRONE_GIT_SSH_URL" ]]; then + ssh-keyscan $HOST > /root/.ssh/known_hosts 2> /dev/null else - ssh-keyscan -p $PORT $DRONE_NETRC_MACHINE > /root/.ssh/known_hosts 2> /dev/null + ssh-keyscan -p $PORT $HOST > /root/.ssh/known_hosts 2> /dev/null fi export DRONE_REMOTE_URL="$DRONE_GIT_SSH_URL" fi