Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.

Fixes for system containers generate RPM#949

Closed
giuseppe wants to merge 17 commits intoprojectatomic:masterfrom
giuseppe:generate-rpm-fixes
Closed

Fixes for system containers generate RPM#949
giuseppe wants to merge 17 commits intoprojectatomic:masterfrom
giuseppe:generate-rpm-fixes

Conversation

@giuseppe
Copy link
Collaborator

Add some tests for the generate RPM feature of system containers and fix some issues that I've found while using these tests.

@giuseppe giuseppe changed the title Generate rpm fixes Fixes for system containers generate RPM Mar 23, 2017
@giuseppe giuseppe force-pushed the generate-rpm-fixes branch 4 times, most recently from 26003cb to f7dba93 Compare March 23, 2017 20:25
@giuseppe giuseppe changed the title Fixes for system containers generate RPM [WIP] Fixes for system containers generate RPM Mar 23, 2017
@giuseppe giuseppe force-pushed the generate-rpm-fixes branch from f7dba93 to 6c8d925 Compare March 23, 2017 22:37
@giuseppe
Copy link
Collaborator Author

bot, retest this please

@giuseppe giuseppe changed the title [WIP] Fixes for system containers generate RPM Fixes for system containers generate RPM Mar 23, 2017
@giuseppe giuseppe force-pushed the generate-rpm-fixes branch 2 times, most recently from 8efd4a3 to 2cbfd7c Compare March 24, 2017 10:36
@rhatdan
Copy link
Member

rhatdan commented Mar 24, 2017

Great work. LGTM

@giuseppe
Copy link
Collaborator Author

I am adding some more cleanups @TomasTomecek would like to use the same feature for Docker containers, so I am moving the RPM generator in its own file.

@giuseppe
Copy link
Collaborator Author

@TomasTomecek I have added some more patches to move the code to a new file.

It is not the nicest API, but it is a starting point from what I refactored out from syscontainers.py. We can clean it up incrementally with your feedbacks.

The entrypoint is generate_rpm. For the Docker part, you won't probably need the arguments that have a default value (values, installed_files, installed_files_template, rename_files).

Beside that, it makes sense to share the same structure /exports and /exports/hostfs so to keep the possibility of having the same image for Docker and for system containers.

@TomasTomecek
Copy link
Contributor

@giuseppe Thank you!

Beside that, it makes sense to share the same structure /exports and /exports/hostfs so to keep the possibility of having the same image for Docker and for system containers.

Absolutely. I want to reuse as much code as possible.

Unfortunately there is some further refactoring required: if I want to use functionality from mount.py inside rpm_host_install.py, the code halts on import loop:

Traceback (most recent call last):
  File "./atomic", line 33, in <module>
    import Atomic
  File "Atomic/__init__.py", line 3, in <module>
    from .atomic import Atomic
  File "Atomic/atomic.py", line 6, in <module>
    from .syscontainers import SystemContainers
  File "Atomic/syscontainers.py", line 17, in <module>
    from .rpm_host_install import RPMHostInstall, RPM_NAME_PREFIX
  File "Atomic/rpm_host_install.py", line 5, in <module>
    from . import mount
  File "Atomic/mount.py", line 23, in <module>
    from . import Atomic
ImportError: cannot import name Atomic

I'm not sure how to refactor it -- likely syscontainers import from atomic.py needs to be taken out.

@giuseppe
Copy link
Collaborator Author

@TomasTomecek should the Docker code be added somewhere else? I think rpm_host_install.py should not be an user of mount but that we add the should be used only for the part in common between OSTree and Docker.
As I see it, we need to add the --system-package option for Docker (which differently from OSTree, I think it should default to no, as it is expensive to mount the image each time a container is installed and probably only few containers will have /exports, or even better we add a LABEL used both by Docker and system containers so users don't need to be aware of these details), then from the Docker backend we mount the image and once it is mounted the functions from rpm_host_install.py are used.

Do you think it makes sense?

@giuseppe
Copy link
Collaborator Author

@TomasTomecek I pushed a small fixup patch that enables to do this:

diff --git a/Atomic/install.py b/Atomic/install.py
index 855f137..8527b51 100644
--- a/Atomic/install.py
+++ b/Atomic/install.py
@@ -4,6 +4,11 @@ from . import util
 from .util import add_opt
 from .syscontainers import OSTREE_PRESENT
 from Atomic.backendutils import BackendUtils
+import os
+import shutil
+from .mount import DockerMount
+from .rpm_host_install import RPMHostInstall, RPM_NAME_PREFIX
+import tempfile
 
 try:
     from . import Atomic
@@ -121,6 +126,23 @@ class Install(Atomic):
                 return self.syscontainers.install(self.image, self.name)
             be.pull_image(self.args.image, remote_image_obj, debug=self.args.debug)
             img_obj = be.has_image(self.image)
+
+
+        if self.args.system_package in ['build', 'yes']:
+            temp_dir = tempfile.mkdtemp()
+            os.makedirs(os.path.join(temp_dir, "root"))
+            m = DockerMount(os.path.join(temp_dir, "root"))
+            m.mount(self.image)
+            try:
+                origin_name, path = RPMHostInstall.generate_rpm("test", self.image, img_obj.labels, os.path.join(temp_dir, "root/rootfs/exports"), temp_dir)
+                shutil.move(path, origin_name)
+            finally:
+                m.unmount()
+                shutil.rmtree(temp_dir)
+            sys.exit(0)
+
         install_args = img_obj.get_label('INSTALL')
         if not install_args:
             return 0

Of course, this is just a proof of concept and cannot be used as it is (also should not probably stay here in install.py). Just wanted to show what we can do with the new code in common.

@giuseppe giuseppe force-pushed the generate-rpm-fixes branch 2 times, most recently from 306df1b to 6a909f7 Compare March 27, 2017 21:53
@giuseppe
Copy link
Collaborator Author

There are a few fixes that are nice to have as soon as possible and would be nice to have before #952. Is this ready to 🚢?

@TomasTomecek
Copy link
Contributor

@giuseppe Thank you, that diff was very helpful! I opened #955, feel free to take a look once you have time.

@giuseppe
Copy link
Collaborator Author

@TomasTomecek thanks for the feedback. I saw the /etc related fix, that is indeed a good thing to have. Though, let's keep working on the new PR you have opened, and if there are no blockers let's merge this PR. It will also help @ashcrow and me for the oneshot feature in system containers

@giuseppe giuseppe force-pushed the generate-rpm-fixes branch from 3b988a0 to 5db5263 Compare March 28, 2017 18:54
@rh-atomic-bot
Copy link

☔ The latest upstream changes (presumably 1b216a4) made this pull request unmergeable. Please resolve the merge conflicts.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the generate-rpm-fixes branch from 5db5263 to 8b20eff Compare March 28, 2017 19:31
@baude
Copy link
Member

baude commented Mar 28, 2017

looks like we need a rebase and to pass tests still ?

@giuseppe
Copy link
Collaborator Author

I rebased and now I get some weird errors, taking a look...

@giuseppe giuseppe force-pushed the generate-rpm-fixes branch from 8b20eff to a5fd3cb Compare March 28, 2017 19:56
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the generate-rpm-fixes branch 2 times, most recently from c646683 to a22fda4 Compare March 28, 2017 21:22
@giuseppe
Copy link
Collaborator Author

@baude tests are passing again

@baude
Copy link
Member

baude commented Mar 29, 2017

lgtm

@baude
Copy link
Member

baude commented Mar 29, 2017

@rh-atomic-bot r+ a22fda4

@rh-atomic-bot
Copy link

⌛ Testing commit a22fda4 with merge 2981a0e...

rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Fixes this error:
AttributeError: 'bool' object has no attribute 'replace'

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
return immediately once the rpm is uninstalled as there is
nothing left on the host.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Sometimes I don't want to wait for pylint to complete.  Add a new
makefile rule that launches directly the tests suite.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Regression introduced with commit 1f67164

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Generate the RPM from the checkout of the container without requiring a
separate one.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
This let us control the IMAGE_ID from tests so we can test
upgrade/rollback more easily.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
This bug doesn't depend from the RPM generator.  Just spotted it as I
was testing install failures.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
and move it to `generate_rpm`.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Test that auto behaves like yes.  Fixed with the in place RPM build.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Refactor the RPM generation code for system containers in a new file so
that it can be shared with the Docker backend.

For fully supporting the same /exports structure we will need to add the
support for reading the manifest.json file as well, but since the Docker
backend doesn't use --set for settings of the container, preprocessing
files won't be very useful.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
rh-atomic-bot pushed a commit that referenced this pull request Mar 29, 2017
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #949
Approved by: baude
@rh-atomic-bot
Copy link

☀️ Test successful - status-redhatci
Approved by: baude
Pushing 2981a0e to master...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants