-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (99 loc) · 3.54 KB
/
deploy.yml
File metadata and controls
113 lines (99 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
name: Deploy to Production
on:
push:
tags:
- 'v*'
workflow_dispatch:
inputs:
version:
description: 'Image version to deploy'
required: true
default: 'latest'
jobs:
build-and-push:
name: Build and Push to GHCR
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Build and Push Images
run: |
./scripts/deployment/deploy-to-registry.sh \
--username ${{ github.repository_owner }} \
--token ${{ secrets.GITHUB_TOKEN }} \
--version ${{ steps.version.outputs.VERSION }}
deploy:
name: Deploy to Production Server
needs: build-and-push
runs-on: ubuntu-latest
if: ${{ success() }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set version
id: version
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
else
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
fi
- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -H ${{ secrets.DEPLOY_SERVER }} >> ~/.ssh/known_hosts
# Test SSH connection
ssh -i ~/.ssh/deploy_key -o ConnectTimeout=10 ${{ secrets.DEPLOY_USERNAME }}@${{ secrets.DEPLOY_SERVER }} "echo 'SSH connection successful'"
- name: Deploy Application
run: |
./scripts/deployment/deploy-to-server.sh \
--server ${{ secrets.DEPLOY_SERVER }} \
--domain ${{ secrets.DEPLOY_DOMAIN }} \
--username ${{ secrets.DEPLOY_USERNAME }} \
--ssh-key ~/.ssh/deploy_key \
--registry-url ghcr.io \
--registry-user ${{ github.repository_owner }} \
--registry-token ${{ secrets.GITHUB_TOKEN }} \
--image-version ${{ steps.version.outputs.VERSION }} \
--email ${{ secrets.DEPLOY_EMAIL }} \
--db-password ${{ secrets.DB_PASSWORD }}
- name: Verify Deployment
run: |
echo "Deployment completed successfully!"
echo "Application URL: https://${{ secrets.DEPLOY_DOMAIN }}"
echo ""
echo "To check deployment status, SSH into the server:"
echo " ssh ${{ secrets.DEPLOY_USERNAME }}@${{ secrets.DEPLOY_SERVER }}"
echo " cd /opt/erp-system"
echo " docker compose ps"
echo " docker compose logs -f"
notify:
name: Notify Deployment Status
needs: [build-and-push, deploy]
runs-on: ubuntu-latest
if: always()
steps:
- name: Deployment Success
if: ${{ success() }}
run: |
echo "✅ Deployment successful!"
echo "Application is available at: https://${{ secrets.DEPLOY_DOMAIN }}"
- name: Deployment Failed
if: ${{ failure() }}
run: |
echo "❌ Deployment failed!"
echo "Please check the logs for details."
exit 1