Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
02f5e3b
chore: update pnpm version and enhance deployment workflow
wiktoriavh Oct 18, 2025
d32f516
ci: add id to Node setup step in deployment workflow
wiktoriavh Oct 18, 2025
515c871
ci: add logging
wiktoriavh Oct 18, 2025
0e97dad
ci: store Node version in environment for deployment workflow
wiktoriavh Oct 18, 2025
2fdf6cc
chore: update Dockerfile to install production dependencies only
wiktoriavh Oct 18, 2025
e5e2a49
chore: update Dockerfile to ignore scripts during production dependen…
wiktoriavh Oct 18, 2025
6eb1266
chore: update TypeScript version in pnpm-lock.yaml
wiktoriavh Oct 18, 2025
8b3a7dc
ci: enhance deployment workflow to include file transfer and containe…
wiktoriavh Oct 18, 2025
bb11e8c
ci: add new deployment workflow for Discord bot to streamline VPS upd…
wiktoriavh Oct 18, 2025
471ef2b
ci: simplify deployment workflow for Discord bot by consolidating ste…
wiktoriavh Oct 18, 2025
9bbc2cf
ci: update deployment workflow to include .env.local file creation wi…
wiktoriavh Oct 18, 2025
4c70007
ci: read Node version from .nvmrc and set it in the environment for d…
wiktoriavh Oct 18, 2025
89e7520
ci: update deployment workflow to use 'docker compose' command for im…
wiktoriavh Oct 18, 2025
aef229e
ci: read Node version from .nvmrc and output it during deployment wor…
wiktoriavh Oct 18, 2025
2be4ccb
ci: remove version specification from docker-compose.yml for streamli…
wiktoriavh Oct 18, 2025
c0120f8
chore: update TypeScript version to 5.9.3 in package.json and pnpm-lo…
wiktoriavh Oct 18, 2025
c908403
chore: modify Dockerfile to ignore scripts during pnpm install for im…
wiktoriavh Oct 18, 2025
a79b76f
ci: update deployment workflow to switch to 'ci/deploy-with-docker' b…
wiktoriavh Oct 18, 2025
118c47f
ci: enhance docker-compose.yml to include guides tracker configuratio…
wiktoriavh Oct 18, 2025
8d60678
chore: add data directory creation and permissions setup for node use…
wiktoriavh Oct 18, 2025
a159aa2
feat: enhance command deployment logic to support both global and gui…
wiktoriavh Oct 18, 2025
8df6150
feat: add server ID configuration to Discord settings for enhanced co…
wiktoriavh Oct 18, 2025
222be71
feat: add SERVER_ID to deployment workflow for Discord integration
wiktoriavh Oct 18, 2025
6f5660d
Merge branch 'main' into ci/deploy-with-docker
wiktoriavh Oct 19, 2025
a3ca10e
chore: update dependencies in pnpm-lock.yaml
wiktoriavh Oct 19, 2025
b04735f
refactor: remove guildId from deployCommands function to streamline c…
wiktoriavh Oct 19, 2025
0f4bdea
feat: add additional configuration variables for repel command in dep…
wiktoriavh Oct 19, 2025
d4d9ee8
fix: update activity name in client presence for improved clarity
wiktoriavh Oct 19, 2025
6f937f9
chore: update deployment workflow to pull from main branch instead of…
wiktoriavh Oct 19, 2025
92951c6
chore: remove SERVER_ID from Discord configuration in env.ts
wiktoriavh Oct 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 52 additions & 66 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,60 @@
name: Build, Test and Deploy Discord Bot to VPS

on:
workflow_dispatch: # Manual trigger only
# Uncomment below when VPS is ready:
# push:
# branches: [ "main" ]
# paths-ignore:
# - 'docs/**'
# - '.gitignore'
# - 'LICENSE'
push:
branches: [ "main" ]
workflow_dispatch: # Allow manual deployment

jobs:
build-test-deploy:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

- name: Install dependencies
run: |
if [ -f package-lock.json ]; then
npm ci --no-audit --no-fund
else
npm install --no-audit --no-fund
fi

- name: Lint
run: npm run lint

- name: Build bot
run: npm run build:ci

- name: Run tests
run: npm run test:ci

- name: Package build output
run: tar czf bot-build.tar.gz ./dist

- name: Copy build artifact to VPS
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
source: "bot-build.tar.gz"
target: "/home/${{ secrets.VPS_USER }}/discord-bot/"

- name: Create .env file on VPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
script: |
echo "DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }}" > /home/${{ secrets.VPS_USER }}/discord-bot/.env
echo "CLIENT_ID=${{ secrets.CLIENT_ID }}" >> /home/${{ secrets.VPS_USER }}/discord-bot/.env

- name: Extract and restart bot on VPS
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
script: |
cd /home/${{ secrets.VPS_USER }}/discord-bot/
tar xzf bot-build.tar.gz
pm2 restart bot || pm2 start ./dist/index.js --name bot
- name: Checkout code
uses: actions/checkout@v4

- name: Read Node version
run: |
NODE_VERSION=$(cat .nvmrc | sed 's/v//')
echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV

- 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 }}
script: |
cd /home/${{ secrets.VPS_USER }}/webdev-bot-deploy

# Stash any local changes
git stash push -m "Auto-deploy $(date)" 2>/dev/null || true

# Pull latest changes
git checkout main
git pull origin main

# Read NODE_VERSION from .nvmrc
export 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 }}
GUIDES_CHANNEL_ID=${{ secrets.GUIDES_CHANNEL_ID }}
SERVER_ID=${{ secrets.SERVER_ID }}
REPEL_LOG_CHANNEL_ID=${{ secrets.REPEL_LOG_CHANNEL_ID }}
REPEL_ROLE_ID=${{ secrets.REPEL_ROLE_ID }}
MODERATORS_ROLE_IDS=${{ secrets.MODERATORS_ROLE_IDS }}
EOF

# Stop any existing containers
docker compose down || true

# Build and start production container with profile
docker compose --profile prod up -d --build

# Check status
echo "Deployment completed. Container status:"
docker compose ps
38 changes: 38 additions & 0 deletions .github/workflows/shorter-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build, Test and Deploy Discord Bot to VPS but shorter

on:
workflow_dispatch: # Allow manual deployment

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- 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 }}
script: |
cd /home/${{ secrets.VPS_USER }}/webdev-bot

# Stash any local changes
git stash push -m "Auto-deploy $(date)" 2>/dev/null || true

# Pull latest changes
git checkout main
git pull origin main

# Stop any existing containers
docker-compose down || true

# Build and start production container with profile
docker-compose --profile prod up -d --build

# Check status
echo "Deployment completed. Container status:"
docker-compose ps
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ FROM base AS deps

COPY package.json pnpm-lock.yaml ./

RUN pnpm install --prod --frozen-lockfile
RUN pnpm install --frozen-lockfile --production --ignore-scripts

# Dev dependencies stage - Install all dependencies
FROM base AS deps-dev

COPY package.json pnpm-lock.yaml ./

RUN pnpm install --frozen-lockfile
RUN pnpm install --frozen-lockfile --ignore-scripts

# Build stage - Compile TypeScript
FROM deps-dev AS build
Expand All @@ -41,6 +41,9 @@ COPY --from=deps /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY package.json ./

# Create data directory and set permissions for node user
RUN mkdir -p /app/data && chown -R node:node /app/data

# Run as non-root user for security
USER node

Expand All @@ -53,6 +56,9 @@ ENV NODE_ENV=development

COPY . .

# Create data directory and set permissions for node user
RUN mkdir -p /app/data && chown -R node:node /app/data

# Run as non-root user for security
USER node

Expand Down
14 changes: 12 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
# Production service - optimized runtime
bot-prod:
Expand All @@ -12,6 +10,11 @@ services:
restart: unless-stopped
env_file:
- .env.local
environment:
- GUIDES_TRACKER_PATH=/app/data/guides-tracker.json
volumes:
# Persist guides tracker data
- guides-data:/app/data
profiles:
- prod

Expand All @@ -26,6 +29,8 @@ services:
restart: unless-stopped
env_file:
- .env.local
environment:
- GUIDES_TRACKER_PATH=/app/data/guides-tracker.json
volumes:
# Mount source code for hot reload
- ./src:/app/src:ro
Expand All @@ -35,6 +40,11 @@ services:
# Mount package files (in case dependencies change)
- ./package.json:/app/package.json:ro
- ./pnpm-lock.yaml:/app/pnpm-lock.yaml:ro
# Persist guides tracker data
- guides-data:/app/data
profiles:
- dev

volumes:
guides-data:
driver: local
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"packageManager": "pnpm@10.17.1",
"dependencies": {
"discord.js": "^14.22.1",
"typescript": "^5.9.3",
"web-features": "^3.3.0"
},
"devDependencies": {
Expand All @@ -42,8 +43,7 @@
"husky": "^9.1.7",
"lint-staged": "^16.2.1",
"tsup": "^8.5.0",
"tsx": "^4.20.6",
"typescript": "^5.9.2"
"tsx": "^4.20.6"
},
"lint-staged": {
"*.{ts,js}": [
Expand Down
Loading