Files
root 773f838272
Update README Actions Table / update-readme (push) Successful in 9s
feat(truenas-deploy): default remote path to /mnt/jupiter/apps/<owner>/<repo>
2026-10-13 11:35:48 -07:00

91 lines
3.5 KiB
YAML

name: 'Deploy to TrueNAS'
description: 'Deploys a Docker Compose stack to TrueNAS SCALE over SSH and pulls latest container images.'
inputs:
ssh_key:
description: 'Private SSH key for authenticating to TrueNAS'
required: true
app_name:
description: 'Application subpath under /mnt/jupiter/apps/<owner>/<repo> (defaults to <owner>/<repo>)'
required: false
default: ''
compose_file:
description: 'Path to the local docker-compose file in the repository'
required: false
default: 'docker-compose.yaml'
host:
description: 'TrueNAS SSH host IP or domain'
required: false
default: '10.0.0.218'
user:
description: 'TrueNAS SSH user'
required: false
default: 'root'
env_file_content:
description: 'Optional .env file content to write to the remote application directory'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Deploy Docker Compose Stack to TrueNAS
shell: bash
env:
INPUT_SSH_KEY: ${{ inputs.ssh_key }}
INPUT_APP_NAME: ${{ inputs.app_name }}
INPUT_COMPOSE_FILE: ${{ inputs.compose_file }}
INPUT_HOST: ${{ inputs.host }}
INPUT_USER: ${{ inputs.user }}
INPUT_ENV_CONTENT: ${{ inputs.env_file_content }}
REPO_FULL_NAME: ${{ github.repository }}
REPO_OWNER: ${{ github.repository_owner }}
run: |
set -euo pipefail
FULL_REPO="${REPO_FULL_NAME:-$GITHUB_REPOSITORY}"
OWNER="${REPO_OWNER:-$(dirname "$FULL_REPO")}"
if [ -n "$INPUT_APP_NAME" ]; then
case "$INPUT_APP_NAME" in
*/*) APP_DIR_NAME="$INPUT_APP_NAME" ;;
*) APP_DIR_NAME="${OWNER}/${INPUT_APP_NAME}" ;;
esac
else
APP_DIR_NAME="$FULL_REPO"
fi
COMPOSE_FILE="$INPUT_COMPOSE_FILE"
if [ ! -f "$COMPOSE_FILE" ]; then
if [ -f "docker-compose.yml" ]; then
COMPOSE_FILE="docker-compose.yml"
elif [ -f "docker-compose.yaml" ]; then
COMPOSE_FILE="docker-compose.yaml"
else
echo "::error::Compose file '$COMPOSE_FILE' not found!"
exit 1
fi
fi
mkdir -p ~/.ssh
echo "$INPUT_SSH_KEY" > ~/.ssh/truenas_deploy_key
chmod 600 ~/.ssh/truenas_deploy_key
ssh-keyscan -H "$INPUT_HOST" >> ~/.ssh/known_hosts 2>/dev/null
REMOTE_DIR="/mnt/jupiter/apps/${APP_DIR_NAME}"
echo "Ensuring remote directory ${REMOTE_DIR} on ${INPUT_HOST}..."
ssh -i ~/.ssh/truenas_deploy_key -o StrictHostKeyChecking=no "${INPUT_USER}@${INPUT_HOST}" "mkdir -p ${REMOTE_DIR}"
if [ -n "$INPUT_ENV_CONTENT" ]; then
echo "Writing .env configuration to ${REMOTE_DIR}/.env..."
printf "%s\n" "$INPUT_ENV_CONTENT" | ssh -i ~/.ssh/truenas_deploy_key -o StrictHostKeyChecking=no "${INPUT_USER}@${INPUT_HOST}" "cat > ${REMOTE_DIR}/.env && chmod 600 ${REMOTE_DIR}/.env"
fi
echo "Syncing ${COMPOSE_FILE} to ${REMOTE_DIR}/docker-compose.yml..."
scp -i ~/.ssh/truenas_deploy_key -o StrictHostKeyChecking=no "$COMPOSE_FILE" "${INPUT_USER}@${INPUT_HOST}:${REMOTE_DIR}/docker-compose.yml"
echo "Pulling images and starting containers in ${REMOTE_DIR}..."
ssh -i ~/.ssh/truenas_deploy_key -o StrictHostKeyChecking=no "${INPUT_USER}@${INPUT_HOST}" "cd ${REMOTE_DIR} && docker compose pull && docker compose up -d --remove-orphans"
rm -f ~/.ssh/truenas_deploy_key
echo "✅ Successfully deployed ${APP_DIR_NAME} to TrueNAS!"