Move mergeAbraShEnv and use it in deploy, rollback, upgrade #638

Closed
opened 2025-09-02 00:44:07 +00:00 by 3wordchant · 4 comments
Owner

kadabra has a handy mergeAbraShEnv function, we could potentially use it in regular app deploy / app upgrade / app rollback.

kadabra has [a handy `mergeAbraShEnv` function](https://git.coopcloud.tech/toolshed/abra/src/branch/main/cli/updater/updater.go#L338-L351), we could potentially use it in regular `app deploy` / `app upgrade` / `app rollback`.
Owner

I believe that is already the case 👁️‍🗨️ I don't think that's documented anywhere for operators to know that these env vars will be put into the app env? I guess it's more for getting config versions and not arbitrary env vars for which the .env should be used?

> grep -iR ReadAbraShEnvVars
cli/app/upgrade.go:             abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath)
cli/app/rollback.go:            abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath)
cli/app/deploy.go:              abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath)
cli/updater/updater.go: abraShEnv, err := envfile.ReadAbraShEnvVars(recipe.AbraShPath)
I believe that is already the case 👁️‍🗨️ I don't think that's documented anywhere for operators to know that these env vars will be put into the app env? I guess it's more for getting config versions and not arbitrary env vars for which the `.env` should be used? ```bash > grep -iR ReadAbraShEnvVars cli/app/upgrade.go: abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath) cli/app/rollback.go: abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath) cli/app/deploy.go: abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath) cli/updater/updater.go: abraShEnv, err := envfile.ReadAbraShEnvVars(recipe.AbraShPath) ```
Author
Owner

Ah sorry for being unclear.

cli/updater/updater.go (kadabra) has this:

// mergeAbraShEnv merges abra.sh env vars into the app env vars.
func mergeAbraShEnv(recipe recipe.Recipe, env envfile.AppEnv) error {
	abraShEnv, err := envfile.ReadAbraShEnvVars(recipe.AbraShPath)
	if err != nil {
		return err
	}

	for k, v := range abraShEnv {
		log.Debugf("read v:%s k: %s", v, k)
		env[k] = v
	}

	return nil
}

The other 3 all copypasta the for loop, e.g. cli/app/deploy.go#345:

abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath)
if err != nil {
	log.Fatal(err)
}
for k, v := range abraShEnv {
	app.Env[k] = v
}

So we'd be saving uhh 2 lines per instance by replacing with mergeAbraShEnv, maybe not worth doing idk.

Ah sorry for being unclear. `cli/updater/updater.go` (kadabra) has this: ```golang // mergeAbraShEnv merges abra.sh env vars into the app env vars. func mergeAbraShEnv(recipe recipe.Recipe, env envfile.AppEnv) error { abraShEnv, err := envfile.ReadAbraShEnvVars(recipe.AbraShPath) if err != nil { return err } for k, v := range abraShEnv { log.Debugf("read v:%s k: %s", v, k) env[k] = v } return nil } ``` The other 3 all copypasta the for loop, e.g. [`cli/app/deploy.go#345`](https://git.coopcloud.tech/toolshed/abra/src/branch/main/cli/app/deploy.go#L129-L135): ```golang abraShEnv, err := envfile.ReadAbraShEnvVars(app.Recipe.AbraShPath) if err != nil { log.Fatal(err) } for k, v := range abraShEnv { app.Env[k] = v } ``` So we'd be saving uhh 2 lines per instance by replacing with `mergeAbraShEnv`, maybe not worth doing idk.
Owner

Ah gotcha, nah it sounds legit! There's loads of duplication and "moving fast"-isms around the codebase, so feel free go for stuff. If the tests pass then it's usually good to blast stuff out. The integration suite is pretty gnarly so we can be confident if it passes.

Ah gotcha, nah it sounds legit! There's loads of duplication and "moving fast"-isms around the codebase, so feel free go for stuff. If the tests pass then it's usually good to blast stuff out. The integration suite is pretty gnarly so we can be confident if it passes.
Author
Owner

Oh wait this was merged with !657

Oh wait this was merged with !657
Sign in to join this conversation.
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: toolshed/abra#638
No description provided.