-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (117 loc) · 4.15 KB
/
deploy.yml
File metadata and controls
140 lines (117 loc) · 4.15 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
name: Deploy to Hostinger VPS
on:
push:
branches: [ main, production ]
workflow_dispatch:
inputs:
environment:
description: 'Deployment environment'
required: true
default: 'production'
type: choice
options:
- production
- staging
jobs:
deploy:
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'
cache-dependency-path: client/package-lock.json
- name: Install dependencies
run: |
cd client
npm ci
- name: Run tests
run: |
cd client
npm test -- --passWithNoTests
- name: Build application
run: |
cd client
npm run build
env:
DATABASE_URL: ${{ secrets.DATABASE_URL }}
NEXTAUTH_SECRET: ${{ secrets.NEXTAUTH_SECRET }}
NEXTAUTH_URL: ${{ secrets.NEXTAUTH_URL }}
RESEND_API_KEY: ${{ secrets.RESEND_API_KEY }}
CLOUDINARY_CLOUD_NAME: ${{ secrets.CLOUDINARY_CLOUD_NAME }}
CLOUDINARY_API_KEY: ${{ secrets.CLOUDINARY_API_KEY }}
CLOUDINARY_API_SECRET: ${{ secrets.CLOUDINARY_API_SECRET }}
- name: Deploy to VPS
uses: appleboy/[email protected]
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
key: ${{ secrets.VPS_SSH_KEY }}
port: ${{ secrets.VPS_PORT }}
script: |
# Set variables
APP_DIR="/var/www/wedding"
REPO_URL="https://github.com/${{ github.repository }}.git"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
# Create release directory
mkdir -p "$APP_DIR/releases"
cd "$APP_DIR/releases"
# Clone repository
git clone -b ${{ github.ref_name }} "$REPO_URL" "$TIMESTAMP"
cd "$TIMESTAMP/client"
# Install dependencies
npm ci --production=false
# Create environment file
cat > .env.local << 'EOF'
DATABASE_URL="${{ secrets.DATABASE_URL }}"
NEXTAUTH_SECRET="${{ secrets.NEXTAUTH_SECRET }}"
NEXTAUTH_URL="${{ secrets.NEXTAUTH_URL }}"
RESEND_API_KEY="${{ secrets.RESEND_API_KEY }}"
CLOUDINARY_CLOUD_NAME="${{ secrets.CLOUDINARY_CLOUD_NAME }}"
CLOUDINARY_API_KEY="${{ secrets.CLOUDINARY_API_KEY }}"
CLOUDINARY_API_SECRET="${{ secrets.CLOUDINARY_API_SECRET }}"
NODE_ENV="production"
PORT=3000
EOF
# Generate Prisma client and run migrations
npm run db:generate
npm run db:push
# Build application
npm run build
# Backup current deployment
if [ -d "$APP_DIR/current" ]; then
mv "$APP_DIR/current" "$APP_DIR/backup-$(date +%Y%m%d-%H%M%S)" || true
fi
# Update symbolic link
ln -sfn "$APP_DIR/releases/$TIMESTAMP" "$APP_DIR/current"
# Restart application
pm2 restart wedding-website || pm2 start ecosystem.config.js --env production
pm2 save
# Cleanup old releases (keep last 5)
cd "$APP_DIR/releases"
ls -t | tail -n +6 | xargs -d '\n' rm -rf -- || true
echo "Deployment completed successfully!"
- name: Health Check
run: |
# Wait for application to start
sleep 30
# Check if website is responding
response=$(curl -s -o /dev/null -w "%{http_code}" "${{ secrets.NEXTAUTH_URL }}/api/health" || echo "000")
if [ "$response" = "200" ]; then
echo "✅ Health check passed - Application is running"
else
echo "❌ Health check failed - HTTP status: $response"
exit 1
fi
- name: Notify deployment status
if: always()
run: |
if [ "${{ job.status }}" = "success" ]; then
echo "🎉 Deployment successful!"
echo "Website: ${{ secrets.NEXTAUTH_URL }}"
else
echo "❌ Deployment failed!"
fi