diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..30e1811e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM --platform=linux/amd64 node:18-slim +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" +ENV NEXT_TELEMETRY_DISABLED 1 +WORKDIR "/Master-Bot" + +# Ports for the Dashboard +EXPOSE 3000 +ENV PORT 3000 + +# Install prerequisites and register fonts +RUN apt-get update && apt-get upgrade -y -q && \ + apt-get install -y -q openssl && \ + apt-get install -y -q --no-install-recommends libfontconfig1 && \ + npm install -g pnpm + +# Copy files to Container (Excluding whats in .dockerignore) +COPY ./ ./ +RUN pnpm install --ignore-scripts && pnpm -F * build + +# If you are running Master-Bot in a Standalone Container and need to connect to a service on localhost uncomment the following ENV for each service running on the containers host +# ENV POSTGRES_HOST="host.docker.internal" +# ENV REDIS_HOST="host.docker.internal" +# ENV LAVA_HOST="host.docker.internal" + +# Uncomment the following for Standalone Master-Bot Docker Container Build +# RUN pnpm db:push +# CMD ["pnpm", "-r", "start"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..ec8317b4 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,85 @@ +version: '3' +services: + master-bot: + platform: 'linux/amd64' + env_file: + - docker.env + restart: always + build: . + ports: + - '3000:3000' # Dashboard + # - "5555:5555" # Prisma Studio Port - uncomment to open + command: > + sh -c "pnpm run db:push && pnpm run -r start" + depends_on: + lavalink: + condition: service_healthy + postgres: + condition: service_healthy + redis: + condition: service_healthy + environment: + POSTGRES_USER: ${POSTGRES_USER} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} # Password is required and must match '.env' file + POSTGRES_DB_NAME: ${POSTGRES_DB_NAME} # Must match '.env' file + POSTGRES_PORT: ${POSTGRES_PORT} + POSTGRES_HOST: ${POSTGRES_HOST} # Must match '.env' file + REDIS_HOST: ${REDIS_HOST} # Must match service name + REDIS_PORT: ${REDIS_PORT} + REDIS_DB: ${REDIS_DB} + links: + - lavalink + - redis + - postgres + volumes: + - ./logs:/Master-Bot/apps/bot/logs + lavalink: + restart: always + image: fredboat/lavalink:3-alpine + healthcheck: + test: 'echo lavalink' + interval: 10s + timeout: 10s + retries: 3 + volumes: + - ./application.yml:/opt/Lavalink/application.yml + postgres: + env_file: + - docker.env + image: postgres:15-alpine + restart: always + healthcheck: + test: + ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB_NAME}'] + interval: 10s + timeout: 5s + retries: 5 + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB_NAME=${POSTGRES_DB_NAME} + - POSTGRES_PORT=${POSTGRES_PORT} + volumes: + - postgres:/var/lib/postgresql/data + redis: + env_file: + - docker.env + image: redis:7-alpine + restart: always + environment: + - ALLOW_EMPTY_PASSWORD=yes + - REDIS_PORT=${REDIS_PORT} + - REDIS_DB=${REDIS_DB} + command: redis-server --save 20 1 --loglevel warning + healthcheck: + test: ['CMD', 'redis-cli', 'ping'] + interval: 10s + timeout: 10s + retries: 3 + volumes: + - redis:/data +volumes: + postgres: + driver: local + redis: + driver: local diff --git a/docker.env b/docker.env new file mode 100644 index 00000000..947ddb8b --- /dev/null +++ b/docker.env @@ -0,0 +1,26 @@ + # Editing this file is not required and used for Docker-Compose Only + # these will overwrite the needed .env variables to create and link ALL the containers correctly + # Fill out your .env as normal then to dockerize + # run "docker compose --env-file docker.env up -d --build" in root folder + + # Prisma Override + DATABASE_URL="postgresql://postgresUsername:postgresPassword@postgres:5432/master-bot?schema=public&connect_timeout=300" + + # LavaLink Docker Container + LAVA_HOST="lavalink" + LAVA_PASS="youshallnotpass" + LAVA_PORT=2333 + LAVA_SECURE=false + + # Postgres Docker Container + POSTGRES_HOST="postgres" + POSTGRES_USER="postgresUsername" + POSTGRES_PORT=5432 + POSTGRES_PASSWORD="postgresPassword" + POSTGRES_DB_NAME="master-bot" + + # Redis Docker Container + REDIS_HOST="redis" + REDIS_PORT=6379 + REDIS_DB=0 + REDIS_PASSWORD="redisPassword" \ No newline at end of file diff --git a/package.json b/package.json index ee2acf27..f745db8f 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "lint": "turbo lint && manypkg check", "lint:fix": "turbo lint:fix && manypkg fix", "type-check": "turbo type-check", - "postinstall": "pnpm db:push" + "postinstall": "pnpm db:push", + "docker-compose": "docker compose --env-file docker.env up -d --build" }, "dependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.1.0",