Craig can be installed and ran locally. Some use cases for this are:
- Contributing to Craig's source code
- Creating multiple instances of Craig
Craig can only be ran on a Linux machine. The installation has been tested on a fresh install of Ubuntu 22.04 and Kubuntu 23.10.
The following apt
packages will be automatically installed by the install script install.sh:
make inkscape ffmpeg flac fdkaac vorbis-tools opus-tools zip unzip lsb-release curl gpg redis postgresql sed coreutils build-essential
git clone --recurse-submodules https://github.com/CraigChat/craig.git
We need to create a Discord Bot account for the Craig instance.
- Log into Discord
- Navigate to the developer application page
- Click on
New Application
in the top-right - Give your new Craig instance a name (e.g. LocalCraig or MyCraigBot)
- Accept terms of service and click
Create
- Under
SETTINGS->General Information
take note and copy down the following:- APPLICATION ID (corresponds to
DISCORD_APP_ID
)
- APPLICATION ID (corresponds to
- Under
SETTINGS->Bot
take note and copy down the following:- TOKEN (corresponds to
DISCORD_BOT_TOKEN
)- you might have to click
Reset Token
if this is hidden
- you might have to click
- TOKEN (corresponds to
- Under
SETTINGS->OAuth2->General
take note and copy down the following:- CLIENT ID (corresponds to
CLIENT_ID
) - CLIENT SECRET (correpsonds to
CLIENT_SECRET
)- you might have to click
Reset Secret
if this is hidden
- you might have to click
- CLIENT ID (corresponds to
- Under
SETTINGS->OAuth2->General
click onAdd Redirect
and paste in the following URI: http://localhost:3000/api/login - Save changes
- Under
SETTINGS->General Information->APP ICON
click on the photo icon - You can use the default one, which is located in the git repo: apps/download/page/public/craig.png. I recommend changing it slightly so as not to get confused with the actual Craig bot
After installation, your self-hosted instance of Craig can be invited to any Discord server. There is an optional environment variable in install.config.example which sets the development server for synchronized slash commands: DEVELOPMENT_GUILD_ID
. Running yarn run sync:dev
in the main git repo will then only synchronize commands to that development sever, as opposed to all the servers your Craig bot has been invited to. This gives you a sandbox in which to test experimental slash commands.
- Follow this guide to create a Discord server
- Follow this guide to obtain your new server's ID
Copy the example config file in the main directory and rename it
cp ./install.config.example ./install.config
Edit the following environment variables in the newly created install.config file with values you obtained from the previous step:
DISCORD_BOT_TOKEN
DISCORD_APP_ID
CLIENT_ID
CLIENT_SECRET
and optionally:
DEVELOPMENT_GUILD_ID
There are additional configuration variables in install.config.example, such as Craig's PostgreSQL database username and password, Patreon ID, etc.
There are even more configuration options located in: apps/bot/config/_default.js and apps/tasks/config/_default.js.
Changing some of these variables from their default values will break Craig, so be careful.
Go into the main directory and run the following:
./install.sh
Note that the script will prompt for sudo
privileges, in order to automatically install dependencies and configure PostgreSQL.
The installation should take a while. Please make note of any errors or warnings. The install generates an output log located in the main directory: install.log.
You can invite Craig to any Discord server by going to the following URL in your browser. Just make sure to replace CLIENT_ID
in the URL with the actual value of your Discord Bot's client ID.
If everything went smoothly up to now, there should be a running instance of Craig on your local machine. Congratulations!
You can try recording and using Craig's slash commands.
Located at: http://localhost:3000/login
Craig automatically serves the download pages with the https://
protocol. For example, if you try to go to the download page after recording, the link will be of the form:
https://localhost:5029/rec/RECORDING_ID
Most if not all browsers won't serve this because localhost
doesn't have a signed certificate for https://
. You can simply change the protocol to http://
by removing the s
and then you will be able to access your recording download:
http://localhost:5029/rec/RECORDING_ID
When testing with Kubuntu 23.10, the following error stops sudo apt update
from working, which prematurely exits the install script:
E: Failed to fetch https://packages.redis.io/deb/dists/mantic/InRelease 403 Forbidden [IP: 18.173.121.98 443]
E: The repository 'https://packages.redis.io/deb mantic InRelease' is not signed.
This occurs because Redis does not have a signature for the Kubuntu 23.10 release (Mantic).
A workaround is to comment out the first line in /etc/apt/sources.list.d/redis.list
, i.e.:
#deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb mantic main
To avoid having to continually comment this out every time the install script is ran, you can add the #
directly in install.sh:
echo "#deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list
This might need to be done for other distributions as well.
By default, Craig will not automatically restart if you reboot your computer. You can re-run a modified version of install.sh script so that the following steps are performed:
- Make sure the Redis server is online
- Make sure the PostgreSQL database is online
- Start the application
To speed up the restart (and avoid rebuilding Craig), you should comment out some unnecessary steps (function calls) in the install script:
# install_apt_packages
# install_node
start_redis
start_postgresql
# config_env
# config_react
# config_yarn
# config_cook
start_app
Here are some useful commands for debugging the installation and for monitoring the Craig application. Make sure that you have sourced nvm
and you are using the installed version of node
in order to run pm2
commands:
source ~/.nvm/nvm.sh
nvm use node
pm2 monit
pm2 logs > pm2.log
pm2 restart all
pm2 stop all