DockerMake icon indicating copy to clipboard operation
DockerMake copied to clipboard

pre-build step?

Open paleozogt opened this issue 8 years ago • 4 comments

Currently, build runs after all the requires run. Could we have a pre_build that runs before the requires? ie,

foobar:
    FROM: foobase
    pre_build: |
       RUN do stuff before foo and bar run
    requires:
       - foo
       - bar
    build: |
       RUN do stuff after foo and bar run

foo:
    build: |
       RUN do foo stuff

bar:
    build: |
       RUN do bar stuff

paleozogt avatar Dec 21 '17 18:12 paleozogt

This you can solve by creating baz: target and adding it to the requires before foo, bar. Can you be more specific how that would be useful?

BTW: I found it quite useful to to extend docker-make with kind of "makefile" tool. example: https://github.com/epcim/docker-salt-formulas/tree/develop

epcim avatar Feb 14 '18 09:02 epcim

Here's a more illustrative example:

foobar1:
    FROM: foobase1
    pre_build: |
       RUN do ABC before foo and bar run
    requires:
       - foo
       - bar
    build: |
       RUN do DEF after foo and bar run

foobar2:
    FROM: foobase2
    pre_build: |
       RUN do UVW before foo and bar run
    requires:
       - foo
       - bar
    build: |
       RUN do XYZ after foo and bar run

foo:
    build: |
       RUN do foo stuff

bar:
    build: |
       RUN do bar stuff

I can't just add a baz: target to foo/bar's requires, because I want different things to happen before foo and bar depending on the parent (foobar1, foobar2).

Of course, I could have a foobar1_setup/foobar2_setup in the requires before foo/bar, but it makes for lots of targets (especially when there are large numbers of foobarXXX.

pre_build doesn't necessarily enables functionality that isn't present in DockerMake, but I think it would make for cleaner, easier to maintain DockerMake.yml files.

paleozogt avatar Feb 14 '18 16:02 paleozogt

Thanks for this suggestion, @paleozogt . I definitely understand the motivation here, although I unfortunately don't believe such functionality could be easily supported with the way the program's written right now.

Curious, though, if you have examples of other build systems that work in this way? Would like to investigate and learn more

avirshup avatar Feb 22 '18 00:02 avirshup

Most of my experience with build systems is with Gradle and CMake, tho these are for code building, not image building. At any rate, both Gradle and CMake support a similar idea. For example, Gradle's tasks have dependsOn and finalizedBy, while CMake tasks have add_dependency and POST_BUILD.

I've also been thinking of DockerMake's targets like OOP inheritance. It's not really the right model for how DockerMake works, but it's what made me want to have a "pre" version of build.

Dockerfile is very limited when it comes to making a constellation of complicated images with different base images and packages (some common, some not). DockerMake let me get on top of that complexity and have a DockerMake.yml that's actually maintainable. So, thanks for making this tool!

paleozogt avatar Feb 22 '18 16:02 paleozogt