Skip to main content
Deploy Faculty Bot using Docker containers for simplified deployment and management.

Prerequisites

  • Docker Engine 20.10 or later
  • Docker Compose v3 or later
  • At least 512MB of available RAM
  • PostgreSQL 13 (can be run in a separate container)

Docker Compose Setup

1

Clone the repository

git clone https://github.com/your-org/faculty-bot.git
cd faculty-bot
2

Configure environment variables

Create a .env file in the project root with the following variables:
DISCORD_TOKEN=your_discord_bot_token

DATABASE_URL=postgres://faculty_manager:averysecurepasswordyes@localhost/faculty_manager

PREFIX=>

SEND_FROM_ADDRESS=noreply@yourdomain.com
MAIL_USERNAME=your_email@yourdomain.com
MAIL_PASSWORD=your_email_password
SMTP_SERVER=smtp.yourdomain.com
SMTP_PORT=587

# PostgreSQL credentials (if using docker_db.yml)
POSTGRES_USER=faculty_manager
POSTGRES_PASSWORD=averysecurepasswordyes
POSTGRES_DB=faculty_manager

# Logging configuration
RUST_LOG="info,sqlx=error,sqlx::query=error,sqlx::query_as=error"
Never commit your .env file to version control. Use .env.example as a template.
3

Configure bot settings

Edit config.json to set up Discord channel and role IDs:
{
  "prefix": "..",
  "channels": {
    "xp": "YOUR_XP_CHANNEL_ID",
    "rules": "YOUR_RULES_CHANNEL_ID",
    "news": "YOUR_NEWS_CHANNEL_ID",
    "logs": "YOUR_LOGS_CHANNEL_ID",
    "ads": "YOUR_ADS_CHANNEL_ID",
    "createChannel": "🔊 New VoiceChannel",
    "mealplan": "YOUR_MEALPLAN_CHANNEL_ID"
  },
  "roles": {
    "staffrole": "YOUR_STAFF_ROLE_ID",
    "verified": "YOUR_VERIFIED_ROLE_ID",
    "mealplannotify": "YOUR_MEALPLAN_NOTIFY_ROLE_ID"
  }
}
4

Launch the bot with Docker Compose

Use the provided docker-compose.yml configuration:
version: "3"
services:
    bot:
        container_name: faculty_manager
        build: .
        volumes:
          - './config.json:/config.json:ro'
          - './images:/images'
          - './migrations:/migrations'
        env_file:
          - .env
        networks:
            - bot
networks: 
    bot: {}
Start the bot:
docker-compose up -d
Or use the pre-built image:
# Uncomment the image line in docker-compose.yml
# image: ghcr.io/rndrmu/facultymanager:latest
docker-compose up -d

Database Container Setup

For development or standalone deployments, you can run PostgreSQL in a container using docker_db.yml:
version: "3"
services:
  database:
    image: postgres:13
    ports: [5432:5432]
    network_mode: "host"
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - ./migrations/faculty_manager.sql:/docker-entrypoint-initdb.d/init.sql
1

Start the database

docker-compose -f docker_db.yml --env-file .env up -d
The database will automatically initialize using the migration script.
2

Verify database connection

docker logs database
Look for “database system is ready to accept connections”.
3

Connect the bot to the database

Update your .env file with the database connection string:
DATABASE_URL=postgres://faculty_manager:averysecurepasswordyes@localhost:5432/faculty_manager

Dockerfile Overview

The bot uses a multi-stage Docker build for optimized image size:
# Builder Stage
FROM rust:1.90-bullseye as builder

WORKDIR /faculty_manager

RUN apt-get update && apt-get install -y cmake && rm -rf /var/lib/apt/lists/*

# Cache dependencies
COPY Cargo.toml Cargo.lock ./
RUN mkdir src && \
    echo "fn main() {}" > src/main.rs && \
    cargo build --release && \
    rm -rf src target/release/deps/faculty_manager*

# Build the actual application
COPY . .
RUN cargo build --release

# Final Runtime Stage
FROM debian:bullseye-slim

# Install runtime dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
      ca-certificates \
      graphicsmagick \
      imagemagick \
      ghostscript && \
    rm -rf /var/lib/apt/lists/*

RUN mv /etc/ImageMagick-6/policy.xml /etc/ImageMagick-6/policy.xml.off || true

COPY --from=builder /faculty_manager/target/release/faculty_manager /usr/local/bin/faculty_manager

WORKDIR /app
COPY templates ./templates

CMD ["/usr/local/bin/faculty_manager"]
The Dockerfile includes ImageMagick and GraphicsMagick for meal plan PDF processing.

Docker Management

View Logs

# View bot logs
docker logs -f faculty_manager

# View database logs
docker logs -f database

Restart the Bot

docker-compose restart bot

Stop the Bot

docker-compose down

Rebuild After Changes

docker-compose build --no-cache
docker-compose up -d

Update to Latest Image

docker-compose pull
docker-compose up -d

Troubleshooting

Symptoms: Error messages about database connection failuresSolutions:
  • Verify DATABASE_URL in .env is correct
  • Ensure the database container is running: docker ps
  • Check if PostgreSQL is accepting connections: docker logs database
  • If using network_mode: host, ensure no firewall blocking port 5432
  • Test connection manually: docker exec -it database psql -U faculty_manager -d faculty_manager
Symptoms: Cannot read config.json or write to images/ directorySolutions:
  • Check file permissions: ls -la config.json images/
  • Ensure the Docker user has read access to mounted files
  • For Linux: chmod 644 config.json && chmod 755 images/
Symptoms: PDF conversion fails with policy errorsSolutions:
  • The Dockerfile already disables restrictive policies
  • If issues persist, check logs: docker logs faculty_manager | grep -i imagemagick
  • Verify PDF file is accessible in the container
Symptoms: docker ps shows container constantly restartingSolutions:
  • Check logs for errors: docker logs faculty_manager
  • Verify Discord token is valid in .env
  • Ensure all required environment variables are set
  • Check if config.json has valid JSON syntax
Symptoms: Meal plan downloads fail, SMTP connection issuesSolutions:
  • Verify network connectivity: docker exec faculty_manager ping -c 4 8.8.8.8
  • Check DNS resolution: docker exec faculty_manager nslookup google.com
  • Ensure no proxy or firewall blocking outbound connections
  • Verify SMTP credentials and server settings in .env

Performance Tuning

Resource Limits

Add resource constraints to docker-compose.yml:
services:
  bot:
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 512M
        reservations:
          memory: 256M

Logging Configuration

Control log verbosity in .env:
# Minimal logging
RUST_LOG="warn"

# Standard logging
RUST_LOG="info,sqlx=error,sqlx::query=error"

# Debug logging
RUST_LOG="debug"

Production Considerations

For production deployments, consider:
  • Using a managed PostgreSQL service instead of a container
  • Implementing automated backups for the database
  • Setting up monitoring and alerting
  • Using Docker secrets for sensitive environment variables
  • Enabling health checks in docker-compose.yml

Docker Compose with Health Checks

services:
  bot:
    healthcheck:
      test: ["CMD", "pgrep", "-f", "faculty_manager"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

Next Steps

Database Setup

Learn about database migrations and schema management

Configuration

Configure bot settings and features

Build docs developers (and LLMs) love