Skip to content

Build fails with TypedSQL enabled but prisma migrations disabled #1327

Closed

Description

@gorbak25

Provide environment information

  System:
    OS: Linux 6.10 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
    Memory: 115.65 GB / 125.68 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.8.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 10.8.2 - /usr/bin/npm

Describe the bug

After applying the workaround from #1325, that is copying the sql folder into the location expected by the cli npx trigger.dev@latest deploy still fails with

└  Error: Error building image. Full build logs have been saved to /tmp/trigger-mQAkpy/build-jvbf0cg5.log
#17 [build 6/6] RUN node node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma --sql
#17 0.546 Prisma schema loaded from prisma/schema.prisma
#17 0.561 Error: Prisma schema validation - (get-config wasm)
#17 0.561 Error code: P1012
#17 0.561 error: Environment variable not found: DATABASE_URL.
#17 0.561   -->  prisma/schema.prisma:8
#17 0.561    |
#17 0.561  7 |   provider = "postgresql"
#17 0.561  8 |   url      = env("DATABASE_URL")
#17 0.561    |
#17 0.561
#17 0.561 Validation Error Count: 1
#17 0.561 [Context: getConfig]
#17 0.561
#17 0.561 Prisma CLI Version : 5.19.1
#17 ERROR: process "/bin/sh -c node node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma --sql" did not complete successfully: exit code: 1
------
> [build 6/6] RUN node node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma --sql:
#17 0.561   -->  prisma/schema.prisma:8
#17 0.561    |
#17 0.561  7 |   provider = "postgresql"
#17 0.561  8 |   url      = env("DATABASE_URL")
#17 0.561    |
#17 0.561
#17 0.561 Validation Error Count: 1
#17 0.561 [Context: getConfig]
#17 0.561
#17 0.561 Prisma CLI Version : 5.19.1
------
Error: failed to solve: process "/bin/sh -c node node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma --sql" did not complete successfully: exit code: 1

This is expected as prisma needs to connect to a live database during the build when TypedSQL is enabled. By exposing the secrets to the build the resulting container could leak them, how does the build system handle the secrets?

Reproduction repo

N/A

To reproduce

Try deploying a project with prisma and TypedSQL enabled.

Additional information

No response

Activity

  1. ericallam commented on Sep 19, 2024

    @ericallam
    Member

    Very good question! We run the prisma generate step inside the "build" stage of the container, and inject the DATABASE_URL env var via a build argument, just to that stage. The final stage of the container then will not have that DATABASE_URL env var embedded inside it. We don't embed any sensitive env vars to final stage. You can see for yourself here:

  2. gorbak25 commented on Sep 19, 2024

    @gorbak25
    Author

    @ericallam The problem is that this environment variable is only set when migrations are enabled in the prisma extension:

    env.DATABASE_URL = manifest.deploy.env?.DATABASE_URL;

    With the following configuration

          prismaExtension({
            schema: "prisma/schema.prisma",
            directUrlEnvVarName: "DATABASE_URL",
            typedSql: true,
            migrate: false,
          }),
    

    DATABASE_URL will never get set during the build. I've fixed this issue by enabling migrations.

  3. changed the title [-] Build fails with TypedSQL enabled due to missing environment variables[/-] [+] Build fails with TypedSQL enabled but prisma migrations disabled[/+] on Sep 19, 2024
  4. gorbak25 commented on Sep 19, 2024

    @gorbak25
    Author

    I've changed the title of this issue to better reflect the problem

  5. added a commit that references this issue on Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions