-
Notifications
You must be signed in to change notification settings - Fork 1
112 lines (87 loc) · 3.17 KB
/
deploy.yml
File metadata and controls
112 lines (87 loc) · 3.17 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
name: Build, Test and Deploy Discord Bot to VPS
on:
# push:
# branches: [ "main" ]
workflow_dispatch: # Allow manual deployment
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm lint
- name: Type check
run: pnpm typecheck
- name: Build
run: pnpm build:ci
- name: Deploy to VPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
timeout: 30m
script: |
set -euo pipefail
echo "🚀 Starting deployment..."
# Create project directory if it doesn't exist
PROJECT_DIR="/home/${{ secrets.VPS_USER }}/moderation-tool-bot"
if [ ! -d "$PROJECT_DIR" ]; then
echo "📁 Creating project directory..."
mkdir -p "$PROJECT_DIR"
fi
# Navigate to project directory
cd "$PROJECT_DIR"
# Check if this is a git repository
if [ ! -d ".git" ]; then
echo "📦 Cloning repository..."
# Clone the repository if not already cloned
git clone https://github.com/r-webdev/moderation-tool.git .
git checkout main
fi
echo "🔄 Pulling latest changes..."
# Pull latest changes
git checkout main
git pull origin main --no-edit
echo "⚙️ Setting up environment..."
# Read Node version from .nvmrc
NODE_VERSION=$(cat .nvmrc | sed 's/v//')
echo "Using Node version: $NODE_VERSION"
# Create .env.local file with secrets
cat > .env.local << EOF
DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}
CLIENT_ID=${{ secrets.CLIENT_ID }}
SERVER_ID=${{ secrets.SERVER_ID }}
SPAM_DETECTION_CHANNEL_ID=${{ secrets.SPAM_DETECTION_CHANNEL_ID }}
ROLE_REGULAR_ID=${{ secrets.ROLE_REGULAR_ID }}
EOF
echo "🐳 Stopping existing containers..."
# Stop any existing containers (ignore errors if none running)
docker compose down --remove-orphans || true
echo "🏗️ Building and starting production container..."
# Build and start production container
docker compose --profile prod up -d --build --force-recreate
echo "⏳ Waiting for container to be healthy..."
# Wait a bit for the container to start
sleep 10
echo "🔍 Checking deployment status..."
# Check container status
if docker compose ps | grep -q "Up"; then
echo "✅ Deployment successful!"
else
echo "❌ Deployment failed!"
exit 1
fi
echo "🎉 Deployment completed successfully!"