Skip to content

Commit abaaf96

Browse files
committed
Add CI/CD for Linode deployment from this repo
1 parent 123f85c commit abaaf96

File tree

1 file changed

+120
-0
lines changed

1 file changed

+120
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Deploy to Linode Production
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
workflow_dispatch:
7+
8+
jobs:
9+
deploy:
10+
name: Deploy to Linode Server
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Deploy to Linode via SSH
18+
uses: appleboy/ssh-action@v1.0.3
19+
with:
20+
host: ${{ secrets.LINODE_HOST }}
21+
username: ${{ secrets.LINODE_USER }}
22+
key: ${{ secrets.LINODE_SSH_KEY }}
23+
port: 5422
24+
script: |
25+
set -e
26+
27+
echo "🚀 Starting deployment to Linode Production..."
28+
echo "================================================"
29+
30+
# Navigate to application directory
31+
cd /var/www/greenwood-kiosk
32+
33+
# Show current state
34+
echo "📍 Current location: $(pwd)"
35+
echo "📝 Current commit: $(git log -1 --oneline)"
36+
37+
# Fetch latest code
38+
echo ""
39+
echo "📥 Fetching latest code from GitHub..."
40+
sudo -u rails git fetch origin
41+
sudo -u rails git reset --hard origin/main
42+
43+
echo "✅ Updated to commit: $(git log -1 --oneline)"
44+
45+
# Install Ruby dependencies
46+
echo ""
47+
echo "💎 Installing Ruby dependencies..."
48+
sudo -u rails bash -lc 'cd /var/www/greenwood-kiosk && bundle install --deployment --without development test'
49+
50+
# Install JavaScript dependencies (if package.json changed)
51+
if git diff HEAD@{1} HEAD --name-only | grep -q "package.json\|yarn.lock"; then
52+
echo ""
53+
echo "📦 Installing JavaScript dependencies..."
54+
sudo -u rails bash -lc 'cd /var/www/greenwood-kiosk && yarn install --frozen-lockfile'
55+
else
56+
echo ""
57+
echo "⏭️ Skipping JavaScript dependencies (no changes)"
58+
fi
59+
60+
# Run database migrations
61+
echo ""
62+
echo "🗄️ Running database migrations..."
63+
sudo -u rails bash -lc 'cd /var/www/greenwood-kiosk && RAILS_ENV=production bundle exec rails db:migrate'
64+
65+
# Precompile assets (if assets changed)
66+
if git diff HEAD@{1} HEAD --name-only | grep -q "app/assets\|app/javascript"; then
67+
echo ""
68+
echo "🎨 Precompiling assets..."
69+
sudo -u rails bash -lc 'cd /var/www/greenwood-kiosk && RAILS_ENV=production bundle exec rails assets:precompile'
70+
else
71+
echo ""
72+
echo "⏭️ Skipping asset precompilation (no changes)"
73+
fi
74+
75+
# Restart Rails application
76+
echo ""
77+
echo "🔄 Restarting Rails application..."
78+
sudo systemctl restart greenwood-admin.service
79+
80+
# Wait a moment for service to start
81+
sleep 3
82+
83+
# Check service status
84+
echo ""
85+
echo "📊 Service Status:"
86+
sudo systemctl status greenwood-admin.service --no-pager -l | head -20 || true
87+
88+
# Check if service is running
89+
if sudo systemctl is-active --quiet greenwood-admin.service; then
90+
echo ""
91+
echo "✅ Service is RUNNING"
92+
else
93+
echo ""
94+
echo "❌ WARNING: Service may not be running properly!"
95+
exit 1
96+
fi
97+
98+
# Show recent logs
99+
echo ""
100+
echo "📜 Recent logs (last 10 lines):"
101+
sudo journalctl -u greenwood-admin.service -n 10 --no-pager || true
102+
103+
echo ""
104+
echo "================================================"
105+
echo "🎉 Deployment completed successfully!"
106+
echo "================================================"
107+
108+
- name: Notify on success
109+
if: success()
110+
run: |
111+
echo "✅ Deployment to Linode successful!"
112+
echo "Deployed commit: ${{ github.sha }}"
113+
echo "By: ${{ github.actor }}"
114+
115+
- name: Notify on failure
116+
if: failure()
117+
run: |
118+
echo "❌ Deployment to Linode FAILED!"
119+
echo "Check the logs above for details"
120+
exit 1

0 commit comments

Comments
 (0)