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

Rebuild container if specified files has changed #6936

Closed
kindermax opened this issue Oct 3, 2019 · 5 comments
Closed

Rebuild container if specified files has changed #6936

kindermax opened this issue Oct 3, 2019 · 5 comments

Comments

@kindermax
Copy link

kindermax commented Oct 3, 2019

Hi. The main idea of this feature request is the ability to specify a list of files on which image depends and rebuilds automatically.

It can be really helpful to just declaratively tell a service, when I want it to rebuild

How it can be used ?
For example we have a simple nodejs service.

webapp:
    image: webapp-dev
    build:
      dockerfile: ./docker/Dockerfile.webapp-dev
      context: .
    working_dir: /work

We can add something like hash or checksum or you name it.

webapp:
    image: webapp-dev
    build:
      dockerfile: ./docker/Dockerfile.webapp-dev
      checksum:
      - ./package.json
      - ./package-lock.json
      - ./docker/Dockerfile.webapp-dev
      context: .
    working_dir: /work

And now when one of these files in checksum changes, docker-compose up webapp will automatically rebuild an image.

This requires a place where docker-compose can store checksums for images and check those against newly calculated ones.

Also, it is a good idea, IMHO, to new command called checksum which calculates and prints the same checksum as it will be used to make the decision to rebuild an image

@fabiosantoscode
Copy link

I really like this idea. However I find it unlikely that it will go in.

As a workaround, you can do some stuff around the npm nodemon package. It doesn't only run JS, as with the --exec argument you can do anything with it, including asking docker-compose to rebuild.

@kindermax
Copy link
Author

Well, yes it can be achieved by wrapping docker-compose in some kind of entry point script where the entry point is responsible for calculating checksums and rebuilding images but its more convenient to have such functionality built into docker-compose. I must say it's not only related to nodejs. Lets say puthon has its onw requirements, go and so on.

@ndeloof ndeloof changed the title [Feature Request] Rebuild container if specified files has changed Rebuild container if specified files has changed Oct 8, 2019
@ndeloof
Copy link
Contributor

ndeloof commented Oct 8, 2019

Actually what you suggest could be better implemented relying on BuildKit as the build engine, as this one do offer very efficient caching and will be able to "rebuild" your image within a second if no change took place on source tree.
Now that we have option to use CLI builder with COMPOSE_DOCKER_CLI_BUILD this sounds feasible. But you would still have to stop/restart your compose stack. If you are looking for an shorter cycle, then you should better look into bind mounting project sources into container and configure your stack to live-reload when source get updated. This is something well supported by nodejs, might be harder to implement with other languages.

@ndeloof
Copy link
Contributor

ndeloof commented Oct 10, 2019

Sounds like a resurection of #184

@ndeloof
Copy link
Contributor

ndeloof commented Oct 10, 2019

Closing as a duplicate for #184 which has already many core contributors of docker-compose watching, and a few proposals.

@ndeloof ndeloof closed this as completed Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants