63 lines
2.0 KiB
YAML
63 lines
2.0 KiB
YAML
name: Deploy over SSH
|
|
description: SSH into server and update compose services
|
|
inputs:
|
|
ssh_key:
|
|
description: Private SSH key content
|
|
required: true
|
|
user:
|
|
description: SSH username
|
|
required: true
|
|
host:
|
|
description: SSH hostname or IP
|
|
required: true
|
|
compose_file:
|
|
description: Path to compose file on remote server
|
|
required: true
|
|
compose_project_name:
|
|
description: Compose project name on remote server
|
|
required: true
|
|
services:
|
|
description: Space-separated compose services
|
|
required: true
|
|
registry:
|
|
description: OCI registry hostname
|
|
required: false
|
|
default: oci.reg.darano.ir
|
|
registry_username:
|
|
description: OCI registry username
|
|
required: false
|
|
default: admin
|
|
registry_password:
|
|
description: OCI registry password
|
|
required: true
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Deploy over SSH
|
|
shell: bash
|
|
env:
|
|
SSH_KEY: ${{ inputs.ssh_key }}
|
|
REMOTE_USER: ${{ inputs.user }}
|
|
REMOTE_HOST: ${{ inputs.host }}
|
|
COMPOSE_FILE: ${{ inputs.compose_file }}
|
|
COMPOSE_PROJECT_NAME: ${{ inputs.compose_project_name }}
|
|
SERVICES: ${{ inputs.services }}
|
|
REGISTRY: ${{ inputs.registry }}
|
|
REGISTRY_USERNAME: ${{ inputs.registry_username }}
|
|
REGISTRY_PASSWORD: ${{ inputs.registry_password }}
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
chmod 700 ~/.ssh
|
|
echo "$SSH_KEY" > ~/.ssh/deploy_key
|
|
chmod 600 ~/.ssh/deploy_key
|
|
printf '%s' "$REGISTRY_PASSWORD" | ssh -i ~/.ssh/deploy_key \
|
|
-o StrictHostKeyChecking=no \
|
|
-o UserKnownHostsFile=/dev/null \
|
|
"$REMOTE_USER@$REMOTE_HOST" \
|
|
"docker login '$REGISTRY' -u '$REGISTRY_USERNAME' --password-stdin && \
|
|
export COMPOSE_PROJECT_NAME='$COMPOSE_PROJECT_NAME' && \
|
|
docker compose -f '$COMPOSE_FILE' up $SERVICES -d --pull=always; \
|
|
rc=\$?; \
|
|
docker logout '$REGISTRY'; \
|
|
exit \$rc"
|