mirror of
https://github.com/nicetry247/offlineacademy.git
synced 2026-07-26 11:58:44 +00:00
fix: initialize sqlite schema on docker startup
This commit is contained in:
+11
-5
@@ -50,7 +50,7 @@ ENV PORT=6767
|
||||
ENV HOSTNAME=0.0.0.0
|
||||
|
||||
RUN apt-get update \
|
||||
&& apt-get install -y --no-install-recommends openssl ca-certificates \
|
||||
&& apt-get install -y --no-install-recommends openssl ca-certificates gosu \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& groupadd --system --gid 1001 nodejs \
|
||||
&& useradd --system --uid 1001 --gid nodejs nextjs
|
||||
@@ -61,12 +61,18 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
|
||||
|
||||
# Runtime writable folders. Users can bind-mount these from anywhere.
|
||||
RUN mkdir -p /app/My_Courses /app/prisma \
|
||||
&& chown -R nextjs:nodejs /app/My_Courses /app/prisma
|
||||
# Keep Prisma CLI available at runtime so fresh bind-mounted SQLite databases
|
||||
# can be initialized automatically before the server starts.
|
||||
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
|
||||
COPY --from=deps --chown=nextjs:nodejs /app/package.json ./package.json
|
||||
COPY --from=deps --chown=nextjs:nodejs /app/package-lock.json ./package-lock.json
|
||||
|
||||
USER nextjs
|
||||
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh \
|
||||
&& mkdir -p /app/My_Courses /app/prisma \
|
||||
&& chown -R nextjs:nodejs /app/My_Courses /app/prisma
|
||||
|
||||
EXPOSE 6767
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
CMD ["node", "server.js"]
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
# Ensure bind-mounted runtime folders exist.
|
||||
mkdir -p /app/My_Courses /app/prisma
|
||||
|
||||
# If the container starts as root, make common bind mounts writable by the app user.
|
||||
# This helps when users create ./prisma/dev.db or ./My_Courses on the host first.
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
chown -R nextjs:nodejs /app/My_Courses /app/prisma 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# A fresh Docker deployment often bind-mounts an empty SQLite file at /app/prisma/dev.db.
|
||||
# Initialize/update the Prisma schema before the Next.js server starts.
|
||||
if [ -n "${DATABASE_URL:-}" ]; then
|
||||
echo "Initializing SQLite schema with Prisma..."
|
||||
gosu nextjs:nodejs ./node_modules/.bin/prisma db push --schema=/app/prisma/schema.prisma --skip-generate
|
||||
fi
|
||||
|
||||
exec gosu nextjs:nodejs "$@"
|
||||
Reference in New Issue
Block a user