Self-Hosting Ticketer

Looking to host the Ticketer bot on your own machine or server? The only required software to do so is Docker Engine. Need help? Join the Ticketer support server! This tutorial assumes you are running Linux to self-host the bot but any other operating system should work fine as well.

Creating the Compose File

Create a directory/folder with any name (like "Ticketer") and then create a file in that directory named "compose.yaml".

$mkdir Ticketer && cd Ticketer
$nano compose.yaml

Copy and paste the following content in the created file:

compose.yaml
name: 'ticketer'

services:
database:
image: mariadb:11
container_name: ticketer-database
restart: unless-stopped
healthcheck:
test: ['CMD', 'healthcheck.sh', '--connect', '--innodb_initialized']
interval: 10s
retries: 3
start_period: 10s
env_file:
- .env.database.production.local
volumes:
- ticketer_database_data:/var/lib/mysql
networks:
- ticketer_database_network

bot:
image: ghcr.io/carelessinternet/ticketer-bot:latest
container_name: ticketer-bot
restart: unless-stopped
# Change the platform to the one on your linux environment (amd64, arm64) if necessary.
# platform: linux/arm64
depends_on:
database:
condition: service_healthy
env_file:
- .env.bot.production.local
- .env.database.production.local
networks:
- ticketer_database_network

# Comment the service below if you do not want to self-host the website.
# The website is exposed on port 2027.
website:
build:
# You may change the version below to >= 3.5.0, or remove the last part after ".git".
context: https://github.com/CarelessInternet/Ticketer.git#v3.5.0
dockerfile: ./apps/website/Dockerfile
args:
NEXT_PUBLIC_SITE_URL: "http://localhost:2027" # Change to the public-facing URL if needed.
# NEXT_PUBLIC_UMAMI_ID: ""
# NEXT_PUBLIC_UMAMI_URL: ""
image: ticketer-website
pull_policy: never
container_name: ticketer-website
restart: unless-stopped
healthcheck:
test: ["CMD", "sh", "-c", "curl -f http://localhost:2027/health || exit 1"]
interval: 5s
timeout: 5s
retries: 5

volumes:
ticketer_database_data:

networks:
ticketer_database_network:

Environment Variables

You will need the credentials to the Discord bot/application. If you have not already, create a new Discord application (enable the "Server Members" intent!) and edit the following variables with the appropriate credentials in a new file named .env.bot.production.local. The variable DISCORD_GUILD_ID is the server (ID) where private commands are used. Put the details inside the quotation marks for the variables that have them!

$nano .env.bot.production.local
.env.bot.production.local
NODE_ENV="production"
DISCORD_APPLICATION_ID=""
DISCORD_BOT_TOKEN=""
DISCORD_GUILD_ID=""
DISCORD_OWNER_ID=""

The database also requires a few credentials to run. Create a file named .env.database.production.local and then create some login credentials with the following template below. You can change every variable to have whatever value you want except for DB_HOST.

$nano .env.database.production.local
.env.database.production.local
DB_HOST="ticketer-database"
DB_DATABASE="Ticketer"
DB_PORT=3306
DB_USER=""
DB_PASSWORD=""
MARIADB_DATABASE=${DB_DATABASE}
MYSQL_TCP_PORT=${DB_PORT}
MARIADB_USER=${DB_USER}
MARIADB_PASSWORD=${DB_PASSWORD}
MARIADB_RANDOM_ROOT_PASSWORD=true

Running the Bot

Now it is time to run the bot! Run the following command to start the database and bot (this may take some time):

$docker compose up -d

To deploy the application commands of the bot, run the following line:

$docker exec ticketer-bot sh -c "cd /src/apps/bot && pnpm commands:deploy:production"

Once the commands have been deployed, run the /migrate command in Discord to deploy any database changes that may be needed:

/migrate

If you want to stop the database and bot, run the command below:

$docker compose down

To pull the latest image/version of the bot:

$docker compose pull

Accessing The Database

If you want to access the database, you can do so by running the two commands below and replacing USERNAME with the username you chose in the environment variable:

$docker exec -it ticketer-database bash
$mariadb -u USERNAME -p