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 runs: using: 'composite' steps: - uses: webfactory/ssh-agent@v0.9.1 with: ssh-private-key: ${{ inputs.deployment_key }} - name: Create environment file 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 }} EOF - name: Debug environment file shell: bash run: | echo "=== ENVIRONMENT FILE DEBUG ===" echo "File path: ${{ inputs.environment_file }}" echo "" # Check if file exists if [ -f "${{ inputs.environment_file }}" ]; then echo "✅ Environment file exists" # Show file size and permissions ls -la "${{ inputs.environment_file }}" echo "" # Show file contents echo "📄 File contents:" echo "---" cat "${{ inputs.environment_file }}" echo "---" echo "" # Show line count LINE_COUNT=$(wc -l < "${{ inputs.environment_file }}") echo "📊 File has $LINE_COUNT lines" # Check for empty lines or whitespace issues echo "🔍 Checking for issues:" if grep -q "^$" "${{ inputs.environment_file }}"; then echo "⚠️ File contains empty lines" else echo "✅ No empty lines found" fi # Validate each variable is set echo "🔧 Variable validation:" while IFS='=' read -r key value; do if [ -n "$key" ] && [ -n "$value" ]; then echo " ✅ $key = $value" elif [ -n "$key" ]; then echo " ❌ $key is empty" fi done < "${{ inputs.environment_file }}" else echo "❌ Environment file does not exist!" fi echo "==============================" - name: Create Docker context shell: bash run: | docker context rm deploy_target 2>/dev/null || true docker context create deploy_target \ --docker "host=ssh://${{ vars.ssh_user }}@${{ vars.ssh_host }}:${{ vars.ssh_port }}" docker --context deploy_target info - 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 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/,$//') 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 echo "========================="