-
-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (93 loc) · 3.36 KB
/
deploy.yml
File metadata and controls
117 lines (93 loc) · 3.36 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
name: Deploy to Production
on:
push:
branches:
- main
workflow_dispatch: # Allow manual trigger
jobs:
deploy:
name: Deploy to VPS
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
- name: Install SSH key
uses: shimataro/ssh-key-action@v2
with:
key: ${{ secrets.VPS_SSH_KEY }}
known_hosts: unnecessary
if_key_exists: replace
- name: Add VPS to known hosts
run: ssh-keyscan -H ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to VPS
env:
VPS_HOST: ${{ secrets.VPS_HOST }}
VPS_USER: ${{ secrets.VPS_USER }}
run: |
ssh $VPS_USER@$VPS_HOST << 'ENDSSH'
set -e
echo "🚀 Starting deployment..."
cd ~/apps/core
# Initialize rbenv
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init - bash)"
# Pull latest changes
echo "📥 Pulling latest code from main..."
git fetch origin
git reset --hard origin/main
# Generate REVISION file with commit SHA and branch
echo "📝 Generating REVISION file..."
COMMIT_SHA=$(git rev-parse HEAD)
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "${COMMIT_SHA}|${BRANCH}" > REVISION
echo "✅ REVISION: ${BRANCH}@${COMMIT_SHA:0:7}"
# Install dependencies
echo "📦 Installing dependencies..."
bundle install --deployment --without development test
# Load environment variables
export $(cat .env | grep -v '^#' | xargs)
# Precompile assets
echo "🎨 Precompiling assets..."
RAILS_ENV=production bundle exec rails assets:precompile
# Run database migrations
echo "🗄️ Running database migrations..."
RAILS_ENV=production bundle exec rails db:migrate
# Restart services (zero-downtime)
echo "🔄 Restarting Puma (zero-downtime)..."
sudo systemctl reload core-puma
echo "🔄 Restarting Solid Queue..."
sudo systemctl restart core-solidqueue
# Verify deployment
echo "✅ Deployment complete!"
echo "📊 App status:"
sudo systemctl status core-puma --no-pager -l
ENDSSH
- name: Verify deployment
env:
VPS_HOST: ${{ secrets.VPS_HOST }}
VPS_USER: ${{ secrets.VPS_USER }}
run: |
# Wait for app to be ready
sleep 5
# Check if site is responding
if curl -f -s -o /dev/null https://rectorspace.com/up; then
echo "✅ Production site is healthy!"
else
echo "❌ Production site health check failed!"
exit 1
fi
- name: Notify deployment success
if: success()
run: |
echo "✅ Deployment successful!"
echo "🌐 Visit: https://rectorspace.com"
- name: Notify deployment failure
if: failure()
run: |
echo "❌ Deployment failed!"
echo "Check logs: https://github.com/${{ github.repository }}/actions"