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 11:10:29 +02:00
|
|
|
cat << SSHEOF > ~/.ssh/config.dagger
|
|
|
|
|
Host dagger-engine
|
|
|
|
|
HostName $DAGGER_ENGINE_HOST
|
|
|
|
|
User dagger
|
|
|
|
|
IdentityFile ~/.ssh/dagger_key
|
2026-06-02 13:20:20 +02:00
|
|
|
IdentitiesOnly yes
|
2026-06-02 11:10:29 +02:00
|
|
|
StrictHostKeyChecking no
|
|
|
|
|
UserKnownHostsFile /dev/null
|
|
|
|
|
SSHEOF
|
2026-05-17 11:50:39 +02:00
|
|
|
|
2026-06-02 12:51:41 +02:00
|
|
|
if ! grep -q "Include ~/.ssh/config.dagger" ~/.ssh/config 2>/dev/null; then
|
2026-06-02 11:10:29 +02:00
|
|
|
echo "Include ~/.ssh/config.dagger" >> ~/.ssh/config
|
2026-05-17 11:50:39 +02:00
|
|
|
fi
|
|
|
|
|
|
2026-06-02 13:20:20 +02:00
|
|
|
# Wrapper for remote dagger execution
|
2026-06-02 13:19:16 +02:00
|
|
|
cat << 'WRAPPER' > /usr/local/bin/dagger-remote
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
ssh -F ~/.ssh/config.dagger dagger-engine dagger "$@"
|
|
|
|
|
WRAPPER
|
|
|
|
|
chmod +x /usr/local/bin/dagger-remote
|
2026-06-02 11:10:29 +02:00
|
|
|
|
2026-06-02 13:19:16 +02:00
|
|
|
# Verify
|
|
|
|
|
echo "Verifying connection via dagger-remote wrapper..."
|
|
|
|
|
if ! dagger-remote query '{ version }' >/dev/null 2>&1; then
|
|
|
|
|
echo "Error: Dagger engine unreachable via dagger-remote wrapper"
|
2026-06-02 11:10:29 +02:00
|
|
|
exit 1
|
2026-05-17 11:50:39 +02:00
|
|
|
fi
|
2026-06-02 13:19:16 +02:00
|
|
|
|
2026-06-02 13:20:20 +02:00
|
|
|
# Path management
|
2026-06-02 13:19:16 +02:00
|
|
|
mkdir -p ~/bin
|
|
|
|
|
ln -sf /usr/local/bin/dagger-remote ~/bin/dagger
|
|
|
|
|
if [ -n "${GITHUB_PATH:-}" ]; then
|
|
|
|
|
echo "$HOME/bin" >> "$GITHUB_PATH"
|
|
|
|
|
fi
|
|
|
|
|
|
2026-06-02 13:20:20 +02:00
|
|
|
echo "Dagger remote configured successfully."
|