Skip to content

Commit c9ebe7f

Browse files
committed
Update contributing guide for local v3 development
1 parent f4f87ad commit c9ebe7f

3 files changed

Lines changed: 92 additions & 91 deletions

File tree

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ REMIX_APP_PORT=3030
1111
APP_ENV=development
1212
APP_ORIGIN=http://localhost:3030
1313
NODE_ENV=development
14+
CLOUD_ENV=development
15+
V3_ENABLED=true
1416

1517
# Redis is used for the v3 queuing and v2 concurrency control
1618
REDIS_HOST="localhost"
1719
REDIS_PORT="6379"
1820
REDIS_TLS_DISABLED="true"
1921

22+
DEV_OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:3030/otel"
23+
DEV_OTEL_BATCH_PROCESSING_ENABLED="0"
24+
2025
# OPTIONAL VARIABLES
2126
# This is used for validating emails that are allowed to log in. Every email that do not match this regex will be rejected.
2227
# WHITELISTED_EMAILS="authorized@yahoo\.com|authorized@gmail\.com"

CONTRIBUTING.md

Lines changed: 87 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ Thank you for helping us make Trigger.dev even better! 🤩
1010

1111
The development branch is `main`. This is the branch that all pull
1212
requests should be made against. The changes on the `main`
13-
branch are tagged into a release monthly.
13+
branch are tagged into a release periodically.
1414

1515
### Prerequisites
1616

17-
- [Node.js](https://nodejs.org/en) version >=16.x
18-
- [pnpm package manager](https://pnpm.io/installation) version 7
17+
- [Node.js](https://nodejs.org/en) version 20.11.1
18+
- [pnpm package manager](https://pnpm.io/installation) version 8.15.5
1919
- [Docker](https://www.docker.com/get-started/)
2020

2121
### Setup
@@ -33,15 +33,19 @@ branch are tagged into a release monthly.
3333
```
3434
cd trigger.dev
3535
```
36-
3. Install the required packages using pnpm.
36+
3. Ensure you are on the correct version of Node.js (20.11.1). If you are using `nvm`, there is an `.nvmrc` file that will automatically select the correct version of Node.js when you navigate to the repository.
37+
38+
4. Run `corepack enable` to use the correct version of pnpm (`8.15.5`) as specified in the root `package.json` file.
39+
40+
5. Install the required packages using pnpm.
3741
```
3842
pnpm i
3943
```
40-
4. Create your `.env` file
44+
6. Create your `.env` file
4145
```
4246
cp .env.example .env
4347
```
44-
5. Open it and generate a new value for `ENCRYPTION_KEY`:
48+
7. Open it and generate a new value for `ENCRYPTION_KEY`:
4549

4650
`ENCRYPTION_KEY` is used to two-way encrypt OAuth access tokens and so you'll probably want to actually generate a unique value, and it must be a random 16 byte hex string. You can generate one with the following command:
4751

@@ -51,27 +55,23 @@ branch are tagged into a release monthly.
5155

5256
Feel free to update `SESSION_SECRET` and `MAGIC_LINK_SECRET` as well using the same method.
5357

54-
6. Start Docker. This starts the required services like Postgres. If this is your first time using Docker, consider going through this [guide](DOCKER_INSTALLATION.md)
58+
8. Start Docker. This starts the required services like Postgres & Redis. If this is your first time using Docker, consider going through this [guide](DOCKER_INSTALLATION.md)
5559

5660
```
5761
pnpm run docker
5862
```
5963

6064
This will also start and run a local instance of [pgAdmin](https://www.pgadmin.org/) on [localhost:5480](http://localhost:5480), preconfigured with email `admin@example.com` and pwd `admin`. Then use `postgres` as the password to the Trigger.dev server.
6165

62-
7. Migrate the database
66+
9. Migrate the database
6367
```
6468
pnpm run db:migrate
6569
```
66-
8. Build the app
67-
```
68-
pnpm run build --filter webapp
69-
```
70-
9. Run the seed script
71-
```
72-
pnpm run db:seed
73-
```
74-
10. Run the app. See the section below.
70+
10. Build the server app
71+
```
72+
pnpm run build --filter webapp
73+
```
74+
11. Run the app. See the section below.
7575
7676
## Running
7777
@@ -83,99 +83,92 @@ branch are tagged into a release monthly.
8383
8484
It should run on port `3030`: [http://localhost:3030](http://localhost:3030/)
8585
86-
2. Once the app is running click the magic link button and enter your email.
87-
3. Check your terminal, the magic link email should have printed out as following:
86+
2. Once the app is running click the magic link button and enter your email. You will automatically be logged in, since you are running locally. Create an Org and your first project in the dashboard.
8887
89-
```sh
90-
webapp:dev: Log in to Trigger.dev
91-
webapp:dev:
92-
webapp:dev: Click here to log in with this magic link
93-
webapp:dev: [http://localhost:3030/magic?token=U2FsdGVkX18OvB0JxgaswTLCSbaRz%2FY82TN0EZWhSzFyZYwgG%2BIzKVTkeiaOtWfotPw7F8RwFzCHh53aBpMEu%2B%2B%2FItb%2FcJYh89MSjc3Pz92bevoEjqxSQ%2Ff%2BZbks09JOpqlBbYC3FzGWC8vuSVFBlxqLXxteSDLthZSUaC%2BS2LaA%2BJgp%2BLO7hgjAaC2lXbCHrM7MTgTdXOFt7i0Dvvuwz6%2BWY25RnfomZOPqDsyH0xz8Q2rzPTz0Xu53WSXrZ1hd]
94-
webapp:dev:
95-
webapp:dev: If you didn't try to log in, you can safely ignore this email.
96-
```
88+
## Manual testing using v3-catalog
9789
98-
Paste the magic link shown in your terminal into your browser to login.
90+
We use the `<root>/references/v3-catalog` subdirectory as a staging ground for testing changes to the SDK (`@trigger.dev/sdk` at `<root>/packages/trigger-sdk`), the Core package (`@trigger.dev/core` at `<root>packages/core`), the CLI (`trigger.dev` at `<root>/packages/cli-v3`) and the platform (The remix app at `<root>/apps/webapp`). The instructions below will get you started on using the `v3-catalog` for local development of Trigger.dev (v3).
9991
100-
## Adding and running migrations
92+
### First-time setup
10193
102-
1. Modify packages/database/prisma/schema.prisma file
103-
2. Change directory to the packages/database folder
104-
```sh
105-
cd packages/database
106-
```
107-
3. Generate the Prisma client
94+
First, make sure you are running the webapp according to the instructions above. Then:
10895
109-
```sh
110-
pnpm run generate
111-
```
96+
1. In Postgres go to the "Organizations" table and on your org set the `v3Enabled` column to `true`.
11297
113-
The above updates the prisma client generated into node_modules/.prisma/client folder. This helps with typing of relevant prisma models. It ensures typescript
114-
recognizes fields added or removed from a model and type-checks appropriately.
98+
2. Visit http://localhost:3030 in your browser and create a new V3 project called "v3-catalog". If you don't see an option for V3, you haven't set the `v3Enabled` flag to true.
11599
116-
4. Create and apply the migrations
100+
3. In Postgres go to the "Projects" table and for the project you create change the `externalRef` to `yubjwjsfkxnylobaqvqz`.
117101
118-
```
119-
pnpm run db:migrate:dev
120-
```
102+
4. Build the CLI
121103
122-
This creates a migration file and executes the migrations against your database and applies changes to the database schema(s)
104+
```sh
105+
pnpm run build --filter trigger.dev
106+
```
123107

124-
5. Commit generated migrations as well as changes to the schema.prisma file
125-
6. If you're using VSCode you may need to restart the Typescript server in the webapp to get updated type inference. Open a TypeScript file, then open the Command Palette (View > Command Palette) and run `TypeScript: Restart TS server`.
108+
5. Change into the `<root>/references/v3-catalog` directory and authorize the CLI to the local server:
126109

127-
## Testing CLI changes
110+
```sh
111+
cd references/v3-catalog
112+
pnpm exec triggerdev login -a http://localhost:3030
113+
```
128114

129-
To test CLI changes, follow the steps below:
115+
This will open a new browser window and authorize the CLI against your local user account.
130116

131-
1. Build the CLI and watch for changes
117+
You can optionally pass a `--profile` flag to the `login` command, which will allow you to use the CLI with separate accounts/servers. We suggest using a profile called `local` for your local development:
132118

133119
```sh
134-
cd packages/cli
135-
pnpm run dev
120+
cd references/v3-catalog
121+
pnpm exec triggerdev login -a http://localhost:3030 --profile local
122+
# later when you run the dev or deploy command:
123+
pnpm exec triggerdev dev --profile local
124+
pnpm exec triggerdev deploy --profile local
136125
```
137126

138-
2. Open a new Terminal window and run the webapp locally and then create a new project in the dashboard. Copy out the dev API key.
127+
### Running
139128

140-
3. Create a new temporary Next.js app in references directory
129+
The following steps should be followed any time you start working on a new feature you want to test in v3:
141130

142-
```sh
143-
cd ./references
144-
pnpm create next-app@latest test-cli --ts --no-eslint --tailwind --app --src-dir --import-alias "@/*"
145-
```
131+
1. Make sure the webapp is running on localhost:3030
146132

147-
4. Then once that's finished, add the `@trigger.dev/cli` to the `devDependencies` of the newly created Next.js app's `package.json` file, like so:
133+
2. Open a terminal window and build the CLI and watch for changes
148134

149-
```json
150-
{
151-
// other package.json properties
152-
"devDependencies": { "@trigger.dev/cli": "workspace:*" }
153-
}
135+
```sh
136+
pnpm run dev --filter trigger.dev
154137
```
155138

156-
5. Back in the terminal, navigate into the reference, and initialize the CLI. When prompted, select `self-hosted` and enter `localhost:3030` if you are testing against the local instance of Trigger.dev, or you can just use the Trigger.dev cloud. When asked for an API key, use the key you copied earlier.
139+
2. Open a new terminal window, and anytime changes are made to the `@trigger.dev/core` package, you'll need to manually rebuild the CLI:
157140

158141
```sh
159-
cd ./test-cli
160-
pnpm i
161-
pnpm exec trigger-cli init
142+
pnpm run build --filter trigger.dev
162143
```
163144

164-
6. If you are just testing the `init` command, you can stop here. If you'd like to test the `dev` command, first start the Next.js app on port 3000:
145+
Note: You do not need to do the same for `@trigger.dev/sdk`, just core.
146+
147+
3. Open another terminal window, and change into the `<root>/references/v3-catalog` directory.
148+
149+
4. Run the `dev` command, which will register all the local tasks with the platform and allow you to start testing task execution:
165150

166151
```sh
167-
pnpm run dev
152+
# in <root>/references/v3-catalog
153+
pnpm exec triggerdev dev
168154
```
169155

170-
7. Open a new terminal window, and then run the `dev` command like so:
156+
If you want additional debug logging, you can use the `--log-level debug` flag:
171157

172158
```sh
173-
pnpm exec trigger-cli dev
159+
# in <root>/references/v3-catalog
160+
pnpm exec triggerdev dev --log-level debug
174161
```
175162

176-
8. Please remember to delete the temporary project you created after you've tested the changes, and before you raise a PR.
163+
5. If you make any changes in the CLI/Core/SDK, you'll need to `CTRL+C` to exit the `dev` command and restart it to pickup changes. Any changes to the files inside of the `v3-catalog/src/trigger` dir will automatically be rebuilt by the `dev` command.
164+
165+
6. Navigate to the `v3-catalog` project in your local dashboard at localhost:3030 and you should see the list of tasks.
166+
167+
7. Go to the "Test" page in the sidebar and select a task. Then enter a payload and click "Run test". You can tell what the payloads should be by looking at the relevant task file inside the `/references/v3-catalog/src/trigger` folder. Many of them accept an empty payload.
177168

178-
## Running end-to-end webapp tests
169+
8. Feel free to add additional files in `v3-catalog/src/trigger` to test out specific aspects of the system, or add in edge cases.
170+
171+
## Running end-to-end webapp tests (deprecated)
179172

180173
To run the end-to-end tests, follow the steps below:
181174

@@ -223,6 +216,26 @@ The end-to-end tests use a `setup` and `teardown` script to seed the database wi
223216
pnpm run db:studio
224217
```
225218

219+
## Adding and running migrations
220+
221+
1. Modify packages/database/prisma/schema.prisma file
222+
2. Change directory to the packages/database folder
223+
224+
```sh
225+
cd packages/database
226+
```
227+
228+
3. Create and apply the migrations
229+
230+
```
231+
pnpm run db:migrate:dev
232+
```
233+
234+
This creates a migration file and executes the migrations against your database and applies changes to the database schema(s)
235+
236+
4. Commit generated migrations as well as changes to the schema.prisma file
237+
5. If you're using VSCode you may need to restart the Typescript server in the webapp to get updated type inference. Open a TypeScript file, then open the Command Palette (View > Command Palette) and run `TypeScript: Restart TS server`.
238+
226239
## Add sample jobs
227240

228241
The [references/job-catalog](./references/job-catalog/) project defines simple jobs you can get started with.

docker/docker-compose.yml

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,3 @@ services:
5353
- app_network
5454
ports:
5555
- 6379:6379
56-
57-
otel-collector:
58-
container_name: otel-collector
59-
image: otel/opentelemetry-collector-contrib:latest
60-
restart: always
61-
command: ["--config", "/etc/otel-collector-config.yaml"]
62-
volumes:
63-
- ./otel-collector-config.yaml:/etc/otel-collector-config.yaml
64-
ports:
65-
- "55680:55680"
66-
- "55681:55681"
67-
- "4317:4317" # OTLP gRPC receiver
68-
- "4318:4318" # OTLP http receiver
69-
- "4319:4319" # OTLP internal http receiver
70-
environment:
71-
BASELIME_API_KEY: ${BASELIME_API_KEY}
72-
BASELIME_SERVICE: ${BASELIME_SERVICE}

0 commit comments

Comments
 (0)