2026-05-17 11:50:39 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
2026-06-02 11:10:29 +02:00
|
|
|
if [ -z "${SOPS_AGE_KEY:-}" ]; then
|
|
|
|
|
echo "Error: SOPS_AGE_KEY must be set."
|
|
|
|
|
exit 1
|
2026-05-20 15:48:38 +02:00
|
|
|
fi
|
2026-05-17 11:50:39 +02:00
|
|
|
|
2026-06-02 11:10:29 +02:00
|
|
|
echo "Decrypting secrets with SOPS..."
|
|
|
|
|
export SOPS_AGE_KEY="$SOPS_AGE_KEY"
|
|
|
|
|
SECRETS_JSON=$(mktemp)
|
|
|
|
|
trap "rm -f $SECRETS_JSON" EXIT
|
|
|
|
|
|
2026-06-02 12:45:34 +02:00
|
|
|
sops --decrypt --output-type json secrets.enc.yaml > "$SECRETS_JSON"
|
2026-05-17 11:50:39 +02:00
|
|
|
|
2026-06-02 11:10:29 +02:00
|
|
|
DAGGER_SSH_KEY=$(jq -r '.DAGGER_SSH_KEY' "$SECRETS_JSON")
|
|
|
|
|
DAGGER_ENGINE_HOST=$(jq -r '.DAGGER_ENGINE_HOST' "$SECRETS_JSON")
|
2026-05-17 11:50:39 +02:00
|
|
|
|
2026-06-02 13:19:16 +02:00
|
|
|
# Setup SSH
|
2026-06-02 11:10:29 +02:00
|
|
|
mkdir -p ~/.ssh
|
|
|
|
|
chmod 700 ~/.ssh
|
|
|
|
|
echo "$DAGGER_SSH_KEY" > ~/.ssh/dagger_key
|
|
|
|
|
chmod 600 ~/.ssh/dagger_key
|
2026-05-17 11:50:39 +02:00
|
|
|
|
2026-06-02 16:18:06 +02:00
|
|
|
# Use ssh-agent to manage the key for Dagger's internal SSH client
|
|
|
|
|
eval "$(ssh-agent -s)"
|
|
|
|
|
ssh-add ~/.ssh/dagger_key
|
2026-05-17 11:50:39 +02:00
|
|
|
|
2026-06-02 13:31:11 +02:00
|
|
|
# Export _EXPERIMENTAL_DAGGER_RUNNER_HOST for redirection
|
2026-06-02 16:18:06 +02:00
|
|
|
# Dagger's Go SSH client will now use the agent to find the key
|
|
|
|
|
export _EXPERIMENTAL_DAGGER_RUNNER_HOST="ssh://dagger@$DAGGER_ENGINE_HOST"
|
2026-06-02 13:31:11 +02:00
|
|
|
if [ -n "${GITHUB_ENV:-}" ]; then
|
2026-06-02 16:18:06 +02:00
|
|
|
echo "_EXPERIMENTAL_DAGGER_RUNNER_HOST=ssh://dagger@$DAGGER_ENGINE_HOST" >> "$GITHUB_ENV"
|
|
|
|
|
# Also pass the agent socket if needed, though Dagger usually handles this if exported
|
|
|
|
|
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> "$GITHUB_ENV"
|
|
|
|
|
echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> "$GITHUB_ENV"
|
2026-06-02 13:31:11 +02:00
|
|
|
fi
|
2026-06-02 11:10:29 +02:00
|
|
|
|
2026-06-02 13:19:16 +02:00
|
|
|
# Verify
|
2026-06-02 13:31:11 +02:00
|
|
|
echo "Verifying connection to remote Dagger engine..."
|
2026-06-02 16:18:06 +02:00
|
|
|
# Ensure remote dagger knows which socket to use
|
2026-06-02 16:14:51 +02:00
|
|
|
if ! timeout 45 dagger query --progress=plain '{ version }' ; then
|
2026-06-02 13:31:11 +02:00
|
|
|
echo "Error: Dagger engine unreachable via SSH at $DAGGER_ENGINE_HOST"
|
|
|
|
|
# Debug: try to just run id over ssh
|
2026-06-02 16:14:51 +02:00
|
|
|
ssh -i ~/.ssh/dagger_key -o StrictHostKeyChecking=no "dagger@$DAGGER_ENGINE_HOST" "id"
|
2026-06-02 11:10:29 +02:00
|
|
|
exit 1
|
2026-05-17 11:50:39 +02:00
|
|
|
fi
|
2026-06-02 13:31:11 +02:00
|
|
|
echo "Dagger connection verified."
|