94 lines
2.9 KiB
YAML
94 lines
2.9 KiB
YAML
name: Deploy Docker Compose
|
|
|
|
description: Deploy a Docker Compose file to a remote server via SSH
|
|
|
|
inputs:
|
|
docker_compose_path:
|
|
description: 'Path to the docker-compose file (e.g. docker-compose.yml)'
|
|
required: true
|
|
|
|
remote_host:
|
|
description: 'Remote server IP or hostname'
|
|
required: true
|
|
|
|
remote_user:
|
|
description: 'SSH username on remote server'
|
|
required: true
|
|
|
|
deployment_path:
|
|
description: 'Remote path to deploy the compose file (e.g. /home/linly/services/gitea)'
|
|
required: true
|
|
|
|
|
|
timeout:
|
|
description: 'Timeout in seconds for docker-compose up'
|
|
required: false
|
|
default: 300
|
|
|
|
runs:
|
|
using: composite
|
|
|
|
# Environment variables (we pass inputs to the action)
|
|
env:
|
|
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_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
|
|
TIMEOUT: ${{ inputs.timeout }}
|
|
|
|
# Optional: Set timeout for the entire action
|
|
# timeout-minutes: 10
|
|
|
|
steps:
|
|
- name: Set up SSH config
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
|
chmod 600 ~/.ssh/id_rsa
|
|
|
|
echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
|
|
chmod 644 ~/.ssh/known_hosts
|
|
|
|
# SSH config file
|
|
echo "Host ${REMOTE_HOST}" > ~/.ssh/config
|
|
echo " HostName ${REMOTE_HOST}" >> ~/.ssh/config
|
|
echo " User ${REMOTE_USER}" >> ~/.ssh/config
|
|
echo " IdentityFile ~/.ssh/id_rsa" >> ~/.ssh/config
|
|
echo " StrictHostKeyChecking yes" >> ~/.ssh/config
|
|
echo " UserKnownHostsFile ~/.ssh/known_hosts" >> ~/.ssh/config
|
|
|
|
- name: Copy docker-compose file to remote server
|
|
run: |
|
|
echo "${DOCKER_COMPOSE_PATH}"
|
|
echo "${REMOTE_USER}@${REMOTE_HOST}:${DEPLOYMENT_PATH}"
|
|
mkdir -p "$(dirname "${DEPLOYMENT_PATH}")"
|
|
scp -o StrictHostKeyChecking=yes -P 2223 \
|
|
-o UserKnownHostsFile=~/.ssh/known_hosts \
|
|
-i ~/.ssh/id_rsa \
|
|
${DOCKER_COMPOSE_PATH} \
|
|
"${REMOTE_USER}@${REMOTE_HOST}:${DEPLOYMENT_PATH}"
|
|
shell: bash
|
|
|
|
- name: Deploy services via SSH
|
|
run: |
|
|
ssh -o StrictHostKeyChecking=yes -p 2223 \
|
|
-o UserKnownHostsFile=~/.ssh/known_hosts \
|
|
-i ~/.ssh/id_rsa \
|
|
"${REMOTE_USER}@${REMOTE_HOST}" \
|
|
"cd $(dirname ${DEPLOYMENT_PATH}) && docker compose up -d --timeout ${TIMEOUT}"
|
|
shell: bash
|
|
|
|
- name: Verify services are running
|
|
run: |
|
|
ssh -o StrictHostKeyChecking=yes -p 2223 \
|
|
-o UserKnownHostsFile=~/.ssh/known_hosts \
|
|
-i ~/.ssh/id_rsa \
|
|
"${REMOTE_USER}@${REMOTE_HOST}" \
|
|
docker compose -f ${DEPLOYMENT_PATH} ps
|
|
shell: bash
|
|
|
|
- name: Final success message
|
|
run: echo "✅ Docker Compose deployed successfully on ${REMOTE_HOST}"
|