fix: resolve invalid yaml nesting

This commit is contained in:
2025-09-14 10:11:08 +03:00
parent f640f74ab0
commit f357ee8a6a

View File

@@ -1,72 +1,94 @@
name: Deploy Docker Compose via SSH name: Deploy Docker Compose
description: Deploy a Docker Compose file to a remote server via SSH
runs:
using: composite
inputs: inputs:
docker_compose_path: docker_compose_path:
description: 'Path to deploy docker-compose.yml (e.g. /home/user/app/docker-compose.yml)' description: 'Path to the docker-compose file (e.g. docker-compose.yml)'
required: false required: true
default: 'docker-compose.yml' default: 'docker-compose.yml'
remote_host: remote_host:
description: 'Remote host (e.g. 192.168.1.100)' description: 'Remote server IP or hostname'
required: false required: true
default: '185.218.126.87' default: '185.218.126.87'
remote_user: remote_user:
description: 'Remote user (e.g. ubuntu)' description: 'SSH username on remote server'
required: false required: true
default: 'linly' default: 'linly'
deployment_path: deployment_path:
description: 'the path where the docker-compose file will be copied to' description: 'Remote path to deploy the compose file (e.g. /home/linly/services/gitea)'
required: true required: true
default: '/home/linly/services/gitea' default: '/home/linly/services/gitea'
timeout:
description: 'Timeout in seconds for docker-compose up'
required: false
default: 300
runs:
using: ubuntu-latest
# We use Docker to run this action, so we don't need to run it on a runner
# (you can also use "ubuntu-latest" if you prefer, but Docker is better for consistency)
# Specify the Docker image to use (this is optional but recommended)
# You can use a custom image or just use the base image
# Here we use a minimal image with SSH and docker-compose
# Environment variables (we pass inputs to the action)
env: env:
# These are provided via GitHub Secrets REMOTE_HOST: ${{ inputs.remote_host }}
REMOTE_USER: ${{ inputs.remote_user }}
DEPLOYMENT_PATH: ${{ inputs.deployment_path }}
DOCKER_COMPOSE_PATH: ${{ inputs.docker_compose_path }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }} SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
DEPLOYMENT_PATH: ${{ inputs.deployment_path || 'docker-compose.yml' }} TIMEOUT: ${{ inputs.timeout }}
REMOTE_HOST: ${{ inputs.remote_host || 'your-server.example.com' }}
REMOTE_USER: ${{ inputs.remote_user || 'ubuntu' }} # Optional: Set timeout for the entire action
DOCKER_COMPOSE_PATH: ${{ inputs.docker_compose_path }} # timeout-minutes: 10
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Set up SSH agent (to use private key) - name: Set up SSH config
run: | run: |
mkdir -p ~/.ssh mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa chmod 600 ~/.ssh/id_rsa
# Optional: add known hosts
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts chmod 644 ~/.ssh/known_hosts
# Ensure SSH config
echo "Host ${REMOTE_HOST}" >> ~/.ssh/config # SSH config file
echo "Host ${REMOTE_HOST}" > ~/.ssh/config
echo " HostName ${REMOTE_HOST}" >> ~/.ssh/config echo " HostName ${REMOTE_HOST}" >> ~/.ssh/config
echo " User ${REMOTE_USER}" >> ~/.ssh/config echo " User ${REMOTE_USER}" >> ~/.ssh/config
echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
echo " StrictHostKeyChecking yes" >> ~/.ssh/config echo " StrictHostKeyChecking yes" >> ~/.ssh/config
echo " UserKnownHostsFile ~/.ssh/known_hosts" >> ~/.ssh/config echo " UserKnownHostsFile ~/.ssh/known_hosts" >> ~/.ssh/config
- name: Copy docker-compose.yml to remote host - name: Copy docker-compose file to remote server
run: | run: |
# Ensure the remote path exists
mkdir -p "$(dirname "${DEPLOYMENT_PATH}")" mkdir -p "$(dirname "${DEPLOYMENT_PATH}")"
# Use scp to copy the file scp -o StrictHostKeyChecking=yes \
scp -o StrictHostKeyChecking=yes -o UserKnownHostsFile= ~/.ssh/known_hosts \ -o UserKnownHostsFile= ~/.ssh/known_hosts \
-i ~/.ssh/id_rsa \ -i ~/.ssh/id_rsa \
${COMPOSE_PATH} \ "${DOCKER_COMPOSE_PATH}" \
${REMOTE_USER}@${REMOTE_HOST}:"${DEPLOYMENT_PATH}" "${REMOTE_USER}@${REMOTE_HOST}:${DEPLOYMENT_PATH}"
shell: bash shell: bash
- name: Deploy services via SSH - name: Deploy services via SSH
run: | run: |
# Run docker-compose up -d on the remote host
ssh -o StrictHostKeyChecking=yes \ ssh -o StrictHostKeyChecking=yes \
-o UserKnownHostsFile= ~/.ssh/known_hosts \ -o UserKnownHostsFile= ~/.ssh/known_hosts \
-i ~/.ssh/id_rsa \ -i ~/.ssh/id_rsa \
${REMOTE_USER}@${REMOTE_HOST} \ "${REMOTE_USER}@${REMOTE_HOST}" \
"docker-compose -f ${DEPLOYMENT_PATH} up -d --timeout 300" "docker-compose -f ${DEPLOYMENT_PATH} up -d --timeout ${TIMEOUT}"
shell: bash shell: bash
- name: Verify services are running - name: Verify services are running
@@ -74,7 +96,7 @@ runs:
ssh -o StrictHostKeyChecking=yes \ ssh -o StrictHostKeyChecking=yes \
-o UserKnownHostsFile= ~/.ssh/known_hosts \ -o UserKnownHostsFile= ~/.ssh/known_hosts \
-i ~/.ssh/id_rsa \ -i ~/.ssh/id_rsa \
${REMOTE_USER}@${REMOTE_HOST} \ "${REMOTE_USER}@${REMOTE_HOST}" \
"docker-compose -f ${DEPLOYMENT_PATH} ps" "docker-compose -f ${DEPLOYMENT_PATH} ps"
shell: bash shell: bash