Skip to content

Commit

Permalink
Support Flatpak preinstallation as part of a DNF install
Browse files Browse the repository at this point in the history
Add new functionality for running Flatpak preinstallation after
installing the base system. It's initially implemented only for
the DNF payload.

Flatpak installation is done as an extra "side" payload that the
payloads service calls after the base payload to install
additional content. The base payload provides the list of
Flatpak refs that should be installed from the side payload
and the Flatpaks are installed from a location that is determined
from the base payload's primary source - if the source is a local or
remote install tree we look for a OCI image layout there, if the
base payload is the network (CDN, closest mirror), we install directly
from the configured Flatpak remote.

For http/ftp payloads we mirror the OCI image layout locally
before runing the installation.
  • Loading branch information
owtaylor committed Dec 17, 2024
1 parent b737e31 commit f2f1cb2
Show file tree
Hide file tree
Showing 17 changed files with 1,094 additions and 2 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ AC_CONFIG_FILES([Makefile
pyanaconda/modules/payloads/Makefile
pyanaconda/modules/payloads/payload/Makefile
pyanaconda/modules/payloads/payload/dnf/Makefile
pyanaconda/modules/payloads/payload/flatpak/Makefile
pyanaconda/modules/payloads/payload/live_os/Makefile
pyanaconda/modules/payloads/payload/live_image/Makefile
pyanaconda/modules/payloads/payload/rpm_ostree/Makefile
Expand Down
1 change: 1 addition & 0 deletions pyanaconda/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ class DisplayModes(Enum):

# Types of the payload.
PAYLOAD_TYPE_DNF = "DNF"
PAYLOAD_TYPE_FLATPAK = "FLATPAK"
PAYLOAD_TYPE_LIVE_OS = "LIVE_OS"
PAYLOAD_TYPE_LIVE_IMAGE = "LIVE_IMAGE"
PAYLOAD_TYPE_RPM_OSTREE = "RPM_OSTREE"
Expand Down
5 changes: 5 additions & 0 deletions pyanaconda/modules/common/constants/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
basename="DNF"
)

PAYLOAD_FLATPAK = DBusInterfaceIdentifier(
namespace=PAYLOAD_NAMESPACE,
basename="FLATPAK"
)

PAYLOAD_LIVE_IMAGE = DBusInterfaceIdentifier(
namespace=PAYLOAD_NAMESPACE,
basename="LiveImage"
Expand Down
3 changes: 2 additions & 1 deletion pyanaconda/modules/payloads/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from enum import Enum, unique, auto

from pyanaconda.core.constants import \
PAYLOAD_TYPE_DNF, PAYLOAD_TYPE_LIVE_OS, PAYLOAD_TYPE_LIVE_IMAGE, \
PAYLOAD_TYPE_DNF, PAYLOAD_TYPE_FLATPAK, PAYLOAD_TYPE_LIVE_OS, PAYLOAD_TYPE_LIVE_IMAGE, \
SOURCE_TYPE_LIVE_OS_IMAGE, SOURCE_TYPE_HMC, SOURCE_TYPE_CDROM, SOURCE_TYPE_REPO_FILES, \
SOURCE_TYPE_REPO_PATH, SOURCE_TYPE_NFS, SOURCE_TYPE_URL, SOURCE_TYPE_HDD, SOURCE_TYPE_CDN, \
SOURCE_TYPE_CLOSEST_MIRROR, PAYLOAD_TYPE_RPM_OSTREE, \
Expand All @@ -37,6 +37,7 @@
class PayloadType(Enum):
"""Type of the payload."""
DNF = PAYLOAD_TYPE_DNF
FLATPAK = PAYLOAD_TYPE_FLATPAK
LIVE_OS = PAYLOAD_TYPE_LIVE_OS
LIVE_IMAGE = PAYLOAD_TYPE_LIVE_IMAGE
RPM_OSTREE = PAYLOAD_TYPE_RPM_OSTREE
Expand Down
2 changes: 1 addition & 1 deletion pyanaconda/modules/payloads/payload/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

SUBDIRS = dnf live_os live_image rpm_ostree
SUBDIRS = dnf flatpak live_os live_image rpm_ostree

pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME)
dnf_moduledir = $(pkgpyexecdir)/modules/payloads/payload
Expand Down
10 changes: 10 additions & 0 deletions pyanaconda/modules/payloads/payload/dnf/dnf.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,16 @@ def calculate_required_space(self):
self._dnf_manager.get_installation_size())
return required_space.get_bytes()

def needs_flatpak_side_payload(self):
return True

def get_flatpak_refs(self):
"""Get the list of Flatpak refs to install.
:return: list of Flatpak refs
"""
return self._dnf_manager.get_flatpak_refs()

def get_repo_configurations(self):
"""Get RepoConfiguration structures for all sources.
Expand Down
15 changes: 15 additions & 0 deletions pyanaconda/modules/payloads/payload/dnf/dnf_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Red Hat, Inc.
#
import multiprocessing
import re
import shutil
import threading
import traceback
Expand Down Expand Up @@ -582,6 +583,20 @@ def resolve_selection(self):
log.info("The software selection has been resolved (%d packages selected).",
len(self._base.transaction))

def get_flatpak_refs(self):
"""Determine what Flatpaks need to be preinstalled based on resolved transaction"""
if self._base.transaction is None:
return []

refs = []
for tsi in self._base.transaction:
for provide in tsi.pkg.provides:
m = re.match(r"^flatpak-preinstall\((.*)\)$", str(provide))
if m:
refs.append(m.group(1))

return refs

def clear_selection(self):
"""Clear the software selection."""
self._base.reset(goal=True)
Expand Down
4 changes: 4 additions & 0 deletions pyanaconda/modules/payloads/payload/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ def create_payload(payload_type: PayloadType):
from pyanaconda.modules.payloads.payload.rpm_ostree.rpm_ostree import RPMOSTreeModule
return RPMOSTreeModule()

if payload_type == PayloadType.FLATPAK:
from pyanaconda.modules.payloads.payload.flatpak.flatpak import FlatpakModule
return FlatpakModule()

raise ValueError("Unknown payload type: {}".format(payload_type))

@classmethod
Expand Down
21 changes: 21 additions & 0 deletions pyanaconda/modules/payloads/payload/flatpak/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (C) 2019 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME)
flatpak_moduledir = $(pkgpyexecdir)/modules/payloads/payload/flatpak
dist_flatpak_module_DATA = $(wildcard $(srcdir)/*.py)

MAINTAINERCLEANFILES = Makefile.in
Empty file.
112 changes: 112 additions & 0 deletions pyanaconda/modules/payloads/payload/flatpak/flatpak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#
# Kickstart module for Live OS payload.
#
# Copyright (C) 2019 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.modules.common.errors.payload import IncompatibleSourceError
from pyanaconda.modules.payloads.base.utils import calculate_required_space
from pyanaconda.modules.payloads.constants import SourceType, PayloadType
from pyanaconda.modules.payloads.payload.flatpak.flatpak_manager import FlatpakManager
from pyanaconda.modules.payloads.payload.flatpak.installation import CalculateFlatpaksSizeTask, \
CleanUpDownloadLocationTask, DownloadFlatpaksTask, InstallFlatpaksTask, \
PrepareDownloadLocationTask
from pyanaconda.modules.payloads.payload.payload_base import PayloadBase
from pyanaconda.modules.payloads.payload.flatpak.flatpak_interface import FlatpakInterface

from pyanaconda.anaconda_loggers import get_module_logger
log = get_module_logger(__name__)


class FlatpakModule(PayloadBase):
"""The Flatpak payload module."""

def __init__(self):
super().__init__()
self._flatpak_manager = FlatpakManager()

def for_publication(self):
"""Get the interface used to publish this source."""
return FlatpakInterface(self)

@property
def type(self):
"""Type of this payload."""
return PayloadType.FLATPAK

@property
def default_source_type(self):
"""Type of the default source."""
return None

@property
def supported_source_types(self):
"""List of supported source types."""
# Include all the types of SourceType.
return list(SourceType)

def set_sources(self, sources):
"""Set a new list of sources to this payload.
This overrides the base implementation since the sources we set here
are the sources from the main payload, and can already be initialized.
:param sources: set a new sources
:type sources: instance of pyanaconda.modules.payloads.source.source_base.PayloadSourceBase
"""
self._sources = sources
self._flatpak_manager.set_sources(sources)
self.sources_changed.emit()

def set_flatpak_refs(self, refs):
"""Set the flatpak refs.
:param refs: a list of flatpak refs
"""
self._flatpak_manager.set_flatpak_refs(refs)

def calculate_required_space(self):
"""Calculate space required for the installation.
:return: required size in bytes
:rtype: int
"""
return calculate_required_space(self._flatpak_manager.download_size,
self._flatpak_manager.install_size)

def install_with_tasks(self):
"""Install the payload with tasks."""

tasks = [
CalculateFlatpaksSizeTask(
flatpak_manager=self._flatpak_manager,
),
PrepareDownloadLocationTask(
flatpak_manager=self._flatpak_manager,
),
DownloadFlatpaksTask(
flatpak_manager=self._flatpak_manager,
),
InstallFlatpaksTask(
flatpak_manager=self._flatpak_manager,
),
CleanUpDownloadLocationTask(
flatpak_manager=self._flatpak_manager,
),
]

return tasks
28 changes: 28 additions & 0 deletions pyanaconda/modules/payloads/payload/flatpak/flatpak_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# DBus interface for Flatpak payload.
#
# Copyright (C) 2024 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
from dasbus.server.interface import dbus_interface

from pyanaconda.modules.common.constants.interfaces import PAYLOAD_FLATPAK
from pyanaconda.modules.payloads.payload.payload_base_interface import PayloadBaseInterface


@dbus_interface(PAYLOAD_FLATPAK.interface_name)
class FlatpakInterface(PayloadBaseInterface):
"""DBus interface for Flatpak payload module."""
Loading

0 comments on commit f2f1cb2

Please sign in to comment.