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

Fully custom build commands in compose file #12376

Open
jackmtpt opened this issue Dec 11, 2024 · 2 comments
Open

Fully custom build commands in compose file #12376

jackmtpt opened this issue Dec 11, 2024 · 2 comments

Comments

@jackmtpt
Copy link

Description

Several of our projects use the feature of MSBuild to generate container images as part of publishing: https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container

This means that these projects do not have a Dockerfile, because MSBuild generates the final image itself by adding layer(s) on top of a specified base image that contain the compiled binaries. Typically we would run a command like dotnet publish /t:PublishContainer to build the container image - MSBuild will automatically tag the image and put it into the cache of the local Docker daemon.

We would like the ability to integrate this into a compose file in a similar way that compose can currently build an image from a Dockerfile if it's not present locally. I'm imagining syntax like the following:

  backend:
    image: example/app-backend
    build:
      context: backend
      custom_command: dotnet publish /t:PublishContainer

The custom-command would be executed instead of docker build using the context directory as the working dir (and likely most if not all other options would be ignored).

Currently the workaround for this is that developers must run dotnet publish manually first, and then docker compose up afterwards - this would eliminate that and enable the same simplicity that you get when compose builds from a Dockerfile.

@ndeloof
Copy link
Contributor

ndeloof commented Dec 12, 2024

Comparable to #10615 and a few other to request support for third-party build tooling.

I wonder we could support this feature relying service hooks, i.e we could introduce a build hook, which would run a command responsible to prepare or produce the desired image, before compose trigger a docker build.
That being said, this would break compose file portability (by depending on a third-party command) 🤨

@jackmtpt
Copy link
Author

A pre-build hook could work yeah, as long as the hook can then prevent docker build from actually getting executed since in the dotnet publish scenario docker build will fail because there's no Dockerfile present.

Yes it would introduce a dependency on a third-party command but - at least in the dotnet scenario - anyone who wants to build the image locally after e.g. making a code change is likely to have the required build tools already installed (via their IDE). In fact it would be an intentional choice by the application author to require this because they would not be providing a Dockerfile to build the image the traditional way, so I think that's acceptable.

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

2 participants