Skip to content

Commit c2f9c11

Browse files
authored
chore(controller): update SSH config to support any Git server (#32)
Dynamically extract and configure any Git server from SEMAPHORE_GIT_URL
1 parent 178c97d commit c2f9c11

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

charts/controller/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.2.3
18+
version: 0.2.4
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to

charts/controller/pre-job-hook.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,23 @@ fi
3131
echo "Semaphore toolbox successfully installed."
3232

3333
# Create SSH configuration.
34-
# This is required in order to avoid having to manually accept the GitHub SSH keys fingerprints on checkout.
35-
# Ideally, we should populate ~/.ssh/known_hosts with the GitHub keys from api.github.com/meta.
34+
# This is required to avoid manually accepting the Server SSH key fingerprints on checkout.
3635
mkdir -p ~/.ssh
36+
37+
#
38+
# Do it for GitHub for backwards compatibility
39+
#
3740
echo 'Host github.com' | tee -a ~/.ssh/config
3841
echo ' StrictHostKeyChecking no' | tee -a ~/.ssh/config
3942
echo ' UserKnownHostsFile=/dev/null' | tee -a ~/.ssh/config
43+
44+
#
45+
# Do it for currently used one
46+
#
47+
url="${SEMAPHORE_GIT_URL#ssh://}" # Remove the "ssh://" scheme if present
48+
url="${url#*@}" # Remove everything up to (and including) the '@' if present
49+
host="${url%%[:/]*}" # Now extract the host: it's the substring until the first occurrence of either ':' (port separator) or '/' (path separator)
50+
51+
echo "Host ${host}" | tee -a ~/.ssh/config
52+
echo ' StrictHostKeyChecking no' | tee -a ~/.ssh/config
53+
echo ' UserKnownHostsFile=/dev/null' | tee -a ~/.ssh/config

0 commit comments

Comments
 (0)