Allow systemcontainers to install, run, and uninstall in one go#952
Allow systemcontainers to install, run, and uninstall in one go#952ashcrow wants to merge 5 commits intoprojectatomic:masterfrom
Conversation
Atomic/syscontainers.py
Outdated
| util.call(start_command) | ||
| finally: | ||
| # Uninstall the image post run | ||
| self.uninstall(name) |
There was a problem hiding this comment.
when I firstly suggested this I forgot we had an extract. Sorry :)
At some point we will need an OSTree temporary storage (also to fix mount) but for now I think it would be better if we can do something like:
try:
self.extract(img, tmpdir)
generate_systemd_directives(...)
os.chdir("$tmpdir/rootfs")
util.call(...)
finally:
shutil.rmtree(tmp)tmpdir is better created under the OSTree repository so we are sure to use hard links and the checkout is faster. The _try_ostree_mount function in mount.py does that (we will need to copy/move it to syscontainers). Anyway, I'll have to fix this for the RPM stuff as well so feel free to ignore this part.
What do you think?
I see in your TODO list that there is to create the runc directives for --user. That should be already done by generate_systemd_startstop_directives now to use bwrap-oci so there should not be anything to do for this.
There was a problem hiding this comment.
What do you think?
SGTM. I'll update this afternoon.
I see in your TODO list that there is to create the runc directives for --user. That should be already done by generate_systemd_startstop_directives now to use bwrap-oci so there should not be anything to do for this.
Perfect!
|
We keep making changes to system containers that force the user to have some kind of knowledge of how to install the image, can we remove the option and just put something like a label into the container to do a --oneshot? Force the image developer to define how to install his image and allow the atomic command to react. I want the same thing for --system. If I do And foobar is intended to be a --oneshot --system container I will be prone to forget those options. |
|
@ashcrow, sure! A container that is designed to be "oneshot" probably makes no sense at all to have it normally installed so a label that indicates this behaviour can make this easier for the user. |
|
@giuseppe I'll pull the option code out of this PR, take a look at how labels are used, and see if I can't put something together. I'll probably bug you a bit 😆 |
|
I created an LabelsRunQuestion@giuseppe I noticed that using |
5fba4fd to
4889f33
Compare
|
@ashcrow Nice! We should probably add a check for the type of container also for already pulled images, I guess you are pulling it directly from the local Docker engine? We do that now for images pulled from a registry. I've added a fixup commit here: https://github.com/giuseppe/atomic/tree/oneshot I have not tested it, just wanted to share it quickly. I've done some small changes, also added the possibility of generating the configuration from the config.json.template file and support for systemd tmpfiles, if the container needs to bind directories/files not present on the file system when it starts. Some code is deliberately duplicated in the new function, as it will save some merge conflicts with #949. I also like the new path for Another change is to use a tmpdirectory under the OSTree repository, so we use hard links instead of copying the files. I think at this point all the features we need to support are there. What do you think? |
|
@giuseppe I'll pull in and test. |
|
@yuqi-zhang thanks for the info! @giuseppe I'm thinking that |
|
@ashcrow let's add another exception for now
|
|
I've added another fixup commit that solves the issue and a few other things. There is only one missing part now, and that we need to set the correct This requires some refactoring as the code in common must be moved out of The next failure in the tests is fixed by 10ba9dc (which is part of #949). No idea how this could get broken. |
|
once 949 gets merged, we can use this commit here to refactor out the generate values function and use from here as well: |
|
Local testing worked as expected. |
|
yes, I've done some testing as well and it worked for me (except handling template files). We should probably add the oneshot image to the testing images as well. |
|
@giuseppe I'll add that shortly. I'll also stage a |
|
@ashcrow thanks, could the image include a |
|
@giuseppe the test image? Sure. |
|
☔ The latest upstream changes (presumably 1b216a4) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Added a |
|
I'll add to integration tests an look at your added patch in the morning @giuseppe. |
|
This PR is ready for review. |
|
LGTM |
|
/cc @baude |
Atomic/syscontainers.py
Outdated
| if not os.path.exists(rootfs): | ||
| os.makedirs(rootfs) | ||
|
|
||
| # XXX |
There was a problem hiding this comment.
Yes, good catch. Will update.
|
|
||
| def install(self, image, name): | ||
| """ | ||
| External container install logic. |
There was a problem hiding this comment.
I know we are not outwardly changing at of the interfaces to the users which usually prompts someone to do updates a docs/ file. I'm thinking however it might be worth noting this change and the labels in the docs somwhere.
There was a problem hiding this comment.
Right now there are 3 (or more?) places that document labels. I'm planning on adding it in the Atomic System Containers repo and, as it is used, should propagate to wherever becomes the proper place. Or at least that is the theory.
When the atomic.run is provided and set to "once" the install method will extract, run, and clean up after the container. This change also splits install logic into an internal and external method.
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
|
Removed the leftover and rebased (for good measure). ⬆️ |
|
@baude Ready to merge? |
Closes: #952 Approved by: baude
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #952 Approved by: baude
Closes: #952 Approved by: baude
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #952 Approved by: baude
|
☀️ Test successful - status-redhatci |
See projectatomic/atomic#952 Closes: #58 Approved by: yuqi-zhang
After projectatomic/atomic#952 it's now possible to add a label to an image atomic.run=once so that when installed as a system container it will be run immediately with runc (no systemd involved) and then uninstalled. This use case matches containerized Ansible playbooks very well, so we add that label in playbook2image so that the usage experience of packaged playbooks run as system containers matches standalone container runs.
After projectatomic/atomic#952 it's now possible to add a label to an image atomic.run=once so that when installed as a system container it will be run immediately with runc (no systemd involved) and then uninstalled. This use case matches containerized Ansible playbooks very well, so we add that label in playbook2image so that the usage experience of packaged playbooks run as system containers matches standalone container runs.
After projectatomic/atomic#952 it's now possible to add a label to an image atomic.run=once so that when installed as a system container it will be run immediately with runc (no systemd involved) and then uninstalled. This use case matches containerized Ansible playbooks very well, so we add that label in playbook2image so that the usage experience of packaged playbooks run as system containers matches standalone container runs.
This change adds a new optional label called
atomic.run. When set tooncethe image will be extracted, run, and cleaned up. This currently requires the use of--system.The idea behind this new option is that there are cases where a system container would not be a full fledged service on a host. For example, the openshift-ansible installer isn't a service, but a containerized installer.
Example:
/cc @sdodson @tbielawa