Skip to content

Commit

Permalink
test: Test CI
Browse files Browse the repository at this point in the history
  • Loading branch information
MAHDTech committed Jul 21, 2023
1 parent 423db68 commit 6cbdda0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 23 deletions.
63 changes: 48 additions & 15 deletions nix/oci/tanzu/root/etc/profile.d/tanzu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -m

# Variables
export YTT_LIB="/usr/lib/ytt/"
export TANZU_CLI_PLUGIN_GROUP_TKG_VERSION="v2.3.0"

# HACK: A better method is needed.
# Check for a proxy settings script.
Expand Down Expand Up @@ -72,31 +73,63 @@ else
echo "Failed to clean the Tanzu CLI plugins"
}

# HACK: A better method is needed, perhaps interactive 'tanzu plugin source'
if [[ ${TANZU_PULL_THROUGH_CACHE:-EMPTY} == "EMPTY" ]]; then
tanzu init || {
echo "Failed to initialise the Tanzu CLI configuration"
}

echo "No pull-through prefix provided, using default."
# There are 3 options for the Tanzu CLI OCI registry in preference order:
# 1. A custom registry is provided, use it.
# 2. A pull-through cache is provided, use it.
# 3. No pull-through or custom registry is provided, pull direct from internet.

else
# If there is a custom registry, use it as priority.
if [[ ${TANZU_CUSTOM_REGISTRY:-EMPTY} != "EMPTY" ]]; then

echo "Custom registry provided, using ${TANZU_CUSTOM_REGISTRY}"

# Capture existing OCI URL
TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)"

# Strip the VMware registry prefix.
TANZU_CLI_OCI_URL="${TANZU_CLI_OCI_URL#*projects.registry.vmware.com}"

# Add the custom registry OCI URL and update the plugin cache.
TANZU_CLI_OCI_URL="${TANZU_CUSTOM_REGISTRY}${TANZU_CLI_OCI_URL}"

# Update the plugin source and test pulling the image.
tanzu plugin source update \
default \
--uri "${TANZU_CLI_OCI_URL}" || {
echo "Failed to update plugin configuration to use the provided custom registry."
}

elif [[ ${TANZU_PULL_THROUGH_CACHE:-EMPTY} != "EMPTY" ]]; then

echo "Pull-through prefix provided, prefixing ${TANZU_PULL_THROUGH_CACHE}"

# Capture existing OCI URL
TANZU_CLI_OCI_URL="$(cat "${HOME}/.config/tanzu/config.yaml" | yq '.clientOptions.cli.discoverySources.[0].oci.image')"

# Add the pull-through cache OCI URL
tanzu plugin source add \
--name pull-through-cache \
--type oci \
--uri "${TANZU_PULL_THROUGH_CACHE}/${TANZU_CLI_OCI_URL}" || {
echo "Failed to add the pull-through cache Tanzu CLI plugin source"
TANZU_CLI_OCI_URL="$(tanzu plugin source list --output yaml | yq .[].image)"

# Add the pull-through prefix
TANZU_CLI_OCI_URL="${TANZU_PULL_THROUGH_CACHE}/${TANZU_CLI_OCI_URL}"

# Add the pull-through cache OCI URL and update the plugin cache.
tanzu plugin source update \
default \
--uri "${TANZU_CLI_OCI_URL}" || {
echo "Failed to update plugin configuration to use the provided pull-through cache."
}

else

echo "No custom registry or pull-through cache provided, pulling direct from internet."

fi

tanzu init || {
echo "Failed to initialise the Tanzu CLI using configured sources."
echo "Please check network connectivity and try running 'tanzu init' again."
# Add the VMWare TKG group of plugins at the configured version to match the CLI.
tanzu plugin install \
--group vmware-tkg/default:${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION} || {
echo "Failed to install the Tanzu plugin group TKG ${TANZU_CLI_PLUGIN_GROUP_TKG_VERSION}"
}

tanzu plugin sync || {
Expand Down
17 changes: 9 additions & 8 deletions nix/oci/tanzu/tanzu.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# NOTE: Cachix push
# nix build --json --impure ".#packages.\"x86_64-linux.x86_64-linux\".tanzu" | jq -r '.[0].outputs.out' | cachix push salt-labs
{pkgs, ...}: let
product_name = "tkg";
product_version = "2.2.0";
filename = "tanzu-cli-bundle-linux-amd64.tar.gz";
checksum = "0j640sq4yfidmzr4rbdrqnjczm7xsrnkagsaz9hnrg57sxlzii7h";
homepage = "https://customerconnect.vmware.com/downloads/details?downloadGroup=TKG-220&productId=1400";
# The Tanzu CLI is now de-coupled from TKG.
product_name = "tanzu-cli";
product_version = "0.90.1";
filename = "tanzu-cli-linux-amd64.tar.gz";
checksum = "fec9e268399443de94d1761678aa39be18b7b685dd34a4412933943647b9d0be";
homepage = "https://customerconnect.vmware.com/downloads/details?downloadGroup=TCLI-0901&productId=1431";
in
pkgs.stdenv.mkDerivation {
name = product_name;
Expand All @@ -16,7 +17,7 @@ in
sha256 = checksum;

message = ''
In order to use VMware Tanzu Kubernetes Grid, you need to accept the EULA and download the file from:
In order to use VMware Tanzu CLI, you need to accept the EULA and download the file from:
${homepage}
Expand All @@ -43,13 +44,13 @@ in
installPhase = ''
mkdir --parents $out/bin
source=unpack/cli/core/*/tanzu-core-linux_amd64
source=unpack/*/tanzu-cli-linux_amd64
install --verbose $source $out/bin/tanzu
'';

meta = {
description = "VMware Tanzu Kubernetes Grid CLI";
description = "VMware Tanzu CLI";
homepage = "https://vmware.com";
license = "Commercial";
};
Expand Down

0 comments on commit 6cbdda0

Please sign in to comment.