This commit is contained in:
@@ -27,66 +27,61 @@ inputs:
|
||||
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:
|
||||
- uses: webfactory/ssh-agent@v0.9.1
|
||||
with:
|
||||
ssh-private-key: ${{ inputs.deployment_key }}
|
||||
- name: Get branch name
|
||||
id: branch_name
|
||||
uses: ./.gitea/actions/getTagSafeRef
|
||||
|
||||
- name: Create environment file
|
||||
- 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: |
|
||||
cat > ${{ inputs.environment_file }} << EOF
|
||||
IMAGE_URL=${{ inputs.image_url }}
|
||||
URL=${{ inputs.url }}
|
||||
REGISTRY=${{ inputs.registry }}
|
||||
PROJECT_NAME=${{ inputs.project_name }}
|
||||
COMPOSE_PROJECT_NAME=${{ inputs.project_name }}
|
||||
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
|
||||
|
||||
- name: Remove old Docker context
|
||||
shell: bash
|
||||
run: 'docker context rm deploy_target 2>/dev/null || true'
|
||||
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 }}"
|
||||
|
||||
- name: Create Docker context
|
||||
shell: bash
|
||||
run: 'docker context create deploy_target --docker "host=ssh://${{ vars.ssh_user }}@${{ vars.ssh_host }}:${{ vars.ssh_port }}"'
|
||||
DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} down --remove-orphans || true
|
||||
|
||||
- name: Validate Docker context
|
||||
shell: bash
|
||||
run: 'docker --context deploy_target info'
|
||||
DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} pull
|
||||
|
||||
- name: Stop existing deployment
|
||||
shell: bash
|
||||
run: |
|
||||
docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} down --remove-orphans || true
|
||||
|
||||
- name: Pull latest images
|
||||
shell: bash
|
||||
run: |
|
||||
docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} pull
|
||||
|
||||
- name: Deploy with Docker Compose
|
||||
id: deploy
|
||||
shell: bash
|
||||
run: |
|
||||
docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} up -d
|
||||
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-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} ps --services | tr '\n' ',' | sed 's/,$//')
|
||||
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"
|
||||
|
||||
- name: Show deployment status
|
||||
shell: bash
|
||||
run: |
|
||||
echo "=== Deployment Status ==="
|
||||
docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} ps
|
||||
DOCKER_CONTEXT=deploy_target docker compose -f docker-compose.yml -p ${{ steps.branch_name.outputs.branch_name }} ps
|
||||
echo "========================="
|
||||
|
||||
Reference in New Issue
Block a user