Skip to content

Commit c1646d6

Browse files
RahulKanduriclaude
andcommitted
feat: add automated production deployment workflow
Add GitHub Actions workflow for automated deployment to production server. Features: - Automated deployment on push to master - Manual deployment trigger via workflow_dispatch - Builds library and Storybook on GitHub runner - Rsync deployment over SSH - Automatic PM2 process restart - Secure SSH key handling with cleanup Configuration required: - PRODUCTION_SSH_KEY: SSH private key - PRODUCTION_HOST: Server IP address - PRODUCTION_USER: SSH username - PRODUCTION_PATH: Deployment directory path Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 2643266 commit c1646d6

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Deploy to Production Server
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: '20'
20+
cache: 'npm'
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Build library
26+
run: npm run build
27+
28+
- name: Build Storybook
29+
run: npm run build-storybook
30+
31+
- name: Setup SSH key
32+
run: |
33+
mkdir -p ~/.ssh
34+
echo "${{ secrets.PRODUCTION_SSH_KEY }}" > ~/.ssh/deploy_key
35+
chmod 600 ~/.ssh/deploy_key
36+
ssh-keyscan -H ${{ secrets.PRODUCTION_HOST }} >> ~/.ssh/known_hosts
37+
38+
- name: Deploy to production server
39+
run: |
40+
rsync -avz --delete \
41+
--exclude '.git' \
42+
--exclude '.github' \
43+
--exclude 'logs/*.log' \
44+
--exclude '.env*' \
45+
--exclude 'coverage' \
46+
--exclude '.DS_Store' \
47+
--exclude 'debug-storybook.log' \
48+
-e "ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no" \
49+
./ ${{ secrets.PRODUCTION_USER }}@${{ secrets.PRODUCTION_HOST }}:${{ secrets.PRODUCTION_PATH }}/
50+
51+
- name: Restart PM2 process
52+
run: |
53+
ssh -i ~/.ssh/deploy_key -o StrictHostKeyChecking=no \
54+
${{ secrets.PRODUCTION_USER }}@${{ secrets.PRODUCTION_HOST }} << 'EOF'
55+
cd ${{ secrets.PRODUCTION_PATH }}
56+
echo "πŸ”„ Restarting PM2 storybook process..."
57+
pm2 restart storybook
58+
echo "βœ… PM2 process restarted successfully"
59+
echo ""
60+
echo "πŸ“Š PM2 Status:"
61+
pm2 list
62+
echo ""
63+
echo "πŸ“ Deployed to: $(pwd)"
64+
echo "πŸ“… Deployment time: $(date)"
65+
EOF
66+
67+
- name: Cleanup SSH key
68+
if: always()
69+
run: rm -f ~/.ssh/deploy_key
70+
71+
- name: Deployment summary
72+
if: success()
73+
run: |
74+
echo "βœ… Deployment completed successfully!"
75+
echo "πŸ“‚ Files deployed to production server"

0 commit comments

Comments
Β (0)