diff --git a/docker-compose.yml b/docker-compose.yml index 09f44143..c4c965f7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,15 +6,23 @@ services: container_name: ticket-bot environment: - TOKEN - - DATABASE_URL=postgres://postgres:postgres@pgsql:5432/postgres + networks: + - net depends_on: - pgsql restart: on-failure + volumes: + - /opt/ticket-bot/config:/app/config pgsql: image: postgres:15.3-alpine environment: - POSTGRES_PASSWORD=postgres + networks: + - net volumes: - - ./db-data:/var/lib/postgresql/data - ports: - - "5432:5432" \ No newline at end of file + - /opt/ticket-bot/pgsql:/var/lib/postgresql/data + restart: on-failure + +networks: + net: + driver: bridge \ No newline at end of file diff --git a/docker_run.sh b/docker_run.sh index d271094f..1c0e2036 100644 --- a/docker_run.sh +++ b/docker_run.sh @@ -1,2 +1,22 @@ +#!/bin/bash + +# Setup the config files +if [ ! -f "./config/config.json" ]; then + if [ -f "./temp_config/config.jsonc" ]; then + # Config already setup by the user + echo "Pre-build config detected, moving to config folder..."; + mv ./temp_config/config.jsonc ./config/config.jsonc + else + # Config not setup by the user + echo "Config not detected, creating config..."; + echo "Make sure to edit the config file in /opt/ticket-bot/config/config.jsonc before starting the bot again."; + mv ./temp_config/config.example.jsonc ./config/config.jsonc + exit 1; + fi +else + echo "Config detected, cleaning up temp_config..."; + rm -rf ./temp_config +fi + npx prisma db push --schema=./prisma/docker.prisma npm run start \ No newline at end of file diff --git a/dockerfile b/dockerfile index 53755173..5b1d6503 100644 --- a/dockerfile +++ b/dockerfile @@ -2,10 +2,10 @@ FROM node:20.3-alpine # Setup workspace WORKDIR /app -ENV DATABASE_URL="postgresql://postgres:postgres@db:5432/postgres?schema=public" +ENV DATABASE_URL=postgresql://postgres:postgres@pgsql:5432/postgres?schema=public # Copy runtime files -COPY ./config/config.jsonc ./config/config.jsonc +COPY ./config/ ./temp_config COPY docker_run.sh . COPY locales ./locales @@ -22,5 +22,9 @@ COPY tsconfig.json . COPY src ./src RUN npm run build +# Setup Bash +RUN apk add --no-cache bash +RUN chmod +x ./docker_run.sh + # Start the server -CMD ["./docker_run.sh"] \ No newline at end of file +ENTRYPOINT ["./docker_run.sh"] \ No newline at end of file