forked from MAMV3x3/MLH-Fellowship-pe-portfolio-site
-
Notifications
You must be signed in to change notification settings - Fork 0
125 lines (112 loc) · 3.98 KB
/
deploy.yml
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
114
115
116
117
118
119
120
121
122
123
124
125
name: Deploy
on:
push:
branches:
- main
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
name: Run Tests
env:
TESTING: true
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.10.12'
- name: Setup Python Virtual Environment
run: python -m venv python3-virtualenv
- name: Install Dependencies
run: python3-virtualenv/bin/pip install -r requirements.txt
- name: Run Tests
run: ./run_test.sh
deploy:
name: "Deploy to VPS"
runs-on: ubuntu-latest
needs: test
steps:
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
echo "$SSH_PRIVATE_KEY" > ~/.ssh/deploy-key.pem
chmod 600 ~/.ssh/deploy-key.pem
cat >> ~/.ssh/config <<END
Host my-vps
HostName $SSH_IP
User $SSH_USER
IdentityFile ~/.ssh/deploy-key.pem
StrictHostKeyChecking no
END
env:
SSH_USER: ${{ secrets.SSH_USER }}
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_IP: ${{ secrets.SSH_IP }}
- name: Deploy Site
run: ssh my-vps '~/redeploy-site.sh'
- name: Check Container Status
run: ssh my-vps 'docker ps'
- name: Get Current Date
id: get-date
run: echo "date=$(date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_ENV
shell: bash
- name: Send Discord Notification
if: success()
run: |
curl -s -H "Content-Type: application/json" \
-X POST "${{ secrets.DISCORD_WEBHOOK }}" \
-d '{
"username": "Deploy Buddy",
"avatar_url": "https://repository-images.githubusercontent.com/130118224/a2c75780-e0a9-11eb-8494-3581a0b1c93b",
"embeds": [
{
"title": "🚀 Deployment Successful",
"description": "Deployed commit `${{ github.sha }}` by `${{ github.actor }}` to production.",
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"color": 3066993,
"fields": [
{
"name": "Branch",
"value": "`${{ github.ref }}`",
"inline": true
},
{
"name": "Time",
"value": "`${{ env.date }}`",
"inline": true
}
]
}
]
}'
- name: Send Failure Discord Notification
if: failure()
run: |
curl -s -H "Content-Type: application/json" \
-X POST "${{ secrets.DISCORD_WEBHOOK }}" \
-d '{
"username": "Deploy Buddy",
"avatar_url": "https://i.imgur.com/z1CEtgs.jpeg",
"embeds": [
{
"title": "🚨 Deployment Failed",
"description": "Failed to deploy commit`${{ github.sha }}` by `${{ github.actor }}` to production.",
"url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"color": 16711680,
"fields": [
{
"name": "Branch",
"value": "`${{ github.ref }}`",
"inline": true
},
{
"name": "Time",
"value": "`${{ env.date }}`",
"inline": true
}
]
}
]
}'