76 lines
2.5 KiB
YAML
76 lines
2.5 KiB
YAML
name: 'Auto Deploy Status'
|
|
description: 'Reads current deployment status from app server'
|
|
inputs:
|
|
ssh_key:
|
|
description: 'SSH Private Key'
|
|
required: true
|
|
host:
|
|
description: 'Remote App Host'
|
|
required: true
|
|
port:
|
|
description: 'Remote SSH Port'
|
|
required: true
|
|
user:
|
|
description: 'Remote User'
|
|
required: true
|
|
app_key:
|
|
description: 'Application Key'
|
|
required: true
|
|
auto_deploy_path:
|
|
description: 'Path to auto-deploy repo on remote'
|
|
required: true
|
|
outputs:
|
|
app_upstream_host:
|
|
description: 'Upstream Host or IP'
|
|
value: ${{ steps.get_status.outputs.app_upstream_host }}
|
|
pending_port:
|
|
description: 'Pending Port'
|
|
value: ${{ steps.get_status.outputs.pending_port }}
|
|
pending_color:
|
|
description: 'Pending Color'
|
|
value: ${{ steps.get_status.outputs.pending_color }}
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: SSH Deploy Status
|
|
id: get_status
|
|
shell: bash
|
|
env:
|
|
SSH_KEY: ${{ inputs.ssh_key }}
|
|
DEPLOY_HOST: ${{ inputs.host }}
|
|
DEPLOY_PORT: ${{ inputs.port }}
|
|
DEPLOY_USER: ${{ inputs.user }}
|
|
APP_KEY: ${{ inputs.app_key }}
|
|
AUTO_DEPLOY_PATH: ${{ inputs.auto_deploy_path }}
|
|
run: |
|
|
set -eu
|
|
|
|
SSH_TMP_DIR="$(mktemp -d)"
|
|
trap 'rm -rf "$SSH_TMP_DIR"' EXIT
|
|
|
|
echo "$SSH_KEY" > "$SSH_TMP_DIR/id_rsa"
|
|
chmod 600 "$SSH_TMP_DIR/id_rsa"
|
|
ssh-keyscan -p "$DEPLOY_PORT" "$DEPLOY_HOST" > "$SSH_TMP_DIR/known_hosts"
|
|
|
|
SSH_OPTS=(
|
|
-i "$SSH_TMP_DIR/id_rsa"
|
|
-o UserKnownHostsFile="$SSH_TMP_DIR/known_hosts"
|
|
-o StrictHostKeyChecking=yes
|
|
-p "$DEPLOY_PORT"
|
|
)
|
|
|
|
STATUS_OUTPUT="$(ssh "${SSH_OPTS[@]}" "$DEPLOY_USER@$DEPLOY_HOST" "cd $(printf '%q' "$AUTO_DEPLOY_PATH") && ./common/deploy.sh status $(printf '%q' "$APP_KEY") --format env")"
|
|
printf '%s\n' "$STATUS_OUTPUT"
|
|
|
|
APP_UPSTREAM_HOST="$(printf '%s\n' "$STATUS_OUTPUT" | sed -n 's/^APP_UPSTREAM_HOST=//p')"
|
|
PENDING_PORT="$(printf '%s\n' "$STATUS_OUTPUT" | sed -n 's/^PENDING_PORT=//p')"
|
|
PENDING_COLOR="$(printf '%s\n' "$STATUS_OUTPUT" | sed -n 's/^PENDING_COLOR=//p')"
|
|
|
|
test -n "$APP_UPSTREAM_HOST"
|
|
test -n "$PENDING_PORT"
|
|
test -n "$PENDING_COLOR"
|
|
|
|
echo "app_upstream_host=$APP_UPSTREAM_HOST" >> "$GITHUB_OUTPUT"
|
|
echo "pending_port=$PENDING_PORT" >> "$GITHUB_OUTPUT"
|
|
echo "pending_color=$PENDING_COLOR" >> "$GITHUB_OUTPUT"
|