Skip to content

Commit f81629f

Browse files
committed
auto deploy site for merges to main
1 parent 0707f7a commit f81629f

File tree

5 files changed

+237
-5
lines changed

5 files changed

+237
-5
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
name: Deploy Website to Droplet
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- web-653-autobuild-web # For testing before merge
8+
paths:
9+
- 'src/website/**'
10+
- '.github/workflows/deploy-website.yml'
11+
workflow_dispatch:
12+
13+
jobs:
14+
build-and-deploy:
15+
name: Build and Deploy Website
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '18'
26+
cache: 'npm'
27+
cache-dependency-path: src/website/package-lock.json
28+
29+
- name: Install dependencies
30+
working-directory: src/website
31+
run: npm ci
32+
33+
- name: Build website (standalone mode)
34+
working-directory: src/website
35+
run: npm run web:build
36+
env:
37+
MONGODB_URI: ${{ secrets.MONGODB_URI }}
38+
NEXT_PUBLIC_SERVER_HOST: ${{ secrets.NEXT_PUBLIC_SERVER_HOST }}
39+
NEXT_PUBLIC_SERVER_PORT: ${{ secrets.NEXT_PUBLIC_SERVER_PORT || '3005' }}
40+
NEXT_PUBLIC_POLLING_TIME_MS: ${{ secrets.NEXT_PUBLIC_POLLING_TIME_MS || '1000' }}
41+
42+
- name: Prepare deployment package
43+
working-directory: src/website
44+
run: |
45+
# Create deployment directory
46+
mkdir -p deploy-package
47+
48+
# Copy standalone build contents (not the folder itself)
49+
cp -r .next/standalone/. deploy-package/
50+
51+
# Copy static files
52+
mkdir -p deploy-package/.next/static
53+
cp -r .next/static/. deploy-package/.next/static/
54+
55+
# Copy public files
56+
cp -r public deploy-package/public
57+
58+
# Copy PM2 config
59+
cp ecosystem.config.js deploy-package/
60+
61+
echo "Deployment package prepared"
62+
ls -la deploy-package/
63+
64+
- name: Create deployment archive
65+
working-directory: src/website
66+
run: |
67+
tar -czf website-build.tar.gz -C deploy-package .
68+
echo "Archive created: $(ls -lh website-build.tar.gz)"
69+
70+
- name: Transfer build to droplet
71+
uses: appleboy/scp-action@v0.1.7
72+
with:
73+
host: ${{ secrets.SSH_HOST }}
74+
username: ${{ secrets.SSH_USERNAME }}
75+
key: ${{ secrets.SSH_KEY }}
76+
source: "src/website/website-build.tar.gz"
77+
target: "/tmp/"
78+
strip_components: 2
79+
80+
- name: Deploy with PM2
81+
uses: appleboy/ssh-action@v1.2.2
82+
with:
83+
host: ${{ secrets.SSH_HOST }}
84+
username: ${{ secrets.SSH_USERNAME }}
85+
key: ${{ secrets.SSH_KEY }}
86+
script: |
87+
set -e
88+
89+
echo "Starting deployment..."
90+
91+
# Create logs directory if it doesn't exist
92+
mkdir -p /root/sailbot_workspace/logs
93+
94+
# Navigate to website directory
95+
cd /root/sailbot_workspace/src/website
96+
97+
# Backup current build (if exists)
98+
if [ -d ".next" ]; then
99+
echo "Backing up current build..."
100+
rm -rf .next.backup
101+
mv .next .next.backup
102+
fi
103+
104+
# Extract new build
105+
echo "Extracting new build..."
106+
tar -xzf /tmp/website-build.tar.gz -C /root/sailbot_workspace/src/website
107+
rm /tmp/website-build.tar.gz
108+
109+
# Set environment variables for PM2
110+
export MONGODB_URI="${{ secrets.MONGODB_URI }}"
111+
export NEXT_PUBLIC_SERVER_HOST="${{ secrets.NEXT_PUBLIC_SERVER_HOST }}"
112+
export NEXT_PUBLIC_SERVER_PORT="${{ secrets.NEXT_PUBLIC_SERVER_PORT || '3005' }}"
113+
export NEXT_PUBLIC_POLLING_TIME_MS="${{ secrets.NEXT_PUBLIC_POLLING_TIME_MS || '1000' }}"
114+
115+
# Update PM2 ecosystem file with current env vars
116+
cat > /root/sailbot_workspace/src/website/.env.production << EOF
117+
MONGODB_URI=$MONGODB_URI
118+
NEXT_PUBLIC_SERVER_HOST=$NEXT_PUBLIC_SERVER_HOST
119+
NEXT_PUBLIC_SERVER_PORT=$NEXT_PUBLIC_SERVER_PORT
120+
NEXT_PUBLIC_POLLING_TIME_MS=$NEXT_PUBLIC_POLLING_TIME_MS
121+
NODE_ENV=production
122+
PORT=3005
123+
EOF
124+
125+
# Check if PM2 process exists
126+
if pm2 list | grep -q "sailbot-website"; then
127+
echo "Reloading existing PM2 process..."
128+
pm2 reload ecosystem.config.js --update-env
129+
else
130+
echo "Starting new PM2 process..."
131+
pm2 start ecosystem.config.js
132+
fi
133+
134+
# Save PM2 process list
135+
pm2 save
136+
137+
# Show PM2 status
138+
echo "Deployment complete"
139+
pm2 list
140+
pm2 info sailbot-website
141+
142+
# Cleanup old backup after successful deployment
143+
rm -rf .next.backup
144+
145+
echo "Website deployed successfully"

.github/workflows/deployment.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
name: Deployment
1+
name: Deployment (Legacy - Docker based)
2+
3+
# Old Docker-based deployment - disabled in favor of deploy-website.yml
24

35
on:
4-
# Uncomment once we are ready to deploy
5-
#push:
6-
# branches:
7-
# - main
6+
# Disabled
7+
# push:
8+
# branches:
9+
# - main
810
workflow_dispatch:
911

1012
jobs:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Website PR Check
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
paths:
8+
- 'src/website/**'
9+
- '.github/workflows/website-pr-check.yml'
10+
11+
jobs:
12+
build-and-test:
13+
name: Build Website
14+
runs-on: ubuntu-latest
15+
defaults:
16+
run:
17+
working-directory: src/website
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: '18'
27+
cache: 'npm'
28+
cache-dependency-path: src/website/package-lock.json
29+
30+
- name: Install dependencies
31+
run: npm ci
32+
33+
- name: Run Prettier check
34+
run: npm run format -- --check
35+
36+
- name: Run ESLint
37+
run: npx next lint
38+
39+
- name: Run TypeScript type check
40+
run: npx tsc --noEmit
41+
42+
- name: Build website
43+
run: npm run web:build
44+
env:
45+
MONGODB_URI: ${{ secrets.MONGODB_URI || 'mongodb://localhost:27017/sailbot' }}
46+
NEXT_PUBLIC_SERVER_HOST: http://localhost
47+
NEXT_PUBLIC_SERVER_PORT: 3005
48+
NEXT_PUBLIC_POLLING_TIME_MS: 1000
49+
50+
- name: Check build output
51+
run: |
52+
if [ ! -d ".next" ]; then
53+
echo "Build failed - .next directory not found"
54+
exit 1
55+
fi
56+
echo "Build succeeded"
57+

src/website/ecosystem.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
apps: [
3+
{
4+
name: 'sailbot-website',
5+
script: 'server.js',
6+
cwd: '/root/sailbot_workspace/src/website',
7+
instances: 1,
8+
exec_mode: 'cluster',
9+
autorestart: true,
10+
watch: false,
11+
max_memory_restart: '1G',
12+
env: {
13+
NODE_ENV: 'production',
14+
PORT: 3005,
15+
MONGODB_URI: process.env.MONGODB_URI || 'mongodb://localhost:27017/sailbot',
16+
NEXT_PUBLIC_SERVER_HOST: process.env.NEXT_PUBLIC_SERVER_HOST || 'http://localhost',
17+
NEXT_PUBLIC_SERVER_PORT: process.env.NEXT_PUBLIC_SERVER_PORT || '3005',
18+
NEXT_PUBLIC_POLLING_TIME_MS: process.env.NEXT_PUBLIC_POLLING_TIME_MS || '1000',
19+
},
20+
error_file: '/root/sailbot_workspace/logs/website-error.log',
21+
out_file: '/root/sailbot_workspace/logs/website-out.log',
22+
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
23+
merge_logs: true,
24+
},
25+
],
26+
};
27+

src/website/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const nextConfig = {
2+
output: 'standalone',
23
webpack(config) {
34
const fileLoaderRule = config.module.rules.find((rule) =>
45
rule.test?.test?.('.svg'),

0 commit comments

Comments
 (0)