-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (117 loc) · 4.02 KB
/
deploy-production.yml
File metadata and controls
145 lines (117 loc) · 4.02 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Deploy to derail.me
on:
push:
branches: [main, master]
workflow_dispatch:
inputs:
force_deploy:
description: 'Force deployment'
required: false
default: 'false'
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run TypeScript check
run: npm run check
- name: Run tests
run: npm test || echo "No tests configured yet"
- name: Build application
run: npm run build
deploy-production:
name: Deploy to Production
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
environment:
name: production
url: https://derail.me
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build application
run: npm run build
- name: Deploy to server
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.PRODUCTION_HOST }}
username: ${{ secrets.PRODUCTION_USER }}
key: ${{ secrets.PRODUCTION_SSH_KEY }}
port: ${{ secrets.PRODUCTION_PORT || 22 }}
script: |
set -e
echo "🚀 Starting deployment to derail.me..."
# Navigate to application directory
cd /var/www/chittypro-streamlink || {
echo "Creating application directory..."
sudo mkdir -p /var/www/chittypro-streamlink
sudo chown $USER:$USER /var/www/chittypro-streamlink
cd /var/www/chittypro-streamlink
}
# Backup current deployment
if [ -d "current" ]; then
echo "Creating backup..."
sudo cp -r current backup-$(date +%Y%m%d-%H%M%S) || true
fi
# Clone/update repository
if [ -d ".git" ]; then
echo "Updating repository..."
git fetch origin
git reset --hard origin/main
else
echo "Cloning repository..."
git clone ${{ github.server_url }}/${{ github.repository }} .
fi
# Install dependencies and build
echo "Installing dependencies..."
npm ci --production
echo "Building application..."
npm run build
# Update environment
echo "Updating environment..."
cp .env.production .env
# Update database schema
echo "Updating database..."
npm run db:push || echo "Database update failed, continuing..."
# Restart application
echo "Restarting application..."
pm2 restart chittypro-streamlink || pm2 start ecosystem.config.js --env production
pm2 save
# Reload nginx
echo "Reloading nginx..."
sudo nginx -t && sudo systemctl reload nginx
# Health check
echo "Performing health check..."
sleep 5
if curl -f https://derail.me/api/health > /dev/null 2>&1; then
echo "✅ Deployment successful! https://derail.me is live"
else
echo "⚠️ Health check failed, but deployment completed"
fi
echo "🎉 Deployment to derail.me completed!"
- name: Notify deployment status
if: always()
uses: 8398a7/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow
webhook_url: ${{ secrets.SLACK_WEBHOOK_URL }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}