Maxime-J / umami-sqlite

Umami with SQLite
20 stars 2 forks source link

Usage in Docker #2

Closed eikaramba closed 1 year ago

eikaramba commented 1 year ago

This is more a question than an issue. I wanted to use the base image from umami and just add some docker lines to patch it e.g.

FROM ghcr.io/umami-software/umami:postgresql-latest AS base
ADD https://raw.githubusercontent.com/Maxime-J/umami-sqlite/main/1.40.0.patch /app
WORKDIR /app
USER root
RUN chmod +x /app/1.40.0.patch
RUN patch -p1 < /app/1.40.0.patch

but of course that does not work. the patch needs to be applied before building. so currently i am creating my own docker container from scratch, basically using the dockerfile from umami as a base and just adding the patch somewhere.

i am just curious (not an docker expert). could i just git clone the whole repo within a dockerfile to avoid having to maintain my own repo with the source files in it? again, this is just a question and if you don't have the time or knowledge feel free to ignore this and close the ticket. no hard feelings :)

Maxime-J commented 1 year ago

Indeed, going from scratch is the better way to go :)

I'm not very familiar with Docker, but yes, what you suggest is feasible. Basing on the Dockerfile from umami, it can be done with something like that:

FROM node:16-alpine AS umami
RUN apk add --no-cache git
RUN git clone https://github.com/umami-software/umami

FROM node:16-alpine AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
COPY --from=umami /umami/package.json ./
COPY --from=umami /umami/yarn.lock ./
RUN yarn install --frozen-lockfile

FROM node:16-alpine AS builder
COPY --from=umami /umami /app
COPY --from=deps /app/node_modules /app/node_modules
WORKDIR /app

[...]
eikaramba commented 1 year ago

thank you, i am now trying to use my own repo for now. on windows because of the EOL syntax it is a little bit more difficult to apply the patch. but i will make it work for sure.

and if that does not work, i will just clone inside a docker container ;)

eikaramba commented 1 year ago

unfortunately i need to reopen this ticket: i get

2023-03-30T15:48:54.797689683Z $ npm-run-all check-db update-tracker start-server
2023-03-30T15:48:55.695429938Z $ node scripts/check-db.js
2023-03-30T15:48:55.945922750Z ✓ DATABASE_URL is defined.
2023-03-30T15:48:56.060971261Z ✗ Unable to connect to the database.

i patched the source files. i have a hard time understanding what the problem is

volume is on /database database_url is file:/database/db.db indeed i cannot see a database file inside the volume i just don't know why

eikaramba commented 1 year ago

could it be that the prisma folder needs to be a persistant volume? because i tried to build locally and saw that upon building a database file is created int he prisma folder! that could explain why just setting an abritrary path does not work

Maxime-J commented 1 year ago

Weird, a database connection error in that context likely means Prisma can't access the path you gave.

About your last message, if not already there the db file is created when check-db is run, knowing that: -for a relative path, in most situations, it's relative to the prisma folder. -with the way Umami is handling Docker, check-db isn't called during build process, but at start.

"build": "npm-run-all build-db check-db build-tracker build-geo build-app",
"build-docker": "npm-run-all build-db build-tracker build-geo build-app",
"start-docker": "npm-run-all check-db update-tracker start-server",
"check-db": "node scripts/check-db.js",

So, if you gave it /database/db.db, with docker volume mounted on /database, no db file is created in prisma folder, no db file is created during build process, db.db should be created at container first run in your docker volume.

Would you mind to share the Dockerfile and the command used to run the container?

eikaramba commented 1 year ago

i got it working!

I think it was because the nextjs user does not have rights to write files into the volume. you see at the end of the dockerline, how to this user is switched. normally no problem, but because in the sqlite case we need to write the database this is a problem.

changing it to root fixed it i think. i also changed ENV DATABASE_URL="file:./database.db" to ENV DATABASE_URL="file:/app/prisma/database.db" but given that i anyway change the env file in the caprover interface and it overwrites the default it should not matter.

Maxime-J commented 1 year ago

Cool!👍 Thanks for the details. I'll mention some guidelines in the readme.

I would suggest however to only put the database in the volume, mounting it in a new folder (not the prisma one). I think it can prevent some future issues in case of updates or whatever.

The previous comment has been deleted in order to leave the implementation to everyone.