#!/usr/bin/env bash # Runner-side deploy trigger used by the Gitea Actions workflows in .gitea/workflows/. # # The target host's CI deploy key is pinned to a forced command (dev/ci/ci-deploy-wrapper.sh, # installed on the host — see dev/ci/README.md). So the ONLY thing we send over SSH is the # image tag: it arrives on the host as $SSH_ORIGINAL_COMMAND, the wrapper validates it and runs # the deploy. The runner can never execute an arbitrary command on the target, and the host — # not this script — owns its checkout path (DEPLOY_DIR in the host's ci-deploy.conf). # # Required environment: # DEPLOY_HOST target hostname / IP # DEPLOY_USER SSH user on the target (e.g. the dedicated `deploy` user) # DEPLOY_SSH_KEY private SSH key contents (the CI deploy key) # IMAGE_TAG image tag to deploy, e.g. v1.2.3 or sha-abc1234 # Optional environment: # DEPLOY_SSH_PORT SSH port on the target, if not the default 22 set -euo pipefail : "${DEPLOY_HOST:?}" "${DEPLOY_USER:?}" "${DEPLOY_SSH_KEY:?}" "${IMAGE_TAG:?}" DEPLOY_SSH_PORT="${DEPLOY_SSH_PORT:-22}" key_file="$(mktemp)" trap 'rm -f "$key_file"' EXIT printf '%s\n' "$DEPLOY_SSH_KEY" >"$key_file" chmod 600 "$key_file" echo "+ deploy ${DEPLOY_USER}@${DEPLOY_HOST}:${DEPLOY_SSH_PORT} tag=${IMAGE_TAG}" >&2 # StrictHostKeyChecking=accept-new trusts the host key on first connection and pins it after. # The "command" we pass is delivered to the host's forced-command wrapper as # $SSH_ORIGINAL_COMMAND — it is a tag, not a shell command. exec ssh -i "$key_file" -p "$DEPLOY_SSH_PORT" -o StrictHostKeyChecking=accept-new -o BatchMode=yes \ "${DEPLOY_USER}@${DEPLOY_HOST}" "$IMAGE_TAG"