Skip to content

Commit

Permalink
Merge branch 'release/1.19.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lueschem committed Apr 24, 2024
2 parents f37f347 + 90f3d14 commit bf8cfe5
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 32 deletions.
8 changes: 8 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
edi (1.19.0) noble; urgency=medium

[ Matthias Luescher ]
* Allow creation of buildah container based on podman image.
* Added edi_project_directory_hash to load time dictionary.

-- Matthias Lüscher (Launchpad) <m.luescher@datacomm.ch> Wed, 24 Apr 2024 19:04:09 +0200

edi (1.18.2) noble; urgency=medium

[ Matthias Luescher ]
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
# built documents.
#
# The short X.Y version.
version = '1.18.2'
release = '1.18.2'
version = '1.19.0'
release = '1.19.0'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
3 changes: 2 additions & 1 deletion edi/commands/imagecommands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import logging
from edi.commands.image import Image
from edi.commands.lxccommands.export import Export
from edi.lib.commandrunner import CommandRunner, Artifact, ArtifactType
from edi.lib.commandrunner import CommandRunner
from edi.lib.artifact import ArtifactType, Artifact
from edi.lib.configurationparser import command_context
from edi.lib.helpers import print_success

Expand Down
5 changes: 3 additions & 2 deletions edi/commands/projectcommands/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
from edi.lib.shellhelpers import run
from edi.lib.buildahhelpers import create_container, delete_container, is_container_existing
from edi.lib.configurationparser import command_context
from edi.lib.commandrunner import ArtifactType, Artifact, find_artifact
from edi.lib.commandrunner import find_artifact
from edi.lib.artifact import ArtifactType, Artifact


class Configure(Project):
Expand Down Expand Up @@ -83,7 +84,7 @@ def _run(self):

print(f"Going to create project container '{container_name}'\n"
f"based on content of '{bootstrapped_rootfs.location}'.")
create_container(container_name, bootstrapped_rootfs.location)
create_container(container_name, bootstrapped_rootfs)

seal_file = self._get_seal_artifact().location

Expand Down
12 changes: 12 additions & 0 deletions edi/lib/artifact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from collections import namedtuple
from enum import Enum


class ArtifactType(Enum):
PATH = 'path'
BUILDAH_CONTAINER = 'buildah-container'
PODMAN_IMAGE = 'podman-image' # Owned by non-root user.
PODMAN_IMAGE_ROOT = 'podman-image-root' # Owned by root.


Artifact = namedtuple("Artifact", "name, location, type")
27 changes: 20 additions & 7 deletions edi/lib/buildahhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import logging
from packaging.version import Version
from edi.lib.helpers import FatalError
from edi.lib.artifact import ArtifactType
from edi.lib.versionhelpers import get_stripped_version
from edi.lib.shellhelpers import run, Executables, require
from edi.lib.podmanhelpers import is_image_existing


buildah_install_hint = "'sudo apt install buildah'"
Expand Down Expand Up @@ -85,24 +87,35 @@ def delete_container(name):


@require('buildah', buildah_install_hint, BuildahVersion.check)
def create_container(name, rootfs_archive):
def create_container(name, source_artifact):
if is_container_existing(name):
raise FatalError(f"The container '{name}' already exists!")

if not os.path.isfile(rootfs_archive):
raise FatalError(f"The root file system archive '{rootfs_archive}' does not exist!")
if source_artifact.type == ArtifactType.PATH:
if not os.path.isfile(source_artifact.location):
raise FatalError(f"The root file system archive '{source_artifact.location}' does not exist!")
elif source_artifact.type == ArtifactType.PODMAN_IMAGE:
if not is_image_existing(source_artifact.location):
raise FatalError(f"The podman image '{source_artifact.location}' does not exist!")
else:
raise FatalError(f"Unable to create a container from '{source_artifact.type}'!")

temp_container_name = name + "-temp"

if is_container_existing(temp_container_name):
delete_container(temp_container_name)

cmd = [buildah_exec(), "--name", temp_container_name, "from", "scratch"]
run(cmd, log_threshold=logging.INFO)
if source_artifact.type == ArtifactType.PATH:
cmd = [buildah_exec(), "--name", temp_container_name, "from", "scratch"]
run(cmd, log_threshold=logging.INFO)

nested_command = "fakeroot tar --numeric-owner -C " + r'${container_root}' + " -axf " + str(rootfs_archive)
nested_command = ("fakeroot tar --numeric-owner -C " + r'${container_root}' + " -axf " +
str(source_artifact.location))

run_buildah_unshare(temp_container_name, nested_command)
run_buildah_unshare(temp_container_name, nested_command)
else:
cmd = [buildah_exec(), "--name", temp_container_name, "from", source_artifact.location]
run(cmd, log_threshold=logging.INFO)

cmd = [buildah_exec(), "rename", temp_container_name, name]
run(cmd, log_threshold=logging.INFO)
Expand Down
14 changes: 2 additions & 12 deletions edi/lib/commandrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,16 @@
import jinja2
import stat
from codecs import open
from enum import Enum
from collections import namedtuple

from edi.lib.artifact import ArtifactType, Artifact
from edi.lib.helpers import (chown_to_user, FatalError, get_workdir, get_artifact_dir,
create_artifact_dir, print_success)
from edi.lib.shellhelpers import run, safely_remove_artifacts_folder
from edi.lib.configurationparser import remove_passwords
from edi.lib.yamlhelpers import LiteralString
from edi.lib.podmanhelpers import is_image_existing, try_delete_image, untag_image


class ArtifactType(Enum):
PATH = 'path'
BUILDAH_CONTAINER = 'buildah-container'
PODMAN_IMAGE = 'podman-image' # Owned by non-root user.
PODMAN_IMAGE_ROOT = 'podman-image-root' # Owned by root.


Artifact = namedtuple("Artifact", "name, location, type")


Command = namedtuple("Command", "script_name, script_content, node_name, resolved_template_path, "
"node_dictionary, config_node, output_artifacts")

Expand Down
1 change: 1 addition & 0 deletions edi/lib/configurationparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ def _get_load_time_dictionary(self):
load_dict = get_base_dictionary()
load_dict["edi_work_directory"] = get_workdir()
load_dict["edi_project_directory"] = self.project_directory
load_dict["edi_project_directory_hash"] = self.get_project_directory_hash()
load_dict["edi_project_plugin_directory"] = self.get_project_plugin_directory()
load_dict['edi_log_level'] = logging.getLevelName(logging.getLogger().getEffectiveLevel())
load_dict['edi_configuration_name'] = self.get_configuration_name()
Expand Down
2 changes: 1 addition & 1 deletion edi/lib/versionhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

# The do_release script will update this version!
# During launchpad debuild neither the git version nor the package version is available.
edi_fallback_version = '1.18.2'
edi_fallback_version = '1.19.0'


def get_edi_version():
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
setup(
name='edi',

version='1.18.2',
version='1.19.0',

description='Embedded Development Infrastructure - edi',
long_description=long_description,
Expand Down
10 changes: 6 additions & 4 deletions tests/lib/test_buildahhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import tempfile
from contextlib import contextmanager
from edi.lib.artifact import Artifact, ArtifactType
from edi.lib.helpers import FatalError, chown_to_user
from edi.lib.buildahhelpers import (is_container_existing, get_buildah_version, BuildahVersion, create_container,
run_buildah_unshare, delete_container, extract_container_rootfs)
Expand Down Expand Up @@ -132,11 +133,11 @@ def test_buildah_container_creation(datadir):
demo_rootfs_archive = os.path.join(archive_dir, 'demo_rootfs.tar')
shutil.copyfile(os.path.join(datadir, "demo_rootfs.tar"), demo_rootfs_archive)

create_container(container_name, demo_rootfs_archive)
create_container(container_name, Artifact(name='xy', location=demo_rootfs_archive, type=ArtifactType.PATH))
assert is_container_existing(container_name)

with pytest.raises(FatalError) as error:
create_container(container_name, demo_rootfs_archive)
create_container(container_name, Artifact(name='xy', location=demo_rootfs_archive, type=ArtifactType.PATH))

assert 'already exists' in error.value.message
assert container_name in error.value.message
Expand Down Expand Up @@ -170,7 +171,7 @@ def test_buildah_rootfs_extraction(datadir):
assert 'does not exist' in error.value.message
assert container_name in error.value.message

create_container(container_name, demo_rootfs_archive)
create_container(container_name, Artifact(name='xy', location=demo_rootfs_archive, type=ArtifactType.PATH))

extract_container_rootfs(container_name, extracted_rootfs_archive)

Expand All @@ -188,7 +189,8 @@ def test_buildah_rootfs_extraction(datadir):
@pytest.mark.requires_buildah
def test_buildah_container_creation_failure():
with pytest.raises(FatalError) as error:
create_container("some-stupid-container-name", "wrong_rootfs_archive.tar")
create_container("some-stupid-container-name",
Artifact(name='xy', location="/path/to/wrong_rootfs_archive.tar", type=ArtifactType.PATH))

assert 'does not exist' in error.value.message
assert 'wrong_rootfs_archive.tar' in error.value.message
3 changes: 2 additions & 1 deletion tests/lib/test_commandrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
# along with edi. If not, see <http://www.gnu.org/licenses/>.

from edi.lib.configurationparser import ConfigurationParser
from edi.lib.commandrunner import CommandRunner, ArtifactType, Artifact
from edi.lib.commandrunner import CommandRunner
from edi.lib.artifact import ArtifactType, Artifact
from tests.libtesting.contextmanagers.workspace import workspace
from tests.libtesting.helpers import get_command, suppress_chown_during_debuild
from edi.lib import mockablerun
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/test_podmanhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import os
import logging
import shutil
from edi.lib.artifact import Artifact, ArtifactType
from edi.lib.helpers import FatalError, chown_to_user
from edi.lib.podmanhelpers import (get_podman_version, PodmanVersion, is_image_existing, try_delete_image, untag_image,
podman_exec)
Expand Down Expand Up @@ -116,7 +117,7 @@ def test_buildah_podman_workflow(datadir):
container_name = f'edi-pytest-{get_random_string(6)}'
assert not is_container_existing(container_name)

create_container(container_name, demo_rootfs_archive)
create_container(container_name, Artifact(name='xy', location=demo_rootfs_archive, type=ArtifactType.PATH))

image_name = f'edi-pytest-{get_random_string(6)}:test'.lower()

Expand Down

0 comments on commit bf8cfe5

Please sign in to comment.