From 66d7551e3b7c1c9e4c6f8e34a50e4a5711c95611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Sch=C3=A4fer?= Date: Fri, 26 Jan 2024 21:52:07 +0100 Subject: [PATCH] Drop build-deb support Building a debian package from a given oci container using the debbuild tool was an extra helper command to turn a container into a package. However, flake-pilot should not have this responsibility and if it should provide it, it should be done with the native tools from the respective distribution. --- .bumpversion.cfg | 2 - Makefile | 4 - doc/flake-ctl-podman-build-deb.rst | 83 ----------- doc/flake-ctl.rst | 2 +- flake-ctl/debbuild/container.spec.in | 82 ----------- flake-ctl/debbuild/oci-deb | 207 --------------------------- flake-ctl/src/cli.rs | 23 --- flake-ctl/src/deb.rs | 111 -------------- flake-ctl/src/defaults.rs | 4 - flake-ctl/src/main.rs | 5 - package/flake-pilot.spec | 24 ---- 11 files changed, 1 insertion(+), 546 deletions(-) delete mode 100644 doc/flake-ctl-podman-build-deb.rst delete mode 100644 flake-ctl/debbuild/container.spec.in delete mode 100755 flake-ctl/debbuild/oci-deb delete mode 100644 flake-ctl/src/deb.rs diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 535ee31..e91566a 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -13,6 +13,4 @@ tag = True [bumpversion:file:flake-ctl/Cargo.toml] -[bumpversion:file:flake-ctl/debbuild/oci-deb] - [bumpversion:file:firecracker-pilot/guestvm-tools/sci/Cargo.toml] diff --git a/Makefile b/Makefile index b0e10ed..439b5d1 100644 --- a/Makefile +++ b/Makefile @@ -109,10 +109,6 @@ install: $(DESTDIR)$(SBINDIR)/sci install -m 755 target/release/flake-ctl \ $(DESTDIR)$(BINDIR)/flake-ctl - install -m 755 flake-ctl/debbuild/oci-deb \ - $(DESTDIR)$(BINDIR)/oci-deb - install -m 644 flake-ctl/debbuild/container.spec.in \ - $(DESTDIR)$(SHAREDIR)/container.spec.in install -m 644 flake-ctl/template/container-flake.yaml \ $(DESTDIR)$(TEMPLATEDIR)/container-flake.yaml install -m 644 flake-ctl/template/firecracker-flake.yaml \ diff --git a/doc/flake-ctl-podman-build-deb.rst b/doc/flake-ctl-podman-build-deb.rst deleted file mode 100644 index beabafa..0000000 --- a/doc/flake-ctl-podman-build-deb.rst +++ /dev/null @@ -1,83 +0,0 @@ -FLAKE-CTL-PODMAN-BUILD-DEB(8) -============================= - -NAME ----- - -**flake-ctl podman build-deb** - Build debian package from OCI image - -SYNOPSIS --------- - -.. code:: bash - - USAGE: - flake-ctl podman build-deb [OPTIONS] --oci --repo - - OPTIONS: - --app ... - --oci - --repo - -DESCRIPTION ------------ - -The build-deb command takes an OCI tar container and packages it into a debian (.deb) -package. The produced package will be placed into a local debian repository such -that tools like **apt** can consume it. If provided via the **--app** option, the -package provides post install and removal scripts which registers/removes the -application for the container at install/uninstall time of the package. - -OPTIONS -------- - ---app ... - - An absolute path to the application on the host - and optional absolute path to the application in the - container. The path spec is separated by a semicolon. - This option can be specified multiple times. - - For example: - - --app /usr/bin/myapp;/usr/bin/ls - - Registers /usr/bin/myapp and calls /usr/bin/ls inside - - --app /usr/bin/aws;/ - - Registers /usr/bin/aws and calls the default entrypoint - ---oci - - OCI image to load into local podman registry - ---repo - - Output directory to store package(s) as local debian repository - -FILES ------ - -* /usr/share/podman-pilot/container.spec.in -* /usr/bin/oci-deb - -EXAMPLE -------- - -.. code:: bash - - $ flake-ctl podman build-deb --oci SOME.docker.tar \ - --repo ${HOME}/localrepo \ - --app /usr/bin/myapp - -AUTHOR ------- - -Marcus Schäfer - -COPYRIGHT ---------- - -(c) 2022, Elektrobit Automotive GmbH -(c) 2023, Marcus Schäfer diff --git a/doc/flake-ctl.rst b/doc/flake-ctl.rst index 761b30b..760507d 100644 --- a/doc/flake-ctl.rst +++ b/doc/flake-ctl.rst @@ -41,7 +41,7 @@ registration process. SEE ALSO -------- -podman-pilot(8), flake-ctl-podman-build-deb(8), flake-ctl-list(8), flake-ctl-podman-load(8), flake-ctl-podman-register(8), flake-ctl-podman-remove(8), firecracker-pilot(8), flake-ctl-firecracker-load(8), flake-ctl-firecracker-register(8), flake-ctl-firecracker-remove(8) +podman-pilot(8), flake-ctl-list(8), flake-ctl-podman-load(8), flake-ctl-podman-register(8), flake-ctl-podman-remove(8), firecracker-pilot(8), flake-ctl-firecracker-load(8), flake-ctl-firecracker-register(8), flake-ctl-firecracker-remove(8) AUTHOR ------ diff --git a/flake-ctl/debbuild/container.spec.in b/flake-ctl/debbuild/container.spec.in deleted file mode 100644 index 08d92f8..0000000 --- a/flake-ctl/debbuild/container.spec.in +++ /dev/null @@ -1,82 +0,0 @@ -# -# spec.in file for makedeb -# -# Copyright (c) 2022 Elektrobit Automotive GmbH -# Copyright (c) 2023 Marcus Schäfer -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# -Url: https://github.com/OSInside/kiwi -Name: __NAME__ -Summary: Package with __CONTAINER_NAME__:__TAG_VERSION__ OCI image -Version: __VERSION__ -Release: 0 -Group: System/Management -License: MIT -Source0: __SOURCE0__ -Requires: podman -Requires: flake-pilot -BuildRoot: %{_tmppath}/%{name}-%{version}-build -%if "%{_vendor}" == "debbuild" -Packager: NautilOS Team -%endif -BuildArch: __ARCH__ - -%description -This package contains __CONTAINER_NAME__ __TAG_VERSION__ OCI image. - -%prep - -%build - -%install -install -d -m 755 $RPM_BUILD_ROOT%{_datadir}/kiwi-images/native -install -p -D -m 644 %{SOURCE0} $RPM_BUILD_ROOT%{_datadir}/kiwi-images/native/ -ln -s ./$(basename %{SOURCE0}) $RPM_BUILD_ROOT%{_datadir}/kiwi-images/native/__NAME__ - -%clean -rm -rf $RPM_BUILD_ROOT - -%post -#!/bin/sh -if [ -f "/usr/bin/flake-ctl" ]; then - /usr/bin/flake-ctl podman load --oci /usr/share/kiwi-images/native/__SOURCE0_BASENAME__ - for entry in $(echo "__CONTAINER_APPS__" | tr "," " ");do - app=$(echo $entry | cut -f1 -d\;) - target=$(echo $entry | cut -f2 -d\;) - test -z "$target" && target=$app - /usr/bin/flake-ctl podman register --app $app --target $target --container __CONTAINER_NAME__ - done -fi - -%preun -#!/bin/sh -if [ -f "/usr/bin/flake-ctl" ]; then - /usr/bin/flake-ctl podman remove --container __CONTAINER_NAME__ - for entry in $(echo "__CONTAINER_APPS__" | tr "," " ");do - app=$(echo $entry | cut -f1 -d\;) - /usr/bin/flake-ctl podman remove --app $app - done -fi - -%files -%defattr(-, root, root) -%{_datadir}/kiwi-images/native - -%changelog diff --git a/flake-ctl/debbuild/oci-deb b/flake-ctl/debbuild/oci-deb deleted file mode 100755 index 4cfce85..0000000 --- a/flake-ctl/debbuild/oci-deb +++ /dev/null @@ -1,207 +0,0 @@ -#!/bin/bash -# Copyright (c) 2022 Elektrobit Automotive GmbH -# Copyright (c) 2023 Marcus Schäfer -# -# This file is part of flake-pilot -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# -set -e - -SPEC_IN=/usr/share/podman-pilot/container.spec.in -PKG_VERSION=3.0.7 -CONTAINER_TAG=latest -CONTAINER_APPS="" - -ARGUMENT_LIST=( - "description:" - "apps:" - "oci:" - "repo:" - "arch:" -) - -# read arguments -if ! opts=$(getopt \ - --longoptions "$(printf "%s," "${ARGUMENT_LIST[@]}")" \ - --name "$(basename "$0")" \ - --options "" \ - -- "$@" -); then - echo "makespec-kiwi" - echo " --oci " - echo " path to OCI container tar file" - echo - echo " --arch " - echo " package architecture" - echo - echo " --repo " - echo " output directory to store package(s)" - echo " as local repository" - echo - echo " --description " - echo " path to KIWI XML description file. If not" - echo " specified default values will apply to the" - echo " following settings:" - echo - echo " - version = ${PKG_VERSION}" - echo " - tag = ${CONTAINER_TAG}" - echo " - name = (basename from OCI tar filename)" - echo - echo " --apps " - echo " register provided app paths. In case the app" - echo " registration is provided with the KIWI XML" - echo " description, this option has no meaning" - exit 1 -fi - -eval set --"${opts}" - -while [[ $# -gt 0 ]]; do - case "$1" in - --description) - argDescription=$2 - shift 2 - ;; - - --oci) - argSource=$2 - shift 2 - ;; - - --apps) - argApps=$2 - shift 2 - ;; - - --repo) - argRepo=$2 - shift 2 - ;; - - --arch) - argArch=$2 - shift 2 - ;; - - *) - break - ;; - esac -done - -# validate arguments -if [ -z "${argSource}" ];then - echo "No OCI tar file specified, use --oci" - exit 1 -fi - -if [ -z "${argArch}" ];then - argArch="$(uname -m)" -fi - -if [ ! -f "${argSource}" ];then - echo "No OCI tar file found, expected: ${argSource}" - exit 1 -fi - -if [ -z "${argRepo}" ];then - echo "No output repo path specified, use --repo" - exit 1 -fi - -if [ -e "${argRepo}" ];then - echo "Warning: Specified output repo path ${argRepo} already exists" -fi - -if [ ! -f "${SPEC_IN}" ];then - echo "No spec template found, expected: ${SPEC_IN}" - exit 1 -fi - -# setup data variables to replace placeholders in spec file -CONTAINER_BASE=$(basename "${argSource}") -CONTAINER_NAME=$( - tar -axf "${argSource}" manifest.json -O \ - | sed -e s"@.*RepoTags\":\[\"\(.*\):.*@\1@" | cut -f1 -d: -) -# exit if CONTAINER_NAME was not found -test -n "${CONTAINER_NAME}" - -CONTAINER_FILE_FRIENDLY_NAME=$(echo "${CONTAINER_NAME}" | tr / _) - -if [ -n "${argDescription}" ];then - if [ ! -f "${argDescription}" ];then - echo "No image description found, expected: ${argDescription}" - exit 1 - fi - PKG_VERSION=$( - xmllint --xpath "string(//image/preferences/version)" \ - "${argDescription}" - ) - CONTAINER_TAG=$( - xmllint --xpath "string(//image/preferences/type/containerconfig/@tag)" \ - "${argDescription}" - ) - CONTAINER_APP_REG=$( - xmllint --xpath "string(//image/description/specification)" \ - "${argDescription}" - ) - CONTAINER_APPS=$(echo "${CONTAINER_APP_REG}" | cut -f3 -d:) -fi - -if [ -z "${CONTAINER_APPS}" ] && [ -n "${argApps}" ];then - CONTAINER_APPS=${argApps} -fi - -# create debbuild dir structure in HOME -for dir in BUILD DEBS SOURCES; do - mkdir -p "${HOME}/debbuild/${dir}" -done - -# copy OCI source -cp "${argSource}" "${HOME}/debbuild/SOURCES" - -# create specfile from template -sed \ - -e "s/__NAME__/oci-$CONTAINER_FILE_FRIENDLY_NAME/g" \ - -e "s/__VERSION__/$PKG_VERSION/g" \ - -e "s/__SOURCE0__/$CONTAINER_BASE/g" \ - -e "s/__TAG_VERSION__/$CONTAINER_TAG/g" \ - -e "s@__CONTAINER_NAME__@$CONTAINER_NAME@g" \ - -e "s@__CONTAINER_APPS__@$CONTAINER_APPS@g" \ - -e "s/__SOURCE0_BASENAME__/$CONTAINER_BASE/g" \ - -e "s/__ARCH__/$argArch/g" \ -< "${SPEC_IN}" > "${HOME}/debbuild/SOURCES/container.spec" - -# build package -debbuild -bb \ - --define "_srcdefattr (-,root,root)" -vv \ -"${HOME}/debbuild/SOURCES/container.spec" - -# extract packages to repo -mkdir -p "${argRepo}" -rsync -a "${HOME}"/debbuild/DEBS/ "${argRepo}" -rm -rf "${HOME}/debbuild" - -# create repo metadata -pushd "${argRepo}" -dpkg-scanpackages -m . > Packages -gzip --force --keep Packages -popd diff --git a/flake-ctl/src/cli.rs b/flake-ctl/src/cli.rs index 79dbec3..6996d60 100644 --- a/flake-ctl/src/cli.rs +++ b/flake-ctl/src/cli.rs @@ -298,29 +298,6 @@ pub enum Podman { #[clap(long)] info: bool, }, - /// Build container package - BuildDeb { - /// OCI image to load into local podman registry - #[clap(long)] - oci: String, - - /// An absolute path to the application on the host - /// and optional absolute path to the application in the - /// container. The path spec is separated by a semicolon. - /// This option can be specified multiple times. - #[clap(long, multiple = true)] - app: Vec, - - /// Output directory to store package(s) as - /// local debian repository - #[clap(long)] - repo: String, - - /// Package BuildArch architecture - /// If not specified it will be taken from uname -m - #[clap(long)] - arch: Option, - } } pub fn parse_args() -> Cli { diff --git a/flake-ctl/src/deb.rs b/flake-ctl/src/deb.rs deleted file mode 100644 index 178749a..0000000 --- a/flake-ctl/src/deb.rs +++ /dev/null @@ -1,111 +0,0 @@ -// -// Copyright (c) 2022 Elektrobit Automotive GmbH -// Copyright (c) 2023 Marcus Schäfer -// -// This file is part of flake-pilot -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -use std::process::Command; -use std::path::Path; -use std::fs; -use crate::defaults; - -pub fn ocideb( - oci: &String, repo: &String, apps: &Vec, arch: Option<&String> -) -> i32 { - /*! - Call oci-deb to create a debian package from the given OCI - container tar including flake-ctl app registration hooks - !*/ - let mut status_code = 255; - - if ! Path::new(defaults::OCIDEB).exists() { - error!("{} not found, please install the {} package", - defaults::OCIDEB, defaults::OCIDEB_PACKAGE - ); - return 1; - } - - info!("Transforming OCI image to deb..."); - - if Path::new(repo).exists() { - warn!("Repo {} already exists, data gets overwritten or added", repo); - } - - let mut oci_deb = Command::new(defaults::OCIDEB); - oci_deb - .arg("--oci") - .arg(oci) - .arg("--repo") - .arg(repo); - - if ! apps.is_empty() { - let apps_string = apps.join(","); - oci_deb - .arg("--apps") - .arg(&apps_string); - } - - if let Some(arch) = arch { - oci_deb.arg("--arch").arg(arch); - } - - info!("oci-deb {:?}", oci_deb); - - match oci_deb.output() { - Ok(output) => { - status_code = output.status.code().unwrap(); - if ! output.status.success() { - error!( - "Failed, error message(s) reported as: {}", - String::from_utf8_lossy(&output.stderr) - ); - } else { - info!("Successfully created package repository at: {}", repo); - info!("Following packages are available:"); - let mut packages: Vec<_> = fs::read_dir(repo) - .unwrap().map(|r| r.unwrap()).collect(); - packages.sort_by_key(|entry| entry.path()); - for filename in packages { - let package = format!("{}", filename.path().display()); - if package.ends_with(".deb") { - info!("--> {}", package); - } - } - let mut kiwi_repo = String::new(); - kiwi_repo.push_str("\n\n"); - kiwi_repo.push_str( - &format!(" \n", repo) - ); - kiwi_repo.push_str(""); - info!("For use with KIWI add the repo as follows:\n{}", - kiwi_repo - ); - } - } - Err(output) => { - error!("Process terminated({}): {}", defaults::OCIDEB, output) - } - } - - status_code -} diff --git a/flake-ctl/src/defaults.rs b/flake-ctl/src/defaults.rs index 82032d8..7978ffd 100644 --- a/flake-ctl/src/defaults.rs +++ b/flake-ctl/src/defaults.rs @@ -28,10 +28,6 @@ pub const PODMAN_PILOT: &str = "/usr/bin/podman-pilot"; pub const FIRECRACKER_PILOT: &str = "/usr/bin/firecracker-pilot"; -pub const OCIDEB: &str = - "/usr/bin/oci-deb"; -pub const OCIDEB_PACKAGE: &str = - "oci-deb"; pub const PODMAN_PATH:&str = "/usr/bin/podman"; pub const FLAKE_TEMPLATE_CONTAINER:&str = diff --git a/flake-ctl/src/main.rs b/flake-ctl/src/main.rs index 97dc940..0f98661 100644 --- a/flake-ctl/src/main.rs +++ b/flake-ctl/src/main.rs @@ -32,7 +32,6 @@ pub mod cli; pub mod podman; pub mod firecracker; pub mod app; -pub mod deb; pub mod app_config; pub mod defaults; pub mod fetch; @@ -193,10 +192,6 @@ async fn main() -> Result> { ); } } - // build deb - cli::Podman::BuildDeb { oci, app, repo, arch } => { - exit(deb::ocideb(oci, repo, app, arch.as_ref())); - } } }, } diff --git a/package/flake-pilot.spec b/package/flake-pilot.spec index 8704cdf..d8836a9 100644 --- a/package/flake-pilot.spec +++ b/package/flake-pilot.spec @@ -67,25 +67,6 @@ to a launcher binary which actually launches the application through a runtime engine like podman. Along with the launcher there is also a control tool to register an application as a flake application -%package -n oci-deb -Summary: Build flake-pilot compliant debian package from OCI container image -Group: System/Management -%if 0%{?debian} || 0%{?ubuntu} -Requires: libxml2-utils -%else -Requires: libxml2-tools -%endif -Requires: rsync -Requires: dpkg -Requires: dpkg-dev -Requires: debbuild - -%description -n oci-deb -Provides oci-deb utility which uses debbuild and dpkg to create -a debian package from a given OCI image file. The created debian -package hooks into the flake-pilot registration mechanism to run -containerized applications. - %package -n flake-pilot-podman Summary: Podman pilot Group: System/Management @@ -190,7 +171,6 @@ install -m 644 flakes.yml %{buildroot}/etc/flakes.yml %config /etc/flakes/container-flake.yaml /usr/bin/podman-pilot /usr/sbin/flake-registry -%doc /usr/share/man/man8/flake-ctl-podman-build-deb.8.gz %doc /usr/share/man/man8/flake-ctl-podman-load.8.gz %doc /usr/share/man/man8/flake-ctl-podman-pull.8.gz %doc /usr/share/man/man8/flake-ctl-podman-register.8.gz @@ -223,7 +203,3 @@ install -m 644 flakes.yml %{buildroot}/etc/flakes.yml %dir /overlayroot /usr/sbin/sci %doc /usr/share/man/man8/sci.8.gz - -%files -n oci-deb -/usr/share/podman-pilot -/usr/bin/oci-deb