88 lines
2.9 KiB
YAML
88 lines
2.9 KiB
YAML
name: 'Docker Compose Deploy'
|
|
description: 'Deploy application using Docker Compose'
|
|
|
|
inputs:
|
|
compose_file:
|
|
description: 'Path to docker-compose file'
|
|
required: false
|
|
default: 'docker-compose.yml'
|
|
project_name:
|
|
description: 'Docker Compose project name'
|
|
required: true
|
|
url:
|
|
description: 'Url of the deployed application'
|
|
required: true
|
|
environment_file:
|
|
description: 'Path to environment file'
|
|
required: false
|
|
default: '.env'
|
|
image_url:
|
|
description: 'Docker image tag to deploy'
|
|
required: false
|
|
default: 'latest'
|
|
registry:
|
|
description: 'Docker registry'
|
|
required: false
|
|
default: 'git.klemp.dev'
|
|
deployment_key:
|
|
description: 'SSH deployment private key'
|
|
required: true
|
|
ssh_port:
|
|
description: 'SSH port'
|
|
required: true
|
|
ssh_host:
|
|
description: 'SSH host'
|
|
required: true
|
|
ssh_user:
|
|
description: 'SSH user'
|
|
required: true
|
|
|
|
runs:
|
|
using: 'composite'
|
|
steps:
|
|
- name: Get branch name
|
|
id: branch_name
|
|
uses: ./.gitea/actions/getTagSafeRef
|
|
|
|
- name: Setup SSH
|
|
uses: webfactory/ssh-agent@v0.9.1
|
|
with:
|
|
ssh-private-key: ${{ inputs.deployment_key }}
|
|
|
|
- name: Add SSH host to known hosts
|
|
shell: bash
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
ssh-keyscan -p ${{ inputs.ssh_port }} ${{ inputs.ssh_host }} >> ~/.ssh/known_hosts
|
|
|
|
cat > .env << EOF
|
|
IMAGE_URL='${{ inputs.image_url }}'
|
|
URL='${{ inputs.url }}'
|
|
REGISTRY=git.klemp.dev
|
|
PROJECT_NAME=${{ steps.branch_name.outputs.branch_name }}
|
|
COMPOSE_PROJECT_NAME=${{ steps.branch_name.outputs.branch_name }}
|
|
EOF
|
|
|
|
docker context rm deploy_target 2>/dev/null || true
|
|
docker context create deploy_target --docker "host=ssh://${{ inputs.ssh_user }}@${{ input.ssh_host }}:${{ input.ssh_port }}"
|
|
|
|
DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} down --remove-orphans || true
|
|
|
|
DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} pull
|
|
|
|
DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} up -d
|
|
|
|
echo "Waiting for services to start..."
|
|
sleep 10
|
|
|
|
CONTAINERS=$(DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} ps --services | tr '\n' ',' | sed 's/,$//')
|
|
echo "containers=$CONTAINERS" >> $GITHUB_OUTPUT
|
|
|
|
echo "✅ Deployment completed successfully!"
|
|
echo "🌐 URL: ${{ inputs.url }}"
|
|
echo "📦 Containers: $CONTAINERS"
|
|
|
|
echo "=== Deployment Status ==="
|
|
DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} ps
|
|
echo "========================="
|