|
1 | | -name: Deploy to OpenStack |
| 1 | +# name: Trigger Deployment |
2 | 2 |
|
3 | | -# Required GitHub Environment Secrets: |
4 | | -# |
5 | | -# Create two environments in GitHub: "production" and "staging" |
6 | | -# Settings → Environments → New environment |
7 | | -# |
8 | | -# For each environment, add these secrets: |
9 | | -# - SSH_HOST: OpenStack instance hostname or IP address |
10 | | -# - SSH_USER: SSH username for the instance |
11 | | -# - SSH_PRIVATE_KEY: Private SSH key for authentication |
12 | | -# - SITE_URL: Site URL (for build) |
13 | | -# - BACKEND_URL: Backend URL (for build) |
14 | | -# - DEPLOY_PATH: (Optional) Deployment path (defaults to ~/processordb-website for prod, ~/processordb-website-staging for staging) |
15 | | -# - PORT: (Optional, staging only) Port for staging app (defaults to 3001 for same instance, set to 3000 for separate instance) |
| 3 | +# # This workflow triggers a webhook that your instance listens for |
| 4 | +# # The instance will then pull the latest code and rebuild |
16 | 5 |
|
17 | | -on: |
18 | | - push: |
19 | | - branches: |
20 | | - - main |
21 | | - - dev |
| 6 | +# on: |
| 7 | +# push: |
| 8 | +# branches: |
| 9 | +# - main |
| 10 | +# - dev |
22 | 11 |
|
23 | | -jobs: |
24 | | - deploy: |
25 | | - runs-on: ubuntu-latest |
| 12 | +# jobs: |
| 13 | +# notify: |
| 14 | +# runs-on: ubuntu-latest |
26 | 15 |
|
27 | | - # Determine environment based on branch |
28 | | - environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} |
| 16 | +# # Determine environment based on branch |
| 17 | +# environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} |
29 | 18 |
|
30 | | - env: |
31 | | - ENVIRONMENT: ${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }} |
32 | | - |
33 | | - steps: |
34 | | - - name: Checkout code |
35 | | - uses: actions/checkout@v4 |
36 | | - |
37 | | - - name: Setup Node.js |
38 | | - uses: actions/setup-node@v4 |
39 | | - with: |
40 | | - node-version: '20' |
41 | | - cache: 'npm' |
42 | | - |
43 | | - - name: Install dependencies |
44 | | - run: npm ci |
45 | | - |
46 | | - - name: Set environment variables |
47 | | - id: env |
48 | | - run: | |
49 | | - if [ "${{ github.ref }}" == "refs/heads/main" ]; then |
50 | | - echo "DEPLOY_PATH=${{ secrets.DEPLOY_PATH || '~/processordb-website' }}" >> $GITHUB_ENV |
51 | | - echo "PM2_APP_NAME=ProcessorDB-website" >> $GITHUB_ENV |
52 | | - echo "PM2_PORT=3000" >> $GITHUB_ENV |
53 | | - echo "ECOSYSTEM_FILE=ecosystem.config.js" >> $GITHUB_ENV |
54 | | - else |
55 | | - # For staging, use port from secret or default to 3001 (same instance) or 3000 (separate) |
56 | | - DEPLOY_PATH="${{ secrets.DEPLOY_PATH || '~/processordb-website-staging' }}" |
57 | | - STAGING_PORT="${{ secrets.PORT || '3001' }}" |
58 | | - |
59 | | - echo "DEPLOY_PATH=$DEPLOY_PATH" >> $GITHUB_ENV |
60 | | - echo "PM2_APP_NAME=ProcessorDB-website-staging" >> $GITHUB_ENV |
61 | | - echo "PM2_PORT=$STAGING_PORT" >> $GITHUB_ENV |
62 | | - echo "ECOSYSTEM_FILE=ecosystem.staging.config.js" >> $GITHUB_ENV |
63 | | - fi |
64 | | -
|
65 | | - - name: Build application |
66 | | - run: npm run build |
67 | | - env: |
68 | | - SITE_URL: ${{ secrets.SITE_URL }} |
69 | | - BACKEND_URL: ${{ secrets.BACKEND_URL }} |
70 | | - |
71 | | - - name: Create staging ecosystem config |
72 | | - if: github.ref != 'refs/heads/main' |
73 | | - run: | |
74 | | - PM2_PORT="${{ env.PM2_PORT }}" |
75 | | - cat > ecosystem.staging.config.js << EOF |
76 | | - module.exports = { |
77 | | - apps : [{ |
78 | | - name: "ProcessorDB-website-staging", |
79 | | - port: "$PM2_PORT", |
80 | | - exec_mode: "cluster", |
81 | | - instances: "max", |
82 | | - script: "./.output/server/index.mjs" |
83 | | - }] |
84 | | - } |
85 | | - EOF |
86 | | -
|
87 | | - - name: Create deployment archive |
88 | | - run: | |
89 | | - FILES=".output ecosystem.config.js package.json package-lock.json public server nuxt.config.ts" |
90 | | - if [ -f "ecosystem.staging.config.js" ]; then |
91 | | - FILES="$FILES ecosystem.staging.config.js" |
92 | | - fi |
93 | | - tar -czf deploy.tar.gz $FILES |
94 | | -
|
95 | | - - name: Setup SSH |
96 | | - uses: webfactory/[email protected] |
97 | | - with: |
98 | | - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} |
99 | | - |
100 | | - - name: Add server to known hosts |
101 | | - run: | |
102 | | - mkdir -p ~/.ssh |
103 | | - chmod 700 ~/.ssh |
104 | | - ssh-keyscan -H ${{ secrets.SSH_HOST }} 2>/dev/null >> ~/.ssh/known_hosts || echo "Warning: ssh-keyscan failed, will use StrictHostKeyChecking=accept-new" |
105 | | - chmod 644 ~/.ssh/known_hosts |
106 | | -
|
107 | | - - name: Deploy to ${{ env.ENVIRONMENT }} |
108 | | - run: | |
109 | | - DEPLOY_PATH="${{ env.DEPLOY_PATH }}" |
110 | | - PM2_APP_NAME="${{ env.PM2_APP_NAME }}" |
111 | | - ECOSYSTEM_FILE="${{ env.ECOSYSTEM_FILE }}" |
| 19 | +# steps: |
| 20 | +# - name: Trigger deployment webhook |
| 21 | +# run: | |
| 22 | +# ENVIRONMENT="${{ github.ref == 'refs/heads/main' && 'production' || 'staging' }}" |
| 23 | +# WEBHOOK_URL="${{ secrets.WEBHOOK_URL }}" |
| 24 | +# WEBHOOK_SECRET="${{ secrets.WEBHOOK_SECRET }}" |
112 | 25 |
|
113 | | - # Copy files to server (accept new host keys automatically) |
114 | | - scp -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=~/.ssh/known_hosts \ |
115 | | - -r deploy.tar.gz ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:$DEPLOY_PATH/ |
| 26 | +# # Create payload |
| 27 | +# PAYLOAD=$(cat <<EOF |
| 28 | +# { |
| 29 | +# "ref": "${{ github.ref }}", |
| 30 | +# "branch": "${{ github.ref_name }}", |
| 31 | +# "commit": "${{ github.sha }}", |
| 32 | +# "environment": "$ENVIRONMENT", |
| 33 | +# "repository": "${{ github.repository }}" |
| 34 | +# } |
| 35 | +# EOF |
| 36 | +# ) |
116 | 37 |
|
117 | | - # SSH into server and deploy (accept new host keys automatically) |
118 | | - ssh -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=~/.ssh/known_hosts \ |
119 | | - ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "bash -s" << EOF |
120 | | - set -e |
121 | | - cd $DEPLOY_PATH |
122 | | - |
123 | | - # Extract deployment files |
124 | | - tar -xzf deploy.tar.gz |
125 | | - |
126 | | - # Install/update dependencies |
127 | | - source ~/.nvm/nvm.sh |
128 | | - npm ci --production |
129 | | - |
130 | | - # Use staging ecosystem config if it exists, otherwise use production |
131 | | - if [ -f "$ECOSYSTEM_FILE" ]; then |
132 | | - PM2_CONFIG="$ECOSYSTEM_FILE" |
133 | | - else |
134 | | - PM2_CONFIG="ecosystem.config.js" |
135 | | - fi |
136 | | - |
137 | | - # Restart PM2 application |
138 | | - pm2 restart $PM2_APP_NAME || pm2 start $PM2_CONFIG |
139 | | - |
140 | | - # Save PM2 process list for auto-restart on reboot |
141 | | - pm2 save --force |
142 | | - |
143 | | - # Clean up |
144 | | - rm -f deploy.tar.gz |
145 | | - |
146 | | - echo "Deployment to ${{ env.ENVIRONMENT }} completed successfully" |
147 | | - EOF |
148 | | -
|
149 | | - - name: Cleanup |
150 | | - if: always() |
151 | | - run: rm -f deploy.tar.gz |
| 38 | +# # Send webhook with secret for authentication |
| 39 | +# curl -X POST "$WEBHOOK_URL" \ |
| 40 | +# -H "Content-Type: application/json" \ |
| 41 | +# -H "X-GitHub-Event: push" \ |
| 42 | +# -H "X-Webhook-Secret: $WEBHOOK_SECRET" \ |
| 43 | +# -d "$PAYLOAD" \ |
| 44 | +# --fail --show-error |
| 45 | + |
| 46 | +# echo "Deployment webhook triggered for $ENVIRONMENT" |
0 commit comments