Skip to content

drawbridge up --patch-env: update existing .env file with drawbridge URLs #43

@radiosilence

Description

@radiosilence

Problem

Currently --local b2c-spa generates a standalone .env.drawbridge that the user has to manually copy or source. But most projects already have a .env file with their own config (third-party keys, feature flags, etc.) — they don't want to replace it wholesale, they just need the drawbridge-managed URLs patched in.

Proposed solution

drawbridge up --local b2c-spa --patch-env ../app-b2c-spa/.env

Behaviour

  1. Parse the target .env file
  2. For each env var in the service's drawbridge config (env: block), check if it exists in the target file
  3. Update matching keys with the drawbridge values (e.g. B2C_API_GATEWAY_URL gets rewritten from the staging URL to https://api.b2c.dev.local/graphql)
  4. Append any keys from drawbridge config that don't exist in the target file (commented with # Added by drawbridge)
  5. Write the patched file back

Considerations

  • Should create a .env.drawbridge.bak backup before patching
  • Should be idempotent — running twice doesn't duplicate entries
  • Need to handle comments and blank lines in the original .env gracefully
  • Could mark patched lines with a trailing comment # [drawbridge] so they can be identified/reverted
  • drawbridge down or a drawbridge unpatch command could restore from backup
  • Should warn if a key exists in both the original and drawbridge config with different values (so user knows what's being overwritten)

Example

Before:

B2C_API_GATEWAY_URL=https://b2c-api-gateway-eng-mint.dev.fresha.io/graphql
REDIS_HOST=localhost
FACEBOOK_APP_ID=630728900463808

After --patch-env:

B2C_API_GATEWAY_URL=https://api.b2c.dev.local/graphql  # [drawbridge]
REDIS_HOST=redis.dev.local  # [drawbridge]
FACEBOOK_APP_ID=630728900463808

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestv0.5Target for v0.5.0 release

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions