vocascan / vocascan-server

Server for Vocascan
https://vocascan.com
Apache License 2.0
26 stars 5 forks source link

Container crashes when using sqlite as DB dialect #97

Open simplylu opened 1 year ago

simplylu commented 1 year ago

Describe the bug Docker container crashes on startup when current Dockerfile is used for the build or the official image, and one selects sqlite as DB backend.

To Reproduce Steps to reproduce the behavior: Via Dockerfile

  1. Clone repository
  2. Build docker container using docker build
  3. Change DB backend to sqlite
  4. Use official traefik installation way to start the container
  5. Container won't start, the docs will produce the below stacktrace

Via official container

  1. Use official traefik installation way to start the container
  2. Change DB backend to sqlite
  3. Container won't start, the docs will produce the below stacktrace

Expected behavior Container should start without any problems.

Desktop (please complete the following information):

Additional context Traceback

info: loaded config file "/etc/vocascan/vocascan.config.js"
error: unhandledRejection: Please install sqlite3 package manually
Error: Please install sqlite3 package manually
    at ConnectionManager._loadDialectModule (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:81:15)
    at new ConnectionManager (/app/node_modules/sequelize/lib/dialects/sqlite/connection-manager.js:24:21)
    at new SqliteDialect (/app/node_modules/sequelize/lib/dialects/sqlite/index.js:15:30)
    at new Sequelize (/app/node_modules/sequelize/lib/sequelize.js:340:20)
    at Object.db.init (/app/database/index.js:34:20)
    at createServer (/app/server.js:22:12)
    at Command.<anonymous> (/app/cmd/web.js:18:26)
    at Command.listener [as _actionHandler] (/app/node_modules/commander/lib/command.js:488:17)
    at /app/node_modules/commander/lib/command.js:1227:65

Possible solution: I changed the Dockerfile to the following, and at least the error disappeared. Need to test further whether the container works as expected or not.

FROM node:14-alpine as builder

RUN apk add --no-cache build-base python3

WORKDIR /build

COPY ./package*.json ./

RUN npm i --only=production

FROM node:14-alpine

WORKDIR /app

COPY --from=builder /build/node_modules /app/node_modules

COPY . .

RUN npm link

# Added this line explicitly. Adding it in the builder context didn't work somehow.
RUN npm install sqlite3

CMD ["vocascan-server", "web"]
luwol03 commented 1 year ago

Hello @js-on,

this is currently a bug which has not been fixed. It definitely was working sometime before. We have a custom postinstall hook, which normally should install sqlite if the --sqlite flag is used on npm ci --sqlite. Normally this should also work inside of the builder stage, but it could be that some native stuff is not correctly copied.

noctera commented 1 year ago

In the meantime, however, there are two ways to fix this problem.

  1. Use a different database than Sqlite3, for example Postgresql. This lets you get your server up and running.
  2. Either your way directly modifying the docker build script file, or write a wrapper around it, as shown below: create a "Dockerfile" in your directory with the following content:
FROM vocascan/server:latest

RUN npm install sqlite3

After that update your "docker-compose.yml" file and add the "build" property and remove the "image" property. This could look like this:

version: "3.8"
services:
vocascan:
  restart: always
  build:
    context: .
    dockerfile: Dockerfile
  tty: true
  environment:
    VOCASCAN_CONFIG: "/etc/vocascan/vocascan.config.js"
  ports:
    - "8000:8000"
  volumes:
    - "./vocascan.config.js:/etc/vocascan/vocascan.config.js:ro"

This will pull the vocascan/server image as base image, and will build a local image with the sqlite3 npm package installed. I just tested it locally, with success.