140 lines
3.7 KiB
YAML
140 lines
3.7 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: "~"
|
|
|
|
infisical_env:
|
|
description: "Infisical Environment"
|
|
type: string
|
|
required: true
|
|
|
|
infisical_path:
|
|
description: "Infisical secret path"
|
|
type: string
|
|
required: false
|
|
default: "/"
|
|
|
|
infisical_api_url:
|
|
description: "Infisical API URL (for self-hosted instances)"
|
|
type: string
|
|
required: false
|
|
default: "https://secrets.itlab-ffeks.dnu.edu.ua"
|
|
|
|
secrets:
|
|
infisical_project_token:
|
|
description: "Infisical Service Token for project secrets"
|
|
required: true
|
|
|
|
infisical_cicd_token:
|
|
description: "Infisical Service Token for CI/CD secrets"
|
|
required: true
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Configure SSH
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
chmod 700 ~/.ssh
|
|
|
|
export INFISICAL_TOKEN="${{ secrets.infisical_cicd_token }}"
|
|
export INFISICAL_API_URL="${{ inputs.infisical_api_url }}"
|
|
export INFISICAL_DOMAIN="$INFISICAL_API_URL"
|
|
export INFISICAL_DISABLE_UPDATE_CHECK=true
|
|
|
|
echo "Fetching SSH keys from Infisical..."
|
|
JUMP_KEY=$(infisical secrets get JUMP_SSH_KEY --plain)
|
|
VM_KEY=$(infisical secrets get VM_SSH_KEY --plain)
|
|
|
|
if [ -z "$JUMP_KEY" ] || [ -z "$VM_KEY" ]; then
|
|
echo "Error: SSH keys retrieved from Infisical are empty!" >&2
|
|
exit 1
|
|
fi
|
|
|
|
echo "$JUMP_KEY" > ~/.ssh/jump_key
|
|
chmod 600 ~/.ssh/jump_key
|
|
|
|
echo "$VM_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: Test SSH connection to VM
|
|
run: |
|
|
ssh -vvv vm 'echo "SSH connection successful" && hostname && whoami'
|
|
|
|
- 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 }}
|
|
|
|
export INFISICAL_TOKEN="${{ secrets.infisical_project_token }}"
|
|
export INFISICAL_API_URL="${{ inputs.infisical_api_url }}"
|
|
export INFISICAL_DOMAIN="$INFISICAL_API_URL"
|
|
export INFISICAL_DISABLE_UPDATE_CHECK=true
|
|
|
|
INFISICAL_ENV="${{ inputs.infisical_env }}"
|
|
INFISICAL_PATH="${{ inputs.infisical_path }}"
|
|
|
|
echo "Running docker compose down and up under Infisical..."
|
|
infisical run --env="$INFISICAL_ENV" --path="$INFISICAL_PATH" -- docker compose down
|
|
infisical run --env="$INFISICAL_ENV" --path="$INFISICAL_PATH" -- docker compose up -d
|
|
EOF
|