Support arbitrary interpolation of compose files #492
Notifications
Total Time Spent: 3 hours 23 minutes
Due Date
decentral1se
3 hours 23 minutes
No due date set.
Dependencies
No dependencies set.
Reference: toolshed/abra#492
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When trying to substitute an env var for a value in a recipe config file, abra sometimes gives an error like:
FATA[0000] unable to validate recipe: error while interpolating services.ssh.ports.[].published: failed to cast to expected type: strconv.Atoi: parsing "": invalid syntax caller="/drone/src/cli/internal/validate.go:71 ValidateRecipe" stack="/drone/src/cli/internal/validate.go:71Steps to reproduce:
Create a recipe with a compose file that includes, for example, a section with
Run
abra app new mynewrecipeGet error
Thanks for the report @marlon ! I'm not super familiar with Go but it seems
Atoiis trying to cast to an integer; maybe it would help to provide a default e.g.published: ${PORT:-22}?Yeh @marlon I think @3wordchant hit the nail on the head here. Also you can check that you're threading the
PORT=...through in the.envfile also?In the same spirit as #525 I think we should try to catch these errors and reinterpret them to something that someone who doesn't know internals can make sense of.See #492 (comment).valid env variable substitution in compose file throws an errorto Improve compose validation errorsComing back to this, I'm not sure we should actually do anything about this in
abra. The original error was a recipe configuration issue. The error message was "good enough" to point in the right direction. I think there is always a tension between making things more usable and letting the underlying errors bubble up. I am not sure where I would hook in to this really long error message to smooth it over (we typically match by string contents...) and furthermore, I would fear that we'd end up suppressing other messages which might match.... gonna bail on this for now, please re-open if you feel strongly otherwise.Sorry to have left this stale for so long, but the issue I was trying to surface here is that the original config snippet I gave is valid compose syntax, but abra seems to be throwing an error when it parses it.
An alternate formulation of the issue is, when I use this syntax:
I get an error:
FATA services.ssh.ports.0 Does not match format 'ports'Is it correct that abra should not allow variable substitution for ports? Is it failing to interpolate before testing the syntax? I don't fully understand but I know that when I run a compose file using this syntax directly using docker compose it works fine. So I infer that it's an abra issue, but maybe I'm missing something.
@marlon all good. can you share the full compose config? I'm a bit suspicious of
services.ssh.portsand what that is doing? In general, I don't think any config specifies ports that is outside of the traefik labels? E.g the gitea config below. This could be anabraissue, but I think it might not be a working config / approach that we've used before, which is maybe why you're running into it?989294173e/compose.yml (L84)You're right that what I'm attempting with this syntax is experimental compared to the conventional approach in coop cloud to handle ports through Traefik labels. The big thing I'm investigating is whether there's a coop cloud-compatible way to assign port mappings based on .env configuration, rather than hardcode them in recipes. This is relevant because the recipe-defined approach complicates running, for example, two SFTP servers behind the same ingress.
I am interested generally in thoughts about the broader experiment, but for the purposes of this syntax issue, I guess the main question is whether variable substitution doesn't work intentionally for some design reason, or whether it's a bug? I had initially thought that maybe it was just expected behavior from docker, but like I said it works in docker compose...
Anyway here's the config I was experimenting with:
(Note that substitution works for ${TAG} in the image declaration, but not for the port)
I see, that makes sense! OK I will investigate if
abrais causing this (seems likely now) since ondocker composeworks... thanks for the info! Had read through this also: https://docs.docker.com/compose/how-tos/environment-variables/variable-interpolation/Woah, this is a bug that cannot be easily fixed. It seems that supporting arbitrary interpolation will require a significant refactor.
abrahas more operating modes thandocker composeanddocker swarm. We sometimes have an app env and sometimes not (e.g. when linting a recipe in isolation). Some values in the compose file require special validation and if the value is not present, then it explodes. So, some code paths don't have access toPORT=2222even tho it's in the app env. I'm not sure how to fix this right now.🤔🤔 Well thanks for looking into it and the explanation!
Improve compose validation errorsto Support arbitrary interpolation of compose files@marlon yeh I guess the work-around for now is to create some hard-coded values in separate
compose.foo.ymlfiles 🤔I would like to carry out this refactor to have full feature parity but it's not super high on my stack atm and also might be a bit of a gruesome refactor. So, I'd ideally punt this down the road a bit until other stuff getting in peoples way are sorted (new v0.12/13).
Good that you caught this one. It highlights some technical debt we need to pay off 🙈
Great, yeah agreed it doesn't seem very high priority but I think resolving it eventually could unlock some useful recipe design patterns.
One day I will learn Go and contribute more than just bug reports lol