Prisma migrate deploy docker optimization/improvement

Heyo, I am currently creating an app with t3 app and using prisma and postgres for the database. Also I'm using the standalone configuration and bundling a postgres server with the application using docker. My Question: How can i run prisma db migrate deploy on the running server in the best way? The docs say that you should run it in a ci/cd pipeline after the server is deployed. That would kinda work but for now I just have a vps which i want to deploy to (possible with github actions but then i have to expose the db, at least locally). The option I have chosen currently is to include a startup script that runs npx prisma migrate deploy before the server starts. This works but by running npx prisma I install the prisma package which makes my container image around 200mb larger that without it. Is this a passible solution or is there a way to solve this situation better? My entrypoint.sh looks like this:
#!/bin/bash

npx --yes prisma migrate deploy
exec node /app/server.js "@"
#!/bin/bash

npx --yes prisma migrate deploy
exec node /app/server.js "@"
My Dockerfile:
... default t3 docker file according to https://create.t3.gg/en/deployment/docker
##### RUNNER

FROM --platform=linux/amd64 node:20-slim AS runner
WORKDIR /app

ENV NODE_ENV production

# ENV NEXT_TELEMETRY_DISABLED 1

RUN apt-get update && apt-get install openssl -y && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/entrypoint.sh ./entrypoint.sh

# Run npx prisma to download the cli client to use in the entrypoint script
RUN npx prisma

EXPOSE 3000
ENV PORT 3000

ENTRYPOINT [ "/app/entrypoint.sh" ]
... default t3 docker file according to https://create.t3.gg/en/deployment/docker
##### RUNNER

FROM --platform=linux/amd64 node:20-slim AS runner
WORKDIR /app

ENV NODE_ENV production

# ENV NEXT_TELEMETRY_DISABLED 1

RUN apt-get update && apt-get install openssl -y && rm -rf /var/lib/apt/lists/*

COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json

COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/entrypoint.sh ./entrypoint.sh

# Run npx prisma to download the cli client to use in the entrypoint script
RUN npx prisma

EXPOSE 3000
ENV PORT 3000

ENTRYPOINT [ "/app/entrypoint.sh" ]
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server