dnephin / dobi

A build automation tool for Docker applications
https://dnephin.github.io/dobi/
Apache License 2.0
309 stars 36 forks source link

Computing image name with a (bash) command #142

Closed Fuco1 closed 6 years ago

Fuco1 commented 6 years ago

Hey.

We are currently building cache images for dependencies such as npm/yarn or composer. What we do is that we compute an sha1 of the lock file and then use that as tag for the image. This is enough because the dependency resolution is deterministic with respect to the lock file.

Is there some way I can achieve this with dobi? What I need to do is get the file, compute the hash and then expose it as a variable so that it can be used in the image field for image=... task.

Fuco1 commented 6 years ago

I have created an image and job and mount tasks that will compute the hash and store it in an ".env" file. Then I depend on this env file in the next image task which seems to work. Except when the lock file changes the env file is not recomputed because I can't depends in the env type task. Is that something that could be considered?

I can depend on the setup task in the image task but that seems like skipping a link in the dependency chain as I would now have to add that everywhere where I depend on the env

dnephin commented 6 years ago

an image and job and mount tasks that will compute the hash

This part sounds right, but you don't need to store the value in a file. You can use the capture action to store the value in an environment variable, and use {env.VARIABLE} as the image or tag for the image.

As you discovered in #74, this will never cache, but when it's fixed, it should have the correct dependency on running the job:capture().

Fuco1 commented 6 years ago

@dnephin That's interesting. Is there a usage of this in the examples? Maybe we can craft one, it seems like a pretty useful feature.

dnephin commented 6 years ago

Not yet, I just opened PR #146 to add an example. How does that look?

Fuco1 commented 6 years ago

@dnephin This is very helpful, thanks a bunch! I'll try these things first thing in the morning when I get to the office and let you know if I have any further questions. Though I think this should give me all I need for now.

Thanks for all the thought put into this project, it's turning out to be quite amazing!