Skip to content

Commit

Permalink
more attempts to run migrate in dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
webdevcody committed Jul 24, 2024
1 parent 2cf4b5b commit 1f78a5f
Show file tree
Hide file tree
Showing 7 changed files with 649 additions and 6 deletions.
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ ARG NEXT_PUBLIC_POSTHOG_KEY
ARG NEXT_PUBLIC_POSTHOG_HOST

RUN npm run build
RUN npm run db:migrate

FROM base AS runner
WORKDIR /app
Expand All @@ -55,16 +54,17 @@ RUN chown nextjs:nodejs .next

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/drizzle ./drizzle

USER nextjs

RUN cd drizzle && npm i

EXPOSE 3000

ENV PORT=3000

ARG HOSTNAME

# this is gross
RUN npm i drizzle-orm postgres @t3-oss/env-nextjs zod

CMD npm run db:migrate && node server.js
CMD ./run.sh
1 change: 1 addition & 0 deletions drizzle/migrate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
17 changes: 17 additions & 0 deletions drizzle/migrate/migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file is to get the migration to run in the Dockerfile right
// before the service runs.

import "dotenv/config";
import { drizzle } from "drizzle-orm/postgres-js";
import postgres from "postgres";
import { migrate } from "drizzle-orm/postgres-js/migrator";

const pg = postgres(process.env.DATABASE_URL!);
const database = drizzle(pg);

async function main() {
await migrate(database, { migrationsFolder: ".." });
await pg.end();
}

main();
Loading

0 comments on commit 1f78a5f

Please sign in to comment.