Skip to content
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

Capture and propagate env info (TRIGGER_ENV) for socket and container providers #1733

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Shahor
Copy link

@Shahor Shahor commented Feb 26, 2025

Fixes #1557

✅ Checklist

  • I have followed every step in the contributing guide
  • The PR title follows the convention.
  • I ran and tested the code works

Testing

Aside of automatic testing, I tried running this changeset in my local machine and while normal behaviour seems to be kept I didn't find a way to be sure my changes were indeed applied as I don't see the env vars being injected in a dev environment (outside of docker/kubernetes).

Since I didn't seen other related env vars (for example TRIGGER_ENV_ID) I assume it's expected and those vars only get injected in production-like infrastructures.

I am more than happy to perform more extended tests provided any one can point me in the right direction if my asumption is incorrect.

I started the discussion here: https://discord.com/channels/1066956501299777596/1316791509818937354/1344447567286501390


Changelog

Adding a new TRIGGER_ENV env var.


Screenshots

[Screenshots]

💯

Summary by CodeRabbit

  • New Features
    • Improved the handling of environment configuration across task execution components.
    • Now, environment details are captured and consistently passed through task coordination, Docker, and Kubernetes processes.
    • Task deployment processes now include additional environment context, providing enhanced operational insights and consistency.
    • Introduced the TRIGGER_ENV environment variable to enhance task execution context.

Copy link

changeset-bot bot commented Feb 26, 2025

🦋 Changeset detected

Latest commit: 9990b56

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
trigger.dev Patch
@trigger.dev/core Patch
@trigger.dev/build Patch
@trigger.dev/python Patch
@trigger.dev/sdk Patch
@internal/redis-worker Patch
@internal/zod-worker Patch
@trigger.dev/react-hooks Patch
@trigger.dev/rsc Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
references-nextjs-realtime Patch
@internal/testcontainers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

coderabbitai bot commented Feb 26, 2025

Walkthrough

This pull request introduces changes to capture and propagate environment information across multiple components. The updates add an "env" header extraction during socket connections, include the trigger environment as an argument for container creation in both Docker and Kubernetes providers, and update internal schemas and classes to support this new data. The changes are implemented without altering the existing interfaces or removing functionality.

Changes

File(s) Change Summary
apps/coordinator/src/index.ts
packages/cli-v3/.../deploy-run-controller.ts
Updated socket connection setup to extract and forward environment data. In the coordinator, a new call to setSocketDataFromHeader("env", "x-trigger-env") was added. In the ProdWorker class, a new env property is initialized and sent as header "x-trigger-env".
apps/docker-provider/src/index.ts
apps/kubernetes-provider/src/index.ts
Added support for passing the environment variable in container creation. The Docker provider now injects --env=TRIGGER_ENV=${opts.envType} into the command, while the Kubernetes provider adds an entry for TRIGGER_ENV in the container's environment array.
packages/core/.../messages.ts Extended the ProdWorkerSocketData schema with a new property env: z.string(), enabling the inclusion of environment information in the data structure.
.changeset/hungry-moles-do.md Added a new entry indicating a patch for the "trigger.dev" and "@trigger.dev/core" components, introducing the TRIGGER_ENV environment variable to task runs.

Sequence Diagram(s)

sequenceDiagram
    participant Worker as ProdWorker
    participant Coordinator as TaskCoordinator
    Worker->>Coordinator: Initiates socket connection with header "x-trigger-env"
    Coordinator-->>Worker: Calls setSocketDataFromHeader("env", "x-trigger-env") to capture env info
    Note over Worker,Coordinator: Environment info is now included in the socket data
Loading
sequenceDiagram
    participant TaskOps as TaskOperations
    participant Container as Container Engine
    TaskOps->>Container: Create container with env variable TRIGGER_ENV=opts.envType
    Container-->>TaskOps: Container initiated with environment variable set
Loading

Suggested reviewers

  • nicktrn

Poem

I hopped through code with joyful zest,
Adding "env" to every request,
Sockets and containers now share the tale,
With headers and schemas, they prevail,
A rabbit’s hop in code—moving systems ahead! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Shahor Shahor force-pushed the feat/add-trigger-env-to-runs branch from d3a1eb7 to 1a69772 Compare February 26, 2025 00:21
@Shahor Shahor force-pushed the feat/add-trigger-env-to-runs branch from 1a69772 to 244c79e Compare February 26, 2025 23:11
@Shahor Shahor marked this pull request as ready for review February 27, 2025 22:09
@Shahor Shahor changed the title Add TRIGGER_ENV env var to runs Add TRIGGER_ENV env var to runs @coderabbitai Feb 27, 2025
@coderabbitai coderabbitai bot changed the title Add TRIGGER_ENV env var to runs @coderabbitai Add TRIGGER_ENV env var to runs Capture and propagate env info for socket and container providers Feb 27, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
.changeset/hungry-moles-do.md (1)

6-7: Clarify the Changeset Description.
The description "Add TRIGGER_ENV environment variable to task runs" is clear and succinct. For better traceability and future reference, consider expanding it with more context about how this variable will be used across components or its impact on task execution.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b2bb01 and 9990b56.

📒 Files selected for processing (1)
  • .changeset/hungry-moles-do.md (1 hunks)
🔇 Additional comments (1)
.changeset/hungry-moles-do.md (1)

1-4: Ensure Release Patch Consistency.
The changeset specifies patch bumps for both "trigger.dev" and "@trigger.dev/core". Please verify that these version updates align with your semantic versioning guidelines and that the context of the changes (i.e., the addition of the TRIGGER_ENV environment variable) is adequately documented.

@Shahor Shahor changed the title Add TRIGGER_ENV env var to runs Capture and propagate env info for socket and container providers Capture and propagate env info (TRIGGER_ENV) for socket and container providers Feb 27, 2025
@ericallam
Copy link
Member

This isn't quite the right way to provide a new built-in environment variable to workloads in Trigger.dev. You should instead add the TRIGGER_ENV variable here:

You can see in that file in other places where we set similar env vars. Also, there are instructions here for how to contribute and do local testing: https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add process.env.TRIGGER_ENV
2 participants