Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile.generated race with same Dockerfile and different build args #113

Open
grugnog opened this issue Feb 25, 2019 · 3 comments
Open

Comments

@grugnog
Copy link

grugnog commented Feb 25, 2019

build.yml looks something like:

build:
  version: 2016-03-14 # version of the build schema.
  steps:
    v1:
      name: v1
      dockerfile: Dockerfile
      args:
        version: 1
    v2:
      name: v2
      dockerfile: Dockerfile
      args:
        version: 2

What happens is that the Dockerfile.generated is the same filename and path. Both builds proceed in parallel (using whichever file was created last). As soon as the first build finishes the Dockerfile.generated is removed and so the second build errors with "Build for step v2:latest failed due to remove dir/Dockerfile.generated: no such file or directory".

I think the solution for this would be to either encode the build args in the filename for Dockerfile.generated (probably in the form of a hash) or generate a random token to the file and track that through the lifecycle of the build. The latter seems like the simpler approach, since it seems likely there is other data (perhaps the context directory, for example) that could affect the build and would need to be included in the hash.

@grugnog
Copy link
Author

grugnog commented Feb 25, 2019

For anyone else with the same issue, it seems that you can work around this by using depends_on to ensure they build in serial and don't step on each others toes.

@khash
Copy link
Member

khash commented Feb 28, 2019

Thank you @grugnog for the suggestion. It makes sense to use depends_on to avoid a race condition, however I'd like to know what you need to achieve so probably we can make changes to accomodate that without serialising the builds.

@grugnog
Copy link
Author

grugnog commented Feb 28, 2019

I think the use case described in my example is probably a good one to work from. We want to allow a single Dockerfile to build different versions of the same program, so (rather than duplicate the Dockerfiles or build some templating system) we use build args to inject the version we want to build.
In this case the 2 builds are totally independent, so the depends_on is really just a workaround - a better result would be to have the Dockerfile.generated file name include a hash or random token, so that the builds can be run in parallel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants