public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Benedikt Niedermayr <benbrenson89@googlemail.com>
To: isar-users@googlegroups.com
Cc: Benedikt Niedermayr <Benedikt.Niedermayr@mixed-mode.de>
Subject: [PATCH 2/6] Added API class for apt cache.
Date: Tue,  6 Feb 2018 11:09:35 +0100	[thread overview]
Message-ID: <1517911779-30507-3-git-send-email-Benedikt.Niedermayr@mixed-mode.de> (raw)
In-Reply-To: <1517911779-30507-1-git-send-email-Benedikt.Niedermayr@mixed-mode.de>

This class implements a simple shell based API for accessing the underlying functionality of
aptly.

Signed-off-by: Benedikt Niedermayr <Benedikt.Niedermayr@mixed-mode.de>
---
 meta/classes/apt-cache.bbclass | 235 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 235 insertions(+)
 create mode 100644 meta/classes/apt-cache.bbclass

diff --git a/meta/classes/apt-cache.bbclass b/meta/classes/apt-cache.bbclass
new file mode 100644
index 0000000..644e5a2
--- /dev/null
+++ b/meta/classes/apt-cache.bbclass
@@ -0,0 +1,235 @@
+# This software is a part of ISAR.
+# Copyright (C) 2017-2018 Mixed-Mode GmbH
+#
+# This class implements common functionality for the isar apt cache.
+
+
+
+SNAPSHOT_BASENAME="repo-snapshot"
+MIRROR_SNAPSHOT_BASENAME="mirror-snapshot"
+
+ISAR_REPO = "${DEBDISTRONAME}-repo-local"
+
+ISAR_REPO_PREFIX = "${DEBDISTRONAME}"
+ISAR_MIRROR_PREFIX = "${DEBDISTRONAME}-mirror"
+
+MIRROR = "${DEBDISTRONAME}"
+MIRROR_SECURITY = "${DEBDISTRONAME}-security"
+MIRROR_UPDATES = "${DEBDISTRONAME}-updates"
+
+CACHE_CONF_DIR = "${TOPDIR}/apt-cache/${DISTRO}/conf"
+CHROOT_CACHE_DIR = "/isar-apt"
+CFG_FILE = "${CACHE_CONF_DIR}/aptly.conf"
+ISAR_FIRST_BUILD_DONE = "${CACHE_CONF_DIR}/isar_first_build_done"
+
+# Reproducible build is turned on per default
+REPRODUCIBLE_BUILD_ENABLED ?= "1"
+
+
+# Setup a new empty debian mirror.
+# $1: The filter for delimiting packages
+# $2: Mirror
+# $3: Remote URL
+# $4: Suite
+mirror_create() {
+    aptly -config=${CFG_FILE} \
+          mirror create \
+          -architectures="${DISTRO_ARCH}" \
+          -filter="$1" \
+          -filter-with-deps \
+          $2 $3 $4
+}
+
+
+# Update a mirror, which may result in downloading new packages
+# $1: Mirror
+mirror_update() {
+    aptly -config=${CFG_FILE} mirror update $1
+}
+
+
+# Create a snapshot from a given mirror.
+# $1: Snapshot name.
+# $2: Mirror
+snapshot_create_from_mirror() {
+    aptly -config=${CFG_FILE} snapshot create $1 from mirror $2
+}
+
+
+# Create a snapshot from a given repository database
+# $1: Snapshot name.
+snapshot_create_from_repo() {
+    aptly -config=${CFG_FILE} \
+          snapshot create \
+          $1 from repo \
+          ${ISAR_REPO}
+}
+
+
+# Rename a snapshot
+# $1: Old name.
+# $2: New name.
+snapshot_rename() {
+	aptly -config=${CFG_FILE} snapshot rename $1 $2
+}
+
+# Delete a snapshot
+# $1: Snapshot name
+snapshot_delete() {
+    aptly -config=${CFG_FILE} \
+          snapshot drop \
+          $1 || bbnote "No snapshot to delete"
+}
+
+
+# Create the actual repository for a given snapshot.
+# $1: Snapshot name.
+# $2: Publish prefix
+# $3: Distribution
+snapshot_publish() {
+    aptly -config=${CFG_FILE} \
+          publish snapshot \
+          -distribution="$3" \
+          $1 \
+          $2
+}
+
+
+# Create a new repository database for Isar generated packages.
+# $1: Repository database name
+repo_db_create() {
+    aptly -config=${CFG_FILE} \
+          repo create \
+          -component="main" \
+          -distribution="${DEBDISTRONAME}" \
+          $1
+}
+
+# Create a new repository database, but
+# use a snapshot as source.
+# $1: Repository database name.
+# $2: Snapshot name
+repo_db_create_from_snapshot() {
+    aptly -config=${CFG_FILE} \
+          repo create \
+          -component="main" \
+          -distribution="${DEBDISTRONAME}" \
+          $1 \
+          from snapshot \
+          $2
+}
+
+
+# Drop a created repository database silenty.
+repo_db_drop() {
+    aptly -config=${CFG_FILE} \
+          repo drop -force \
+          ${ISAR_REPO} || bbnote "No db to drop"
+
+}
+
+
+# Add packages to the local repository database.
+# $1: Repository database name.
+# $*: Packages to add.
+repo_db_add_package() {
+    repo=$1
+    shift
+    aptly -config=${CFG_FILE} repo add -force-replace $repo $*
+}
+
+
+# Delete packages from the repository database.
+# $1: Repository database name.
+# $*: Packages to delete.
+repo_db_delete_package() {
+    repo=$1
+    shift
+    aptly -config=${CFG_FILE} repo remove $repo $*
+}
+
+
+# Publish repository consumed by apt. This function can only be called
+# for repositories
+# $1: Repository database name
+# $2: Path Prefix
+repo_db_publish() {
+    aptly -config=${CFG_FILE} \
+          publish repo \
+          -architectures="${DISTRO_ARCH}" \
+          $1 \
+          $2
+
+}
+
+
+# Drop an already published repository.
+# $1: Path prefix
+repo_db_publish_drop() {
+    aptly -config=${CFG_FILE} \
+          publish drop \
+          ${DEBDISTRONAME} \
+          $1 || bbnote "Nothing to publish"
+}
+
+
+# Switch already published repository to new repository. This
+# will change the content of the published repository. This function
+# can only be called on published repos.
+# $1: Prefix
+cache_update_repo() {
+    aptly -config=${CFG_FILE} \
+          publish update \
+          -force-overwrite \
+          ${DEBDISTRONAME} $1
+}
+
+
+# Add packages to the isar cache.
+# $1: Repository database name
+# $2: Repository prefix
+# $*: Packages to add
+cache_add_package() {
+    repo=$1
+    prefix=$2
+    shift 2
+    repo_db_add_package $repo $*
+    cache_update_repo $prefix
+}
+
+
+# Delete a package from the apt cache.
+# This function is used to be called within do_clean(all) task.
+# $1: Repository database name
+# $2: Repository prefix
+# $*: Packages to delete
+cache_delete_package() {
+    repo=$1
+    prefix=$2
+    shift 2
+    repo_db_delete_package $repo $*
+    cache_update_repo $prefix
+}
+
+
+# Create a snapshot, from current repository state
+cache_create_repo_snapshot() {
+    repo_db_publish_drop ${ISAR_REPO_PREFIX}
+    snapshot_delete ${SNAPSHOT_BASENAME}_${MACHINE}
+    snapshot_create_from_repo ${SNAPSHOT_BASENAME}_${MACHINE}
+    repo_db_publish ${ISAR_REPO} ${ISAR_REPO_PREFIX}
+}
+
+# Load the last snapshot and publish it
+cache_load_snapshot() {
+    last_snapshot=$(aptly --config=${CFG_FILE} --raw -sort=time snapshot list | grep "$1" | tail -n 1)
+
+    if [ -z "$last_snapshot" ]; then
+        bbfatal "Requesting snapshot which has never been created. Repository may be in a inconsistent state. Totally new and clean build required."
+    fi
+    bbplain "Loading last snapshot: $last_snapshot"
+    repo_db_publish_drop ${ISAR_REPO_PREFIX}
+    repo_db_drop
+    repo_db_create_from_snapshot ${ISAR_REPO} ${SNAPSHOT_BASENAME}_${MACHINE}
+    repo_db_publish ${ISAR_REPO} ${ISAR_REPO_PREFIX}
+}
-- 
2.7.4


  parent reply	other threads:[~2018-02-06 10:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-06 10:09 [PATCH 0/6] Local apt cache with aptly Benedikt Niedermayr
2018-02-06 10:09 ` [PATCH 1/6] Implement support for setting up the local apt mirror and isar repository " Benedikt Niedermayr
2018-02-06 10:09 ` Benedikt Niedermayr [this message]
2018-02-06 10:09 ` [PATCH 3/6] Added apt-cache functionality for buildchroot Benedikt Niedermayr
2018-02-06 10:09 ` [PATCH 4/6] Added apt-cache functionality for image rootfs Benedikt Niedermayr
2018-02-06 10:09 ` [PATCH 5/6] Added do_finalize_image task Benedikt Niedermayr
2018-02-06 10:09 ` [PATCH 6/6] Added support for installing isar packages to local isar repository Benedikt Niedermayr
2018-02-06 12:39 ` [PATCH 0/6] Local apt cache with aptly Jan Kiszka
2018-02-06 13:28   ` Jan Kiszka
2018-02-06 14:03     ` Benedikt Niedermayr
2018-02-06 14:26       ` Hombourger, Cedric
2018-02-06 13:00 ` Jan Kiszka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1517911779-30507-3-git-send-email-Benedikt.Niedermayr@mixed-mode.de \
    --to=benbrenson89@googlemail.com \
    --cc=Benedikt.Niedermayr@mixed-mode.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox