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

Slimify based on multiple commands? #515

Open
Pithikos opened this issue May 7, 2023 · 2 comments
Open

Slimify based on multiple commands? #515

Pithikos opened this issue May 7, 2023 · 2 comments

Comments

@Pithikos
Copy link

Pithikos commented May 7, 2023

Scenario

I have a single image that is deployed in 3 different ways:

  1. Running migrations of the app
  2. Deploy app1 internally on port 5000
  3. Deploy app2 externally on port 3000

In each case there's some overlap between files used but not all are used. Running docker-slim against (2) ends up removing files used by case (1) and (3) for example.

How can I solve this? Alternatively is there a way to skip specific files?

I'd prefer to not split into 3 separate containers, since everything is tightly coupled and that will introduce a lot of unnecessary maintenace.


Specifications

  • Version: linux|Transformer|1.39.1|537c77323f2e9a3d6771aa0ea73a047017774d16|2022-11-13_03:27:40AM
  • Platform: Ubuntu 20.04.6 LTS
@kcq
Copy link
Member

kcq commented May 11, 2023

This is a very interesting use case @Pithikos !

The first thing you can try is one/some of the --include-** flags (e.g., --include-path, which can point to a file or to a directory). Those --include-** flags allow you to keep extra things in the minified container image. There's a number of new (already committed, but not in a release) flags like --include-app-image-all (that gets used with --app-image-start-instruction-group) that allow you to keep everything that's in your application part of the image.

Another thing to try is the --exec flag to run extra shell commands during the runtime analysis phase that would allow you to ensure the unused parts of your images get used.

In some cases, wrapping all three (or how many) ways to invoke your container in a shell script (which could be mounted in the build command) and then making this wrapper shell the entrypoint (using the --entrypoint flag) when you execute the slim build command can accomplish what you are looking for.

There's also a new option on the todo list that should help too. There'll be a new slim command called merge where you can point to your minified images and it'll combine all of them into one. It's a relatively straight forward enhancement, so it should be available soon.

@kcq
Copy link
Member

kcq commented Jul 15, 2023

@Pithikos The new release has an experimental merge command that can help with your use case: https://github.com/slimtoolkit/slim/releases/tag/1.40.3

Once you have your 3 minified images that correspond to each of your execution profiles you can merge the first two and then merge the result image of the initial merge with the last minified image. Let me know how it goes and if you encounter any gotchas or if you have any comments or asks there.

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