Skip to content

Commit

Permalink
Several patches to make docker hosting easier. (#237)
Browse files Browse the repository at this point in the history
1. ppl can now config most settings in `djs-bot/.env`, `dashboard/.env`
and `docker/lavalink.env`.
2. make `docker/docker-compose.yml` more robust.
3. add an example of using traefik as revery proxy to hsot the bot.
  • Loading branch information
LewdHuTao authored Sep 13, 2024
2 parents 3f6acc0 + d5ce823 commit b44d6ba
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 51 deletions.
14 changes: 10 additions & 4 deletions djs-bot/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

# Discord configuration

TOKEN=abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890
# https://discord.com/developers/applications/YOUR_CLIENTID/bot
TOKEN=your_token
# https://discord.com/developers/applications/YOUR_CLIENTID/oauth2
CLIENTID=0123456789012345678
CLIENTSECRET=abcdefghijklmnopqrstuvwxyz123456
DEVUID=012345678901234567
JWT_SECRET_KEY=secretkey
JWT_SECRET_KEY=some_secretkey

# This was inserted by `prisma init`:
# Environment variables declared in this file are automatically made available to Prisma.
Expand All @@ -17,11 +19,15 @@ JWT_SECRET_KEY=secretkey
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
# Options: postgresql, mongodb, mysql, sqlite
DATABASE=""
DATABASE="postgresql"

# I don't recommend changing this unless you know what you're doing.
# To get rid of the DB entirely, remove this line completely.
DATABASE_URL="postgresql://root:root@postgres-db:5432/base?schema=public"
POSTGRES_USER=your_username
POSTGRES_PASSWORD=your_pg_pswd
POSTGRES_DB=your_db_name
PGPORT=5432
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres-db:${PGPORT}/${POSTGRES_DB}?schema=public"

# Backend configuration
API_PORT=8080
Expand Down
58 changes: 29 additions & 29 deletions djs-bot/config.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Allows for .env files to be imported and used
require('dotenv').config()
require("dotenv").config();

// exporting the module allows for other files to see all the properties in this file as a single object
module.exports = {
/**
* Name of the bot
* Name of the bot
* @type {string} */
name: "InsertNameHereBot",
/**
* Database option (mongodb, postgresql) https://www.prisma.io/docs/reference/database-reference/connection-urls
* @type {string} */
database: process.env.DATABASE || "postgresql",
/**
/**
* URL to the preferred database (Prisma ORM)
* @type {string} */
db_url: process.env.DATABASE_URL || "",
Expand All @@ -20,18 +20,18 @@ module.exports = {
* Secret information, use the ENV file to store these values if possible
*/
/**
* UID for the Admin(s) of the bot
* UID for the Admin(s) of the bot
* @type {string | string[]} */
ownerId: process.env.DEVUID || ["AdminID"],
/**
/**
* Token for bot login
* @type {string} */
token: process.env.TOKEN || "",
/**
/**
* ID of the bot
* @type {string} */
clientId: process.env.CLIENTID || "",
/**
/**
* Secret Token for bot login
* @type {string} */
clientSecret: process.env.CLIENTSECRET || "",
Expand Down Expand Up @@ -62,20 +62,20 @@ module.exports = {
// Lavalink server; optional public lavalink -> https://lavalink-list.darrennathanael.com/
// Or host one yourself -> https://github.com/lavalink-devs/Lavalink
//--> https://blog.darrennathanael.com/post/how-to-lavalink/
/**
/**
* Music engine to use
* @type {keyof typeof import("./lib/clients/MusicClient").Engine} */
musicEngine: "Erela",

/**
/**
* Nodes to connect to
* @type {import("erela.js").Node[]} */
nodes: [
{
identifier: "DockerNode", // log id string
host: "docker.lavalink",
port: 2333,
password: "youshallnotpass",
port: parseInt(process.env.SERVER_PORT) || 2333,
password: process.env.LAVALINK_SERVER_PASSWORD || "youshallnotpass",
retryAmount: 15, // for lavalink connection attempts
retryDelay: 6000, // Delay between reconnect attempts if connection is lost.
secure: false, // if lavalink is running SSL
Expand All @@ -91,34 +91,34 @@ module.exports = {
},
],

/**
/**
* Invite URL parameters
*/
/**
/**
* Scopes to request for the bot
* @type {import("discord.js").OAuth2Scopes[]}
*/
scopes: ["bot", "applications.commands"],

/**
/**
* Bot oauth scopes
* @type {import("discord.js").OAuth2Scopes[]}
*/
oauth2Scopes: ["identify", "guilds"],

/**
* Permissions to request for the bot
* @type {import("discord.js").PermissionResolvable | bigint}
* @see https://discord.com/developers/docs/topics/permissions#permissions
*/
/**
* Permissions to request for the bot
* @type {import("discord.js").PermissionResolvable | bigint}
* @see https://discord.com/developers/docs/topics/permissions#permissions
*/
permissions: 0, // 8 = Administrator, 0 = Doesn't need permissions (uses slash commands)

/**
* Other parameters used variously throughout the bot
*/
/**
*/
/**
* Debug mode for the bot
*
*
* 0 = No debug logging (production), 1 = Standard Logging (debug info), 2 = Development (everything)
* @type {number} */
OPLevel: 1,
Expand All @@ -128,11 +128,11 @@ module.exports = {
* @type {import('discord.js').ColorResolvable} */
embedColor: "Random",

/**
/**
* PresenceData object | https://discord.js.org/#/docs/main/stable/typedef/PresenceData
*/
presence: {
/**
/**
* online, idle, dnd, invisible, ...
* @type {import("discord.js").PresenceStatus} */
status: "online",
Expand All @@ -151,17 +151,17 @@ module.exports = {
data: (client) => {
return {
someVariable: client.guilds.cache.size,
}
}
};
},
},
{
name: "Music",
type: "LISTENING",
}
},
],
},

/**
/**
* This icon will be in every embed's author field, if you don't want it, just leave it blank or "undefined"
* @type {string} */
iconURL: undefined,
Expand All @@ -172,5 +172,5 @@ module.exports = {
autoPause: true,
autoQueue: false,
history: false,
}
},
};
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.env
lavalink.env
18 changes: 10 additions & 8 deletions docker/djs-bot/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM node:20 as builder

RUN apt-get update -y && \
apt-get install -y \
build-essential \
libpango1.0-dev \
libcairo2-dev \
librsvg2-dev \
libjpeg-dev \
libgif-dev \
fonts-noto-cjk fonts-noto \
apt-get install -y \
build-essential \
libpango1.0-dev \
libcairo2-dev \
librsvg2-dev \
libjpeg-dev \
libgif-dev \
fonts-noto-cjk fonts-noto
RUN npm config set audit false
RUN npm config set fund false
31 changes: 21 additions & 10 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
djs-bot:
container_name: djs-bot
Expand All @@ -18,11 +16,17 @@ services:
tty: true
volumes:
- ../djs-bot:/djs-bot
depends_on:
- postgres-db
- lavalink
ports:
- "8080:8080"
- "3001:3001"
working_dir: /djs-bot
command: ["npm", "run", "${ENABLE:-start}"]
command: ["npm", "run", "${ENABLE:-start}", "--loglevel=error"]
env_file:
- .env
- lavalink.env

dashboard:
container_name: dashboard
Expand All @@ -33,33 +37,40 @@ services:
tty: true
volumes:
- ../dashboard:/dashboard
depends_on:
- postgres-db
- lavalink
ports:
- "3000:3000"
working_dir: /dashboard
command: ["npm", "run", "build-and-start"]
command: sh -c "
npm config set fund false &&
npm config set audit false &&
npm run build-and-start
"
postgres-db:
image: postgres:15.2-alpine
image: postgres:16.4-alpine
container_name: postgres
restart: unless-stopped
environment:
POSTGRES_PASSWORD: root
POSTGRES_USER: root
POSTGRES_DB: base
PGPORT: 5432
volumes:
- postgres_data:/var/lib/postgresql/data
env_file:
- .env
lavalink:
image: fredboat/lavalink:3.7.12
container_name: lavalink
restart: unless-stopped
hostname: docker.lavalink
user: root
volumes:
- ./lavalink/application.yml:/opt/Lavalink/application.yml
- ./lavalink/plugins/:/opt/Lavalink/plugins
ports:
- 2333:2333
env_file:
- lavalink.env
volumes:
postgres_data:
Loading

0 comments on commit b44d6ba

Please sign in to comment.