From 917e84f6ec92d94cb8f6737fb25a0935a0cff7fa Mon Sep 17 00:00:00 2001 From: Bram Kelchtermans Date: Wed, 11 Sep 2024 10:46:35 +0200 Subject: [PATCH] fetch domain from ssh url --- Dockers/remote-node-container/entrypoint.sh | 14 +++++++++++++- Dockers/remote-node-container/version | 2 +- Dockers/remote-react-container/entrypoint.sh | 15 ++++++++++++++- Dockers/remote-react-container/version | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Dockers/remote-node-container/entrypoint.sh b/Dockers/remote-node-container/entrypoint.sh index 3c61974..2e9cf29 100644 --- a/Dockers/remote-node-container/entrypoint.sh +++ b/Dockers/remote-node-container/entrypoint.sh @@ -1,5 +1,17 @@ #!/bin/bash set -e +extract_domain() { + local url=$1 + + # Handle different SSH URL formats + if [[ $url == ssh://* ]]; then + # For URLs starting with ssh://, extract the domain + echo "$url" | sed -E 's|ssh://[^@]+@([^:/]+).*|\1|' + else + # For URLs without ssh://, extract the domain after '@' and before ':' + echo "$url" | sed -E 's|[^@]+@([^:/]+).*|\1|' + fi +} # Check if the required environment variables are set if [ -z "$REPO_URL" ]; then @@ -47,7 +59,7 @@ fi chmod 600 /root/.ssh/id_rsa # Extract the domain from the REPO_URL -DOMAIN=$(echo $REPO_URL | awk -F'[@:]' '{print $3}') +DOMAIN=extract_domain "$REPO_URL" # Check if the repository directory already exists if [ ! -d "/workspace/.git" ]; then diff --git a/Dockers/remote-node-container/version b/Dockers/remote-node-container/version index 415b19f..42f7d23 100644 --- a/Dockers/remote-node-container/version +++ b/Dockers/remote-node-container/version @@ -1 +1 @@ -2.0 \ No newline at end of file +2.1 \ No newline at end of file diff --git a/Dockers/remote-react-container/entrypoint.sh b/Dockers/remote-react-container/entrypoint.sh index 99985bb..ffe88dc 100644 --- a/Dockers/remote-react-container/entrypoint.sh +++ b/Dockers/remote-react-container/entrypoint.sh @@ -1,6 +1,19 @@ #!/bin/bash set -e +extract_domain() { + local url=$1 + + # Handle different SSH URL formats + if [[ $url == ssh://* ]]; then + # For URLs starting with ssh://, extract the domain + echo "$url" | sed -E 's|ssh://[^@]+@([^:/]+).*|\1|' + else + # For URLs without ssh://, extract the domain after '@' and before ':' + echo "$url" | sed -E 's|[^@]+@([^:/]+).*|\1|' + fi +} + # Check if the required environment variables are set if [ -z "$REPO_URL" ]; then echo "Error: REPO_URL environment variable must be set." @@ -27,7 +40,7 @@ fi chmod 600 /root/.ssh/id_rsa # Extract the domain from the REPO_URL -DOMAIN=$(echo $REPO_URL | awk -F'[@:]' '{print $3}') +DOMAIN=extract_domain "$REPO_URL" # Check if the repository directory already exists if [ ! -d "/workspace/.git" ]; then diff --git a/Dockers/remote-react-container/version b/Dockers/remote-react-container/version index 415b19f..42f7d23 100644 --- a/Dockers/remote-react-container/version +++ b/Dockers/remote-react-container/version @@ -1 +1 @@ -2.0 \ No newline at end of file +2.1 \ No newline at end of file