dnephin / dobi

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

Can we compute env in shell #173

Closed kindermax closed 4 years ago

kindermax commented 4 years ago

I am asking about the ability to compute env vars before command run. This is kinda makefile behavior.

For example, calculate a hash from the file, and expose it as MY_TAG and use it as a tag for the image.

cat myfile.txt | base64 -

I have

image=myimage:
    tags: ['{env.MY_TAG}']

I would like to note that it would be great to do it in dobi and not outside of it

For example this is not desired:

MY_TAG=$(cat myfile.txt | base64 -) dob myimage:pull
dnephin commented 4 years ago

Yes, this is supported using the :capture() task of a job resource: http://dnephin.github.io/dobi/tasks.html#job-tasks

There is an example here: https://github.com/dnephin/dobi/blob/master/examples/env-vars/dobi.yaml

I think for your case it would be something like this:


image=bash:
  image: bash
  tags: [5]
  pull: once

job=base64:
  use: bash
  # probably a `mounts:` here as well to make the file available to this container
  command: bash -c 'cat myfile.txt | base64 -'

image=myimage:
  tags: ['{env.MY_TAG}']
  depends:
    - base64:capture(MY_TAG)
kindermax commented 4 years ago

Got the idea, thank you for your quick response!