diff --git a/.env.example b/.env.example index d210db09..cb707827 100644 --- a/.env.example +++ b/.env.example @@ -14,6 +14,8 @@ DB_NAME=kaikidb # Docker NODE_DOCKER_PORT=8080 NODE_ENV=production +# Same as DATABASE_URL but with localhost instead of db as host. +DATABASE_URL_DOCKER_BUILD= # Bot settings DADBOT_MAX_LENGTH=256 diff --git a/Dockerfile.dev b/Dockerfile.dev index 42261315..fa51cf14 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -6,7 +6,9 @@ RUN apt update && curl -sLO https://github.com/fastfetch-cli/fastfetch/releases/ COPY package*.json ./ RUN npm install COPY prisma . -RUN npx prisma generate +ARG DATABASE_URL +ENV DATABASE_URL $DATABASE_URL +RUN npx prisma db pull && npx prisma generate COPY . ./ RUN npm run build CMD ["npm", "run", "dev"] diff --git a/db.yml b/db.yml new file mode 100644 index 00000000..dd5ede88 --- /dev/null +++ b/db.yml @@ -0,0 +1,17 @@ +services: + db: + image: mariadb:latest + restart: unless-stopped + env_file: ./.env + command: --wait-timeout=28800 + ports: + - "3306:3306" + environment: + - MYSQL_ROOT_PASSWORD=$DB_ROOT_PASSWORD + - MYSQL_DATABASE=$DB_NAME + - MYSQL_USER=$DB_USER + - MYSQL_PASSWORD=$DB_PASSWORD + volumes: + - db:/var/lib/mysql +volumes: + db: diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 2b208bd5..ab7ef577 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,33 +1,19 @@ -version: "3.8" +include: + - db.yml services: - db: - image: mariadb:latest - restart: unless-stopped - env_file: ./.env - command: --wait-timeout=28800 - ports: - - "3307:3306" - environment: - - MYSQL_ROOT_PASSWORD=$DB_ROOT_PASSWORD - - MYSQL_DATABASE=$DB_NAME - - MYSQL_USER=$DB_USER - - MYSQL_PASSWORD=$DB_PASSWORD - volumes: - - db:/var/lib/mysql kaikibot: depends_on: - db build: context: . dockerfile: Dockerfile.dev + network: host args: - - DATABASE_URL=$DATABASE_URL + - DATABASE_URL=$DATABASE_URL_DOCKER_BUILD restart: unless-stopped env_file: ./.env stdin_open: true tty: true volumes: - - ./src:/usr/app/src -volumes: - db: + - ./src:/usr/app/src \ No newline at end of file