Skip to content

Commit 82e7b4c

Browse files
committed
Squashed commit of the following:
commit 64862db Author: Niels <[email protected]> Date: Thu Sep 19 16:25:17 2024 +0200 Update dotEnv.ts to ignore OTEL_EXPORTER_OTLP_ENDPOINT as well (#1307) * Update dotEnv.ts * Create four-buttons-run.md --------- Co-authored-by: Eric Allam <[email protected]> commit c65d482 Author: Thibaut Cuchet <[email protected]> Date: Thu Sep 19 16:22:57 2024 +0200 Feat: Extension puppeteer (#1323) * feat: add puppeteer extension * chore: update package and config * feat: add puppeteer task * Create little-donkeys-protect.md --------- Co-authored-by: Eric Allam <[email protected]> commit b4be736 Author: Eric Allam <[email protected]> Date: Thu Sep 19 15:21:03 2024 +0100 prismaExtension fixes for #1325 and #1327
1 parent d20c346 commit 82e7b4c

File tree

23 files changed

+608
-26
lines changed

23 files changed

+608
-26
lines changed

.changeset/four-buttons-run.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
Ignore OTEL_EXPORTER_OTLP_ENDPOINT environment variable from `.env` files, to prevent the internal OTEL_EXPORTER_OTLP_ENDPOINT being overwritten with a user-supplied value.

.changeset/friendly-brooms-cry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"trigger.dev": patch
3+
"@trigger.dev/build": patch
4+
---
5+
6+
prismaExtension fixes for #1325 and #1327

.changeset/little-donkeys-protect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/build": patch
3+
---
4+
5+
Feat: puppeteer build extension

.vscode/launch.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
"cwd": "${workspaceFolder}/references/v3-catalog",
3737
"sourceMaps": true
3838
},
39+
{
40+
"type": "node-terminal",
41+
"request": "launch",
42+
"name": "Debug prisma-catalog deploy CLI",
43+
"command": "pnpm exec trigger deploy --self-hosted --load-image",
44+
"cwd": "${workspaceFolder}/references/prisma-catalog",
45+
"sourceMaps": true
46+
},
3947
{
4048
"type": "node-terminal",
4149
"request": "launch",

docs/config/config-file.mdx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,9 @@ export default defineConfig({
444444
```
445445

446446
<Note>
447-
The `prismaExtension` will inject the `DATABASE_URL` environment variable into the build process
448-
when running the `deploy` command. This means the CLI needs to have `process.env.DATABASE_URL` set
449-
at the time of calling the `deploy` command. You can do this via a `.env` file and passing the
450-
`--env-file .env` option to the deploy command or via shell environment variables. This goes for direct database URLs as well.
447+
The `prismaExtension` will inject the `DATABASE_URL` environment variable into the build process. Learn more about setting environment variables for deploying in our [Environment Variables](/deploy-environment-variables) guide.
451448

452-
These environment variables are only used during the build process and are not embedded in the final image.
449+
These environment variables are only used during the build process and are not embedded in the final container image.
453450

454451
</Note>
455452

packages/build/package.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"./extensions/core": "./src/extensions/core.ts",
2828
"./extensions/prisma": "./src/extensions/prisma.ts",
2929
"./extensions/audioWaveform": "./src/extensions/audioWaveform.ts",
30-
"./extensions/typescript": "./src/extensions/typescript.ts"
30+
"./extensions/typescript": "./src/extensions/typescript.ts",
31+
"./extensions/puppeteer": "./src/extensions/puppeteer.ts"
3132
},
3233
"sourceDialects": [
3334
"@triggerdotdev/source"
@@ -49,6 +50,9 @@
4950
],
5051
"extensions/typescript": [
5152
"dist/commonjs/extensions/typescript.d.ts"
53+
],
54+
"extensions/puppeteer": [
55+
"dist/commonjs/extensions/puppeteer.d.ts"
5256
]
5357
}
5458
},
@@ -145,6 +149,17 @@
145149
"types": "./dist/commonjs/extensions/typescript.d.ts",
146150
"default": "./dist/commonjs/extensions/typescript.js"
147151
}
152+
},
153+
"./extensions/puppeteer": {
154+
"import": {
155+
"@triggerdotdev/source": "./src/extensions/puppeteer.ts",
156+
"types": "./dist/esm/extensions/puppeteer.d.ts",
157+
"default": "./dist/esm/extensions/puppeteer.js"
158+
},
159+
"require": {
160+
"types": "./dist/commonjs/extensions/puppeteer.d.ts",
161+
"default": "./dist/commonjs/extensions/puppeteer.js"
162+
}
148163
}
149164
},
150165
"main": "./dist/commonjs/index.js",

packages/build/src/extensions/prisma.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,9 @@ export class PrismaExtension implements BuildExtension {
127127
if (this.options.typedSql) {
128128
generatorFlags.push(`--sql`);
129129

130-
const schemaDir = dirname(this._resolvedSchemaPath);
131-
const prismaDir = dirname(schemaDir);
130+
const prismaDir = usingSchemaFolder
131+
? dirname(dirname(this._resolvedSchemaPath))
132+
: dirname(this._resolvedSchemaPath);
132133

133134
context.logger.debug(`Using typedSql`);
134135

@@ -226,15 +227,29 @@ export class PrismaExtension implements BuildExtension {
226227
commands.push(
227228
`${binaryForRuntime(manifest.runtime)} node_modules/prisma/build/index.js migrate deploy`
228229
);
230+
}
229231

230-
env.DATABASE_URL = manifest.deploy.env?.DATABASE_URL;
232+
env.DATABASE_URL = manifest.deploy.env?.DATABASE_URL;
231233

232-
if (this.options.directUrlEnvVarName) {
233-
env[this.options.directUrlEnvVarName] =
234-
manifest.deploy.env?.[this.options.directUrlEnvVarName];
235-
} else {
236-
env.DIRECT_URL = manifest.deploy.env?.DIRECT_URL;
234+
if (this.options.directUrlEnvVarName) {
235+
env[this.options.directUrlEnvVarName] =
236+
manifest.deploy.env?.[this.options.directUrlEnvVarName] ??
237+
process.env[this.options.directUrlEnvVarName];
238+
239+
if (!env[this.options.directUrlEnvVarName]) {
240+
context.logger.warn(
241+
`prismaExtension could not resolve the ${this.options.directUrlEnvVarName} environment variable. Make sure you add it to your environment variables or provide it as an environment variable to the deploy CLI command. See our docs for more info: https://trigger.dev/docs/deploy-environment-variables`
242+
);
237243
}
244+
} else {
245+
env.DIRECT_URL = manifest.deploy.env?.DIRECT_URL;
246+
env.DIRECT_DATABASE_URL = manifest.deploy.env?.DIRECT_DATABASE_URL;
247+
}
248+
249+
if (!env.DATABASE_URL) {
250+
context.logger.warn(
251+
`prismaExtension could not resolve the DATABASE_URL environment variable. Make sure you add it to your environment variables. See our docs for more info: https://trigger.dev/docs/deploy-environment-variables`
252+
);
238253
}
239254

240255
context.logger.debug(`Adding the prisma layer with the following commands`, {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { BuildManifest } from "@trigger.dev/core/v3";
2+
import { BuildContext, BuildExtension } from "@trigger.dev/core/v3/build";
3+
4+
export function puppeteer() {
5+
return new PuppeteerExtension();
6+
}
7+
8+
class PuppeteerExtension implements BuildExtension {
9+
public readonly name = "PuppeteerExtension";
10+
11+
async onBuildComplete(context: BuildContext, manifest: BuildManifest) {
12+
if (context.target === "dev") {
13+
return;
14+
}
15+
16+
context.logger.debug(`Adding ${this.name} to the build`);
17+
18+
const instructions = [
19+
`RUN apt-get update && apt-get install curl gnupg -y \
20+
&& curl --location --silent https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
21+
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
22+
&& apt-get update \
23+
&& apt-get install google-chrome-stable -y --no-install-recommends \
24+
&& rm -rf /var/lib/apt/lists/*`,
25+
];
26+
27+
context.addLayer({
28+
id: "puppeteer",
29+
image: {
30+
instructions,
31+
},
32+
});
33+
}
34+
}

packages/cli-v3/src/deploy/buildImage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ COPY --chown=bun:bun . .
492492
493493
${postInstallCommands}
494494
495-
from build as indexer
495+
FROM build AS indexer
496496
497497
USER bun
498498
WORKDIR /app
@@ -601,7 +601,7 @@ COPY --chown=node:node . .
601601
602602
${postInstallCommands}
603603
604-
from build as indexer
604+
FROM build AS indexer
605605
606606
USER node
607607
WORKDIR /app

packages/cli-v3/src/utilities/dotEnv.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function resolveDotEnvVars(cwd?: string, envFile?: string) {
2121
// remove TRIGGER_API_URL and TRIGGER_SECRET_KEY, since those should be coming from the worker
2222
delete result.TRIGGER_API_URL;
2323
delete result.TRIGGER_SECRET_KEY;
24+
delete result.OTEL_EXPORTER_OTLP_ENDPOINT;
2425

2526
return result;
2627
}

0 commit comments

Comments
 (0)