denzp / cargo-wharf

Cacheable and efficient Docker images builder for Rust
https://hub.docker.com/r/denzp/cargo-wharf-frontend
Apache License 2.0
223 stars 8 forks source link

output multiple images? #25

Open kilpatty opened 4 years ago

kilpatty commented 4 years ago

Is there a way to allow this to output multiple images?

I'm using a workspace, but rather than output 2 binaries in the same image, I'd love to have this output 2 images each with one of the binaries.

If there is somewhere you can point me to implement this please do, I'm happy to spend the time!

denzp commented 4 years ago

I wonder if the quick workaround works in your case: docker build -f inner-crate-path/Cargo.toml .

In this case, the frontend will build only binary(-es) defined in a crate at inner-crate-path of the workspace.

There is a major drawback with this - unfortunately, you'll need to duplicate [package.metadata.wharf] annotations per each subcrate. The approach is also used by the cargo-wharf itself to produce 2 images out of a single workspace: https://hub.docker.com/r/denzp/cargo-wharf-frontend https://hub.docker.com/r/denzp/cargo-container-tools

denzp commented 4 years ago

On the long run, I've been thinking about something similar to Cargo cfg(...). Eventually, it might be possible to specify base and "overridden" settings:

[package.metadata.wharf.builder]
image = "rust"

[package.metadata.wharf.output]
image = "debian:stable-slim"

[workspace.metadata.'cfg(name = binary-2)'.wharf.output] # <--
image = "ubuntu:latest"

[[package.metadata.wharf.binary]]
name = "binary-1"
destination = "/usr/local/bin/binary-1"

[[package.metadata.wharf.'cfg(name = binary-2)'.binary]] # <--
name = "binary-2"
destination = "/usr/local/bin/binary-2"

[[package.metadata.wharf.'cfg(name = binary-3)'.binary]] # <--
name = "binary-3"
destination = "/usr/local/bin/binary-3"

This suppose to always output binary binary-1, and optionally binary-2 and binary-3 depending on --build-arg cfg=name=binary-2 or --build-arg cfg=name=binary-3.

Additionally when --build-arg cfg=name=binary-2 is set, the output image should be overridden to ubuntu:latest.

What do you think about this proposal? Would this help for your use case?