Files
phoenix/.gitea/workflows/commentDeploy.yml
Tobias Klemp ee1148ca9f
Some checks failed
CI / build-and-test (push) Has been cancelled
debug
2026-01-02 11:46:58 +01:00

87 lines
3.3 KiB
YAML

name: ChatOps Deploy
on: issue_comment
jobs:
testing:
if: |
gitea.event.issue.pull_request &&
startsWith(gitea.event.comment.body, '/deploy')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get branch name
id: branch_name
uses: ./.gitea/actions/getTagSafeRef
# - name: Build and push image
# id: docker_build
# uses: ./.gitea/actions/build
# with:
# tag: ${{ steps.branch_name.outputs.branch_name }}
# REGISTRY_ACCESS_TOKEN: ${{ secrets.REGISTRY_ACCESS_TOKEN }}
# REGISTRY_USER: ${{ gitea.actor }}
# - name: Deploy application
# uses: ./.gitea/actions/deploy
# with:
# project_name: ${{ steps.branch_name.outputs.branch_name }}
# url: '${{ steps.branch_name.outputs.branch_name }}.phoenix.klemp.local'
# # image_url: ${{ steps.docker_build.outputs.image_url }}
# image_url: 'git.klemp.dev/tech-reborn/phoenix:feature-branch-deployments'
# deployment_key: ${{ secrets.SSH_DEPLOYMENT_KEY }}
- name: Setup SSH
uses: webfactory/ssh-agent@v0.9.1
with:
ssh-private-key: ${{ secrets.SSH_DEPLOYMENT_KEY }}
- name: Create environment file
run: |
cat > ${{ inputs.environment_file }} << EOF
IMAGE_URL='git.klemp.dev/tech-reborn/phoenix:feature-branch-deployments'
URL='${{ steps.branch_name.outputs.branch_name }}.phoenix.klemp.local'
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
run: 'docker context rm deploy_target 2>/dev/null || true'
- name: Create Docker context
run: 'docker context create deploy_target --docker "host=ssh://${{ vars.ssh_user }}@${{ vars.ssh_host }}:${{ vars.ssh_port }}"'
- name: Validate Docker context
run: 'docker --context deploy_target info'
- name: Stop existing deployment
run: |
docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} down --remove-orphans || true
- name: Pull latest images
run: |
docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} pull
- name: Deploy with Docker Compose
id: deploy
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
run: |
echo "=== Deployment Status ==="
docker-compose --context deploy_target -f ${{ inputs.compose_file }} -p ${{ inputs.project_name }} ps
echo "========================="