Skip to content

Chore: rename references to test projects, support self-hosted local deploys on macOS #2061

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ docs
examples
out
references
test-projects

CHANGESETS.md
CONTRIBUTING.md
Expand Down
33 changes: 15 additions & 18 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ branch are tagged into a release periodically.
- [Node.js](https://nodejs.org/en) version 20.11.1
- [pnpm package manager](https://pnpm.io/installation) version 8.15.5
- [Docker](https://www.docker.com/get-started/)
- [protobuf](https://github.com/protocolbuffers/protobuf)

### Setup

Expand Down Expand Up @@ -62,15 +61,13 @@ branch are tagged into a release periodically.
pnpm run docker
```

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.

9. Migrate the database
```
pnpm run db:migrate
```
10. Build the server app
10. Build everything
```
pnpm run build --filter webapp
pnpm run build --filter webapp && pnpm run build --filter trigger.dev && pnpm run build --filter @trigger.dev/sdk
```
11. Run the app. See the section below.

Expand All @@ -88,7 +85,7 @@ branch are tagged into a release periodically.

## Manual testing using v3-catalog

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).
We use the `<root>/test-projects/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).

### First-time setup

Expand All @@ -109,10 +106,10 @@ pnpm run build --filter trigger.dev
pnpm i
```

5. Change into the `<root>/references/v3-catalog` directory and authorize the CLI to the local server:
5. Change into the `<root>/test-projects/v3-catalog` directory and authorize the CLI to the local server:

```sh
cd references/v3-catalog
cd test-projects/v3-catalog
cp .env.example .env
pnpm exec trigger login -a http://localhost:3030
```
Expand All @@ -122,7 +119,7 @@ This will open a new browser window and authorize the CLI against your local use
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:

```sh
cd references/v3-catalog
cd test-projects/v3-catalog
pnpm exec trigger login -a http://localhost:3030 --profile local
# later when you run the dev or deploy command:
pnpm exec trigger dev --profile local
Expand All @@ -141,7 +138,7 @@ The following steps should be followed any time you start working on a new featu
pnpm run dev --filter trigger.dev --filter "@trigger.dev/*"
```

3. Open another terminal window, and change into the `<root>/references/v3-catalog` directory.
3. Open another terminal window, and change into the `<root>/test-projects/v3-catalog` directory.

4. You'll need to run the following commands to setup prisma and migrate the database:

Expand All @@ -153,22 +150,22 @@ pnpm run generate:prisma
5. Run the `dev` command, which will register all the local tasks with the platform and allow you to start testing task execution:

```sh
# in <root>/references/v3-catalog
# in <root>/test-projects/v3-catalog
pnpm exec trigger dev
```

If you want additional debug logging, you can use the `--log-level debug` flag:

```sh
# in <root>/references/v3-catalog
# in <root>/test-projects/v3-catalog
pnpm exec trigger dev --log-level debug
```

6. 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.

7. Navigate to the `v3-catalog` project in your local dashboard at localhost:3030 and you should see the list of tasks.

8. 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.
8. 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 `/test-projects/v3-catalog/src/trigger` folder. Many of them accept an empty payload.

9. Feel free to add additional files in `v3-catalog/src/trigger` to test out specific aspects of the system, or add in edge cases.

Expand All @@ -180,14 +177,14 @@ To run the end-to-end tests, follow the steps below:

```sh
cp ./.env.example ./.env
cp ./references/nextjs-test/.env.example ./references/nextjs-test/.env.local
cp ./test-projects/nextjs-test/.env.example ./test-projects/nextjs-test/.env.local
```

2. Set up dependencies

```sh
# Build packages
pnpm run build --filter @references/nextjs-test^...
pnpm run build --filter @test-projects/nextjs-test^...
pnpm --filter @trigger.dev/database generate

# Move trigger-cli bin to correct place
Expand Down Expand Up @@ -251,9 +248,9 @@ This executes the migrations against your database and applies changes to the da

## Add sample jobs

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

1. `cd` into `references/job-catalog`
1. `cd` into `test-projects/job-catalog`
2. Create a `.env` file with the following content,
replacing `<TRIGGER_DEV_API_KEY>` with an actual key:

Expand All @@ -277,7 +274,7 @@ This will open up a local server using `express` on port 8080. Then in a new ter
pnpm run dev:trigger
```

See the [Job Catalog](./references/job-catalog/README.md) file for more.
See the [Job Catalog](./test-projects/job-catalog/README.md) file for more.

4. Navigate to your trigger.dev instance ([http://localhost:3030](http://localhost:3030/)), to see the jobs.
You can use the test feature to trigger them.
Expand Down
2 changes: 1 addition & 1 deletion ai/references/repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ This is a pnpm 8.15.5 monorepo that uses turborepo @turbo.json. The following wo

## References

- <root>/references/\* are test workspaces that we use to write and test the system. Not quite e2e tests or automated, but just a useful place to help develop new features
- <root>/test-projects/\* are test workspaces that we use to write and test the system. Not quite e2e tests or automated, but just a useful place to help develop new features

## Other

Expand Down
2 changes: 1 addition & 1 deletion apps/supervisor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ TRIGGER_WORKER_TOKEN=tr_wgt_...
pnpm dev
```

4. Build CLI, then deploy a reference project
4. Build CLI, then deploy a test project

```sh
pnpm exec trigger deploy --self-hosted
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/routes/api.v1.projects.$projectRef.$env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
const result: GetProjectEnvResponse = {
apiKey: runtimeEnv.apiKey,
name: project.name,
apiUrl: processEnv.APP_ORIGIN,
apiUrl: processEnv.API_ORIGIN ?? processEnv.APP_ORIGIN,
projectId: project.id,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/cli-v3/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cd packages/cli-v3
pnpm run dev
```

2. Test the local CLI using the job-catalogs located in the `/references` directory
2. Test the local CLI using the job-catalogs located in the `/test-projects` directory

```sh
pnpm i
Expand Down
12 changes: 11 additions & 1 deletion packages/cli-v3/src/deploy/buildImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async function selfHostedBuildImage(
"--build-arg",
`TRIGGER_PROJECT_REF=${options.projectRef}`,
"--build-arg",
`TRIGGER_API_URL=${options.apiUrl}`,
`TRIGGER_API_URL=${normalizeApiUrlForBuild(options.apiUrl)}`,
"--build-arg",
`TRIGGER_SECRET_KEY=${options.apiKey}`,
...(buildArgs || []),
Expand Down Expand Up @@ -723,3 +723,13 @@ ENTRYPOINT [ "dumb-init", "node", "${options.entrypoint}" ]
CMD []
`;
}

// If apiUrl is something like http://localhost:3030, AND we are on macOS, we need to convert it to http://host.docker.internal:3030
// this way the indexing will work because the docker image can reach the local server
function normalizeApiUrlForBuild(apiUrl: string) {
if (process.platform === "darwin") {
return apiUrl.replace("localhost", "host.docker.internal");
}

return apiUrl;
}
Loading