Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

drpcli catalog create --pkg-version stable|tip does not produce a valid catalog #162

Open
mclamb opened this issue Feb 14, 2020 · 0 comments

Comments

@mclamb
Copy link

mclamb commented Feb 14, 2020

The implementation of drpcli catalog create --pkg-version stable|tip in the current tip version of drpcli does not create a valid catalog that can be passed to drpcli catalog updateLocal -c <catalog_just_created>. This is because drpcli catalog updateLocal only downloads content from "real" catalog items and not alias-type entries like -stable and -tip.

The following script has logic that will add the actual version entries if stable and/or tip packages are referenced:

#!/bin/bash

# Get the latest upstream catalog file updated by RackN several times per day
curl --compressed https://repo.rackn.io 2>/dev/null > rackn-catalog.json

# $package_list is just a space-delimited list of content packs and plugins that should be included in the local repository.
# Extract content packs and plugin providers from all the version sets located in content/version_sets/*.yaml
# This will create some bogus entries but they will be ignored
package_list="drp-stable drp-tip drpcli-stable drpcli-tip $(cat content/version_sets/*.yaml | egrep '\- Name:| Version:' | tr -d '^ ' | cut -d: -f2 | sed '$!N;s/\n/-/')"
# Convert to a json list, e.g.: ["bios-stable", "bios-tip"]
package_list_json=$(jq -R -s -c 'split(" ")' < <(echo -n $package_list))

# For every item in $package_list that is stable or tip make sure that we also get its ActualVersion catalog entry because that is what updateLocal uses to download content
# For tip content we use the part of the ActualVersion up to and not including the + sign
package_list_with_actual_versions=$(echo "$package_list $(jq -r --argjson keys "$package_list_json" \
  '.sections.catalog_items[] | select(.Id as $id | $keys | index($id)) | .Meta.Name+"-"+.ActualVersion' rackn-catalog.json)" | cut -d+ -f1 | sort | uniq)
# Convert to a json list, e.g.: ["bios-v4.2.7", "bios-v4.2.8"]
package_list_with_actual_versions_json=$(jq -R -s -c 'split(" ")' < <(echo -n $package_list_with_actual_versions))

# Use the entries in $package_list_with_actual_versions_json to filter the entries in .sections.catalog_items from the upstream catalog
jq --argjson keys "$package_list_with_actual_versions_json" \
  '.meta.Name="catalog" | .meta.Description="Catalog" | .meta.DisplayName="Catalog" |
  { meta: .meta,
    sections: {
      catalog_items: .sections.catalog_items | with_entries( select( .key as $k | $keys | index($k) ) )
    }
  }' rackn-catalog.json

# Cleanup
rm -f rackn-catalog.json
@mclamb mclamb changed the title drpcli catalog create --pkg-version stable|tip does not product a valid catalog drpcli catalog create --pkg-version stable|tip does not produce a valid catalog Feb 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant