From 2d3ea795fa8fc5d0b5efb76eb6c8561928b43a3a Mon Sep 17 00:00:00 2001 From: Drew Walters Date: Mon, 14 Jan 2019 12:24:17 -0600 Subject: [PATCH] mini-mirror: Add support for multi-dist publishing Currently, mini-mirror combines all source distributions into a single distribution and component when publishing. This commit changes the publishing behavior of mini-mirror to separate distributions and components for all published mirrors. Change-Id: Ib32a2adbb6d053a798d97eedb66e272c8961581d --- mini-mirror/README.rst | 18 +++-- .../aptly-example/{ => squeeze}/packages.txt | 0 .../aptly-example/{ => squeeze}/source.txt | 0 mini-mirror/tools/publish_snapshots.sh | 81 +++++++++++-------- 4 files changed, 57 insertions(+), 42 deletions(-) rename mini-mirror/sources/aptly-example/{ => squeeze}/packages.txt (100%) rename mini-mirror/sources/aptly-example/{ => squeeze}/source.txt (100%) diff --git a/mini-mirror/README.rst b/mini-mirror/README.rst index a5693ffc..d051c48d 100644 --- a/mini-mirror/README.rst +++ b/mini-mirror/README.rst @@ -17,15 +17,20 @@ and packages that will be mirrored. .. code:: sources/ - | -- source1/ - |-- source.txt - |-- packages.txt - | -- source2/ - |-- source.txt - |-- packages.txt + | -- source1-prefix/ + |-- source-name/ + |-- source.txt + |-- packages.txt + | -- source2-prefix/ + |-- source-name/ + |-- source.txt + |-- packages.txt Sources are defined as directories containing the files: +* source-prefix - a prefix to separate sources that have conflicting + distribution names (i.e. the directory a source serves from). +* source-name - the name of a source; used for record-keeping. * source.txt - contains location and metadata information for a source. * packages.txt - contains a list of packages, formatted as `package queries `_ for a source. @@ -100,4 +105,3 @@ To build the mini-mirror image, execute the following: export DISTRO=ubuntu ./build.sh - diff --git a/mini-mirror/sources/aptly-example/packages.txt b/mini-mirror/sources/aptly-example/squeeze/packages.txt similarity index 100% rename from mini-mirror/sources/aptly-example/packages.txt rename to mini-mirror/sources/aptly-example/squeeze/packages.txt diff --git a/mini-mirror/sources/aptly-example/source.txt b/mini-mirror/sources/aptly-example/squeeze/source.txt similarity index 100% rename from mini-mirror/sources/aptly-example/source.txt rename to mini-mirror/sources/aptly-example/squeeze/source.txt diff --git a/mini-mirror/tools/publish_snapshots.sh b/mini-mirror/tools/publish_snapshots.sh index e5a9882b..503fe7c0 100755 --- a/mini-mirror/tools/publish_snapshots.sh +++ b/mini-mirror/tools/publish_snapshots.sh @@ -16,41 +16,52 @@ set -e -for source in /opt/sources/*; do - read -r -a info < "${source}"/source.txt - repo=${info[0]} - key=${info[1]} - distro=${info[2]} - components=${info[*]:3} - - # Import source key - wget --no-check-certificate -O - "${key}" | gpg --no-default-keyring \ - --keyring trustedkeys.gpg --import - - snapshots=() - while read -r package; do - snapshots+=("$package") - - # NOTE(drewwalters96): Separate snapshots by package until aptly supports - # multiple package queries for mirrors/snapshots. - aptly mirror create -filter="${package}" -filter-with-deps "${package}" \ - "${repo}" "${distro}" "${components}" - aptly mirror update "${package}" - aptly snapshot create "${package}" from mirror "${package}" - done < "${source}"/packages.txt - - # Combine package snapshots into single source snapshot - aptly snapshot merge "${source}" "${snapshots[@]}" -done - -# Combine source snapshots -read -r -a snapshots <<< "$(ls -d /opt/sources/*)" -aptly snapshot merge minimirror "${snapshots[@]}" - -# Publish snapshot if [ ! -z "$1" ]; then gpg --import /opt/release.gpg - aptly publish snapshot -batch=true -passphrase="${1}" minimirror -else - aptly publish snapshot minimirror fi + +for source_prefix in /opt/sources/*; do + for source in $source_prefix/*; do + read -r -a info < "${source}"/source.txt + repo=${info[0]} + key=${info[1]} + dist=${info[2]} + components=${info[*]:3} + + # Create package query from well-defined package list. + # + # package1 + # package2 ==> package1 | package2 | package3 + # package3 + # + packages=$(awk -v ORS=" | " '{ print $1 }' "${source}"/packages.txt) + packages="${packages::-3}" + + # Import source key + wget --no-check-certificate -O - "${key}" | gpg --no-default-keyring \ + --keyring trustedkeys.gpg --import + + # Create a mirror of each component from a source's repository, update it, + # and publish a snapshot of it. + mirrors=() + for component in $components; do + name="${source}-${component}" + mirrors+=("$name") + + aptly mirror create -filter="${packages}" -filter-with-deps \ + "${name}" "${repo}" "${dist}" "${component}" + aptly mirror update "${name}" + aptly snapshot create "${name}" from mirror "${name}" + done + + # Publish snapshot and sign if a key passphrase is provided + com_list=$(echo "${components[@]}" | tr ' ' ',') + if [ ! -z "$1" ]; then + aptly publish snapshot -component="${com_list}" -distribution="${dist}" \ + -batch=true -passphrase="${1}" "${mirrors[@]}" "${source_prefix:13}" + else + aptly publish snapshot -component="${com_list}" -distribution="${dist}" \ + "${mirrors[@]}" "${source_prefix:13}" + fi + done +done