Skip to content

Commit

Permalink
feat: bun and docker
Browse files Browse the repository at this point in the history
  • Loading branch information
leomotors committed Sep 9, 2023
1 parent 8e4df78 commit 5573eb2
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2,415 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish Release

on:
push:
tags:
- "*.*"

jobs:
tag-release:
name: Publish Release
runs-on: ubuntu-latest

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

- name: Publish Release
uses: Leomotors/auto-publish-release@main
with:
githubToken: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref }}
title: "Bots Gulag"

docker-push:
name: Build Docker Image
runs-on: ubuntu-latest

permissions:
id-token: write
packages: write

steps:
- uses: actions/checkout@v4
name: Check out code
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
push: true
tags: ghcr.io/carelessdev/bots-gulag:${{ github.ref_name }},ghcr.io/carelessdev/bots-gulag:latest
cache-from: type=gha
cache-to: type=gha,mode=max
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM oven/bun as installer

COPY package.json bun.lockb ./

RUN bun install --production --frozen-lockfile

FROM oven/bun as runner

USER bun

COPY --chown=bun:bun src ./src
COPY --chown=bun:bun package.json ./
COPY --chown=bun:bun --from=installer /home/bun/app/node_modules ./node_modules

CMD ["bun", "run", "start"]
16 changes: 2 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
# Bots Gulag

## Problem

Our server has many bots, but most of them doing nothing.

Literally just online.

By running many process, this is very laggy especially when [cocoa-grader](https://github.com/Leomotors/cocoa-grader)
the bots that use so many resources came in.

## Solution

Why not run all bots in a single process?

~~A study~~ shows that a bare nodejs process take a lot of RAM
Run 5 Discord Bots in the same process to make server feels active and not dead.
(It actually dead :skull:)
Binary file added bun.lockb
Binary file not shown.
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
"repository": "https://github.com/CarelessDev/bots-gulag",
"type": "module",
"private": true,
"packageManager": "[email protected]",
"scripts": {
"build": "tsc",
"clean": "rimraf dist/*",
"cb": "yarn clean && yarn build",
"start": "node dist/bot.js",
"start": "bun run src/bot.ts",
"format": "eslint . --fix",
"lint": "eslint . --max-warnings=0"
},
"dependencies": {
"chalk": "5.3.0",
"cocoa-discord-utils": "2.3.0",
"discord.js": "14.13.0",
"dotenv": "16.3.1",
"zod": "3.22.2"
},
"devDependencies": {
Expand All @@ -27,6 +22,10 @@
"@typescript-eslint/eslint-plugin": "6.6.0",
"@typescript-eslint/parser": "6.6.0",
"eslint": "8.49.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-sort-destructure-keys": "^1.5.0",
"prettier": "3.0.3",
"typescript": "5.2.2"
}
Expand Down
Loading

0 comments on commit 5573eb2

Please sign in to comment.