93 lines
1.9 KiB
YAML
93 lines
1.9 KiB
YAML
name: Deploy Docker Compose
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
vm_ip:
|
|
description: VM IP address
|
|
required: true
|
|
type: string
|
|
|
|
jump_host:
|
|
type: string
|
|
default: 212.3.125.242
|
|
|
|
jump_port:
|
|
type: string
|
|
default: "2222"
|
|
|
|
jump_user:
|
|
type: string
|
|
default: jump
|
|
|
|
vm_port:
|
|
type: string
|
|
default: "22"
|
|
|
|
vm_user:
|
|
type: string
|
|
default: debian
|
|
|
|
compose_path:
|
|
type: string
|
|
default: "~/docker-compose.yml"
|
|
|
|
working_directory:
|
|
type: string
|
|
default: "~"
|
|
|
|
secrets:
|
|
jump_ssh_key:
|
|
required: true
|
|
|
|
vm_ssh_key:
|
|
required: true
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Configure SSH
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
chmod 700 ~/.ssh
|
|
|
|
echo "${{ secrets.jump_ssh_key }}" > ~/.ssh/jump_key
|
|
chmod 600 ~/.ssh/jump_key
|
|
|
|
echo "${{ secrets.vm_ssh_key }}" > ~/.ssh/vm_key
|
|
chmod 600 ~/.ssh/vm_key
|
|
|
|
cat > ~/.ssh/config <<EOF
|
|
Host jump
|
|
HostName ${{ inputs.jump_host }}
|
|
User ${{ inputs.jump_user }}
|
|
Port ${{ inputs.jump_port }}
|
|
IdentityFile ~/.ssh/jump_key
|
|
StrictHostKeyChecking no
|
|
|
|
Host vm
|
|
HostName ${{ inputs.vm_ip }}
|
|
User ${{ inputs.vm_user }}
|
|
Port ${{ inputs.vm_port }}
|
|
IdentityFile ~/.ssh/vm_key
|
|
ProxyJump jump
|
|
StrictHostKeyChecking no
|
|
EOF
|
|
|
|
- name: Upload compose file
|
|
run: |
|
|
scp docker-compose.yml vm:${{ inputs.compose_path }}
|
|
|
|
- name: Restart services
|
|
run: |
|
|
ssh vm <<EOF
|
|
set -e
|
|
cd ${{ inputs.working_directory }}
|
|
docker compose down
|
|
docker compose up -d
|
|
EOF
|