Build and run docker image issues
Hi @Maxime-J
I'm also trying to adapt Dockerfile to include sqlite, but I'm not sure at which phase I should inject patch from discussion on closed https://github.com/Maxime-J/umami-sqlite/issues/2 builder phase seems to be the right one, but I see mysql db detected instead in the build log message, which is confusing and I end up getting same problem with unable to connect to db Can you help me to find what's wrong, seems like patch as part of builder phase not applied correctly? With more digging and logging I did it seems smth wrong with the final changes in the image
When I try to run it seems there's still mysql part in it
2024-07-10 15:21:46 yarn run v1.22.19
2024-07-10 15:21:46 $ npm-run-all check-db update-tracker start-server
2024-07-10 15:21:47 $ node scripts/check-db.js
2024-07-10 15:21:47 ✓ DATABASE_URL is defined.
2024-07-10 15:21:47 ✗ Unable to connect to the database: error: Error validating datasource `db`: the URL must start with the protocol `mysql://`.
2024-07-10 15:21:47 --> schema.prisma:7
2024-07-10 15:21:47 |
2024-07-10 15:21:47 6 | provider = "mysql"
2024-07-10 15:21:47 7 | url = env("DATABASE_URL")
docker-compose.yml
services:
umami:
image: moookino/umami
ports:
- "3000:3000"
environment:
DATABASE_URL: 'file:/prisma/database.db'
DATABASE_TYPE: sqlite
APP_SECRET: replace-me-with-a-random-string
restart: unless-stopped
# healthcheck:
# test: ["CMD-SHELL", "curl http://localhost:3000/api/heartbeat"]
# interval: 5s
# timeout: 5s
# retries: 5
volumes:
- ./db/database.db:/prisma/database.db
# volumes:
# umami-db-data:
Dockerfile
FROM node:18-alpine AS deps
RUN apk add git
RUN git clone --depth 1 --single-branch --branch master https://github.com/mikecao/umami.git /app
WORKDIR /app
RUN yarn install --frozen-lockfile
###
FROM node:18-alpine AS builder
RUN apk add git
RUN apk add patch
# This way the pull should not be cached
ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache
RUN git clone --depth 1 --single-branch --branch master https://github.com/mikecao/umami.git /app
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ADD https://raw.githubusercontent.com/Maxime-J/umami-sqlite/main/2.12.1.patch /app
USER root
WORKDIR /app
RUN chmod +x /app/2.12.1.patch
RUN patch -p1 < /app/2.12.1.patch
ENV DATABASE_TYPE sqlite
ENV BASE_PATH ''
ENV NEXT_TELEMETRY_DISABLED 1
RUN yarn build-docker
###
# Production image, copy all the files and run next
FROM node:18-alpine AS runner
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN yarn add npm-run-all dotenv prisma
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js .
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/scripts ./scripts
# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD ["yarn", "start-docker"]
Actually I found a missed copy paste, which I updated in initial message, so it could be used by someone willing to repeat same steps, but I'm still stuck with next step of writing to the DB
yarn run v1.22.19
$ npm-run-all check-db update-tracker start-server
$ node scripts/check-db.js
✓ DATABASE_URL is defined.
✓ Database connection successful.
Error: SQLite database error
attempt to write a readonly database
0: sql_schema_connector::sql_migration_persistence::initialize
with namespaces=None
at schema-engine/connectors/sql-schema-connector/src/sql_migration_persistence.rs:14
1: schema_core::state::ApplyMigrations
at schema-engine/core/src/state.rs:226
✗ Command failed: prisma migrate deploy
Error: SQLite database error
attempt to write a readonly database
0: sql_schema_connector::sql_migration_persistence::initialize
with namespaces=None
at schema-engine/connectors/sql-schema-connector/src/sql_migration_persistence.rs:14
1: schema_core::state::ApplyMigrations
at schema-engine/core/src/state.rs:226
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
ERROR: "check-db" exited with 1.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Hi @moookino, That was obviously the wrong DATABASE_TYPE for the first error you had. Now it's a permission error, maybe caused by the single database file you have as a volume.
I suggest trying with a whole specific folder:
[...]
environment:
DATABASE_URL: 'file:/umami-db/database.db'
[...]
volumes:
- ./db:/umami-db
I will release a new version, feel free to get back if you are still trying to make it work.
I did figure this part out, but thanks anyway, closing 🙂