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

How best to use with multi-stage? #129

Open
sVattic opened this issue May 11, 2019 · 6 comments
Open

How best to use with multi-stage? #129

sVattic opened this issue May 11, 2019 · 6 comments
Labels
documentation enhancement New feature or request

Comments

@sVattic
Copy link

sVattic commented May 11, 2019

Love the tool idea. I am wondering how best to use ansible-bender with multi-stage builds.

In the Docker world, I can leave build dependencies behind by using two images:

FROM some-large-image as temp

RUN install the many build requirements...
RUN make


FROM clean-smaller-image
COPY --from=temp /result /dist
CMD ["/prod"]

With ansible-bender, I can see how to make the first image but not the second.
What do you think?

@TomasTomecek
Copy link
Collaborator

I think this could be doable by mounting the same host path to both container image builds:

$ ansible-bender build --build-volumes /path first-playbook.yaml
$ ansible-bender build --build-volumes /path second-playbook.yaml

I agree it would be lovely to get native support in bender for multi-stage builds.

@TomasTomecek TomasTomecek added the enhancement New feature or request label May 14, 2019
@sVattic
Copy link
Author

sVattic commented May 14, 2019

Oh, that makes sense! That's a perfect workaround for now.

@TomasTomecek
Copy link
Collaborator

okay, so let's treat this issue as a lack of documentation

@slopedog
Copy link
Contributor

slopedog commented Aug 9, 2019

Just found this after leaving a comment on Tomáš's blog. Here's a different way I found to do this:

- name: Start up compile image container
  delegate_to: localhost
  shell: |
    set -e
    buildah rm compile-container || true
    buildah from --name compile-container compile-image
    buildah mount compile-container
  register: compile_img_path
  changed_when: false
  tags: no-cache

- set_fact:
    compile_img_path: "{{ compile_img_path.stdout_lines[-1] }}"

This will put the source image's local filesystem path in the variable compile_img_path, and you can copy things from there.

@cognifloyd
Copy link

Maybe a mode where each play gets treated as a separate image (or layer)?

@irhawks
Copy link

irhawks commented Nov 14, 2021

However, currently mounting using overlay in rootless mode is not supported. when buildah mount compile-container as a non-root user, an exception raises:

$ buildah mount pulsar-all-temp
cannot mount using driver overlay in rootless mode. You need to run it in a `buildah unshare` session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants