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
- Parse the target
.env file
- For each env var in the service's drawbridge config (
env: block), check if it exists in the target file
- 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)
- Append any keys from drawbridge config that don't exist in the target file (commented with
# Added by drawbridge)
- 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
Problem
Currently
--local b2c-spagenerates a standalone.env.drawbridgethat the user has to manually copy or source. But most projects already have a.envfile 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
Behaviour
.envfileenv:block), check if it exists in the target fileB2C_API_GATEWAY_URLgets rewritten from the staging URL tohttps://api.b2c.dev.local/graphql)# Added by drawbridge)Considerations
.env.drawbridge.bakbackup before patching.envgracefully# [drawbridge]so they can be identified/reverteddrawbridge downor adrawbridge unpatchcommand could restore from backupExample
Before:
After
--patch-env: