install ssh-keyscan

This commit is contained in:
2026-04-16 07:08:21 +08:00
parent dce2088374
commit 134ebd528b
+25 -14
View File
@@ -1,30 +1,30 @@
name: 'Checkout and Config Injection' name: "Checkout and Config Injection"
description: 'Clones the project via SSH and injects configs from a separate repo' description: "Clones the project via SSH and injects configs from a separate repo"
inputs: inputs:
ssh_key: ssh_key:
description: 'SSH Private Key' description: "SSH Private Key"
required: true required: true
config_repo: config_repo:
description: 'Configuration Repository Path (e.g., dev-ops/configs.git)' description: "Configuration Repository Path (e.g., dev-ops/configs.git)"
required: false required: false
default: '' default: ""
config_repo_branch: config_repo_branch:
description: 'Configuration Repository Branch' description: "Configuration Repository Branch"
required: false required: false
default: 'main' default: "main"
app_key: app_key:
description: 'Application Key in the config repo' description: "Application Key in the config repo"
required: true required: true
gitea_host: gitea_host:
description: 'Gitea Hostname' description: "Gitea Hostname"
required: false required: false
default: 'gitea.hclife.co' default: "gitea.hclife.co"
gitea_port: gitea_port:
description: 'Gitea SSH Port' description: "Gitea SSH Port"
required: false required: false
default: '2222' default: "2222"
runs: runs:
using: 'composite' using: "composite"
steps: steps:
- name: Checkout and Config - name: Checkout and Config
shell: bash shell: bash
@@ -43,8 +43,19 @@ runs:
echo "$SSH_KEY" > "$SSH_TMP_DIR/id_rsa" echo "$SSH_KEY" > "$SSH_TMP_DIR/id_rsa"
chmod 600 "$SSH_TMP_DIR/id_rsa" chmod 600 "$SSH_TMP_DIR/id_rsa"
ssh-keyscan -p "$GITEA_PORT" "$GITEA_HOST" > "$SSH_TMP_DIR/known_hosts"
# Ensure ssh-keyscan is available for strict host key checking
if ! command -v ssh-keyscan &> /dev/null; then
echo "ssh-keyscan not found, attempting to install..."
if command -v apk &> /dev/null; then
apk add --no-cache openssh-client
elif command -v apt-get &> /dev/null; then
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -y openssh-client
fi
fi
ssh-keyscan -p "$GITEA_PORT" "$GITEA_HOST" > "$SSH_TMP_DIR/known_hosts"
export GIT_SSH_COMMAND="ssh -i $SSH_TMP_DIR/id_rsa -o UserKnownHostsFile=$SSH_TMP_DIR/known_hosts -o StrictHostKeyChecking=yes" export GIT_SSH_COMMAND="ssh -i $SSH_TMP_DIR/id_rsa -o UserKnownHostsFile=$SSH_TMP_DIR/known_hosts -o StrictHostKeyChecking=yes"
echo "Initializing project repository..." echo "Initializing project repository..."