[Ubuntu] Pre-cache Ruby binaries (#2084)

* precache ruby binaries

* remove github_feed_token

* fix logs
This commit is contained in:
Dibir Magomedsaygitov
2020-11-27 10:52:00 +03:00
committed by GitHub
parent 8d6d64a04e
commit 38b0a6005d
13 changed files with 78 additions and 159 deletions

View File

@@ -43,6 +43,10 @@ $toolsExecutables = @{
tools = @("bin/go")
command = "version"
}
Ruby = @{
tools = @("bin/ruby")
command = "--version"
}
}
# Get toolset content

View File

@@ -1,39 +0,0 @@
#!/bin/bash -e
################################################################################
## File: hosted-tool-cache.sh
## Desc: Downloads and installs hosted tools cache
################################################################################
TOOLCACHE_REGISTRY="npm.pkg.github.com"
echo "Configure npm to use github package registry for '@actions' scope"
npm config set @actions:registry "https://${TOOLCACHE_REGISTRY}"
# Execute in /imagegeneration/installers folder to avoid node_modules creation in $HOME
pushd $INSTALLER_SCRIPT_FOLDER
# GitHub Package Registry doesn't support downloading public packages without auth so we have to authorize
echo "Configure auth for github package registry"
echo "//${TOOLCACHE_REGISTRY}/:_authToken=${GITHUB_FEED_TOKEN}" > ".npmrc"
echo "Installing npm-toolcache..."
TOOLSET_PATH="$INSTALLER_SCRIPT_FOLDER/toolcache.json"
PACKAGE_LIST=($(jq -r 'keys | .[]' $TOOLSET_PATH))
for PACKAGE_NAME in ${PACKAGE_LIST[@]}; do
PACKAGE_VERSIONS=($(jq -r ".[\"$PACKAGE_NAME\"] | .[]" $TOOLSET_PATH))
for PACKAGE_VERSION in ${PACKAGE_VERSIONS[@]}; do
echo "Install ${PACKAGE_NAME}@${PACKAGE_VERSION}"
npm install ${PACKAGE_NAME}@${PACKAGE_VERSION}
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "${PACKAGE_NAME}@${PACKAGE_VERSION} installation failure; Error:${exit_code}"
exit 1
fi
done;
done;
popd

View File

@@ -4,8 +4,44 @@
## Desc: Installs Ruby requirements
################################################################################
source $HELPER_SCRIPTS/install.sh
sudo apt-get install ruby-full
sudo gem update --system
# Install Ruby requirements
apt-get install -y libz-dev openssl libssl-dev
echo "Install Ruby from toolset..."
toolset="$INSTALLER_SCRIPT_FOLDER/toolset.json"
PACKAGE_TAR_NAMES=$(curl -s "https://api.github.com/repos/ruby/ruby-builder/releases/latest" | jq -r '.assets[].name')
TOOLSET_VERSIONS=$(jq -r '.toolcache[] | select(.name | contains("Ruby")) | .versions[]' $toolset)
PLATFORM_VERSION=$(jq -r '.toolcache[] | select(.name | contains("Ruby")) | .platform_version' $toolset)
RUBY_PATH="$AGENT_TOOLSDIRECTORY/Ruby"
echo "Check if Ruby hostedtoolcache folder exist..."
if [ ! -d $RUBY_PATH ]; then
mkdir -p $RUBY_PATH
fi
for TOOLSET_VERSION in ${TOOLSET_VERSIONS[@]}; do
PACKAGE_TAR_NAME=$(echo "$PACKAGE_TAR_NAMES" | grep "^ruby-${TOOLSET_VERSION}-ubuntu-${PLATFORM_VERSION}.tar.gz$" | sort -V | tail -1)
RUBY_VERSION=$(echo "$PACKAGE_TAR_NAME" | cut -d'-' -f 2)
RUBY_VERSION_PATH="$RUBY_PATH/$RUBY_VERSION"
echo "Create Ruby $RUBY_VERSION directory..."
mkdir -p $RUBY_VERSION_PATH
echo "Downloading tar archive $PACKAGE_TAR_NAME"
DOWNLOAD_URL="https://github.com/ruby/ruby-builder/releases/download/toolcache/${PACKAGE_TAR_NAME}"
download_with_retries $DOWNLOAD_URL "/tmp" $PACKAGE_TAR_NAME
echo "Expand '$PACKAGE_TAR_NAME' to the '$RUBY_VERSION_PATH' folder"
tar xf "/tmp/$PACKAGE_TAR_NAME" -C $RUBY_VERSION_PATH
COMPLETE_FILE_PATH="$RUBY_VERSION_PATH/x64.complete"
if [ ! -f $COMPLETE_FILE_PATH ]; then
echo "Create complete file"
touch $COMPLETE_FILE_PATH
fi
done

View File

@@ -1,69 +0,0 @@
#!/bin/bash -e
################################################################################
## File: test-toolcache.sh
## Desc: Test Python and Ruby versions in tools cache
################################################################################
# Must be procecessed after tool cache setup(hosted-tool-cache.sh).
Test_Hostedtoolcache_Tool() {
TOOL_NAME=$1
TOOL_EXEC_TEST=$2
if [ -d "$AGENT_TOOLSDIRECTORY/$TOOL_NAME" ]; then
cd $AGENT_TOOLSDIRECTORY/$TOOL_NAME
tool_dirs=($(find . -mindepth 1 -maxdepth 1 -type d | sed "s|^\./||"))
echo "--------------------------------------------"
echo "$TOOL_NAME versions folders: ${tool_dirs[@]}"
echo "--------------------------------------------"
if [ -n "$tool_dirs" ]; then
tool_key=$(echo $TOOL_NAME | tr "[:upper:]" "[:lower:]")
package_versions=($(jq -r ".[\"${TOOLCACHE_KEY_VALUE[$tool_key]}\"] | .[]" "$INSTALLER_SCRIPT_FOLDER/toolcache.json"))
for tool_version in ${package_versions[@]}
do
version_dir=$(find . -name "$tool_version.*" -print -quit)
echo "Test $AGENT_TOOLSDIRECTORY/$TOOL_NAME/$version_dir:"
actual_version=$(eval $AGENT_TOOLSDIRECTORY/$TOOL_NAME/$version_dir/$TOOL_EXEC_TEST)
if [ "$actual_version" = "$tool_version" ]; then
echo "Passed!"
else
echo "Expected: $tool_version; Actual: $actual_version"
exit 1
fi
done;
else
echo "$AGENT_TOOLSDIRECTORY/$tool_version does not include any folders"
exit 1
fi
else
echo "$AGENT_TOOLSDIRECTORY/$tool_version does not exist"
exit 1
fi
}
# define dictionary for key_alias and its values
declare -A TOOLCACHE_KEY_VALUE
package_list=($(jq -r 'keys | .[]' "$INSTALLER_SCRIPT_FOLDER/toolcache.json"))
for package_name in ${package_list[@]}; do
# get key alias
key_alias=$(echo $package_name | cut -f2 -d-)
# set dictionary
TOOLCACHE_KEY_VALUE+=(["$key_alias"]="$package_name")
done;
AGENT_TOOLSDIRECTORY=/opt/hostedtoolcache
Test_Hostedtoolcache_Tool "Ruby" "x64/bin/ruby -e 'puts RUBY_VERSION' | egrep -o '[0-9]+\.[0-9]+'"