diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-25 00:15:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-25 00:15:17 +0300 |
commit | 0afa6fb9d922cb7e201e81b2b668258d3dcf9d46 (patch) | |
tree | 6cc932813286d30095068905cf30b45cbf609558 /scripts | |
parent | 94ca43181461c52ca0381d414387b02e579dbc61 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/gitlab_workhorse_component_helpers.sh | 73 | ||||
-rw-r--r-- | scripts/utils.sh | 16 |
2 files changed, 81 insertions, 8 deletions
diff --git a/scripts/gitlab_workhorse_component_helpers.sh b/scripts/gitlab_workhorse_component_helpers.sh new file mode 100644 index 00000000000..06fe7b2ea51 --- /dev/null +++ b/scripts/gitlab_workhorse_component_helpers.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +set -euo pipefail + +export CURL_TOKEN_HEADER="${CURL_TOKEN_HEADER:-"JOB-TOKEN"}" +export GITLAB_WORKHORSE_BINARIES_LIST="gitlab-resize-image gitlab-zip-cat gitlab-zip-metadata gitlab-workhorse" +export GITLAB_WORKHORSE_PACKAGE_FILES_LIST="${GITLAB_WORKHORSE_BINARIES_LIST} WORKHORSE_TREE" +export GITLAB_WORKHORSE_TREE=${GITLAB_WORKHORSE_TREE:-$(git rev-parse HEAD:workhorse)} +export GITLAB_WORKHORSE_PACKAGE="workhorse-${GITLAB_WORKHORSE_TREE}.tar.gz" +export GITLAB_WORKHORSE_PACKAGE_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/${GITLAB_WORKHORSE_FOLDER}/${GITLAB_WORKHORSE_TREE}/${GITLAB_WORKHORSE_PACKAGE}" + +function gitlab_workhorse_archive_doesnt_exist() { + local package_url="${GITLAB_WORKHORSE_PACKAGE_URL}" + + status=$(curl -I --silent --retry 3 --output /dev/null -w "%{http_code}" "${package_url}") + + [[ "${status}" != "200" ]] +} + +function create_gitlab_workhorse_package() { + local archive_filename="${GITLAB_WORKHORSE_PACKAGE}" + local folder_to_archive="${GITLAB_WORKHORSE_FOLDER}" + local workhorse_folder_path="${TMP_TEST_GITLAB_WORKHORSE_PATH}" + local tar_working_folder="${TMP_TEST_FOLDER}" + + echoinfo "Running 'tar -czvf ${archive_filename} -C ${tar_working_folder} ${folder_to_archive}'" + tar -czvf ${archive_filename} -C ${tar_working_folder} ${folder_to_archive} + du -h ${archive_filename} +} + +function extract_gitlab_workhorse_package() { + local tar_working_folder="${TMP_TEST_FOLDER}" + + echoinfo "Extracting archive to ${tar_working_folder}" + + tar -xzv -C ${tar_working_folder} < /dev/stdin +} + +function upload_gitlab_workhorse_package() { + local archive_filename="${GITLAB_WORKHORSE_PACKAGE}" + local package_url="${GITLAB_WORKHORSE_PACKAGE_URL}" + local token_header="${CURL_TOKEN_HEADER}" + local token="${CI_JOB_TOKEN}" + + echoinfo "Uploading ${archive_filename} to ${package_url} ..." + curl --fail --silent --retry 3 --header "${token_header}: ${token}" --upload-file "${archive_filename}" "${package_url}" +} + +function read_curl_gitlab_workhorse_package() { + local package_url="${GITLAB_WORKHORSE_PACKAGE_URL}" + local token_header="${CURL_TOKEN_HEADER}" + local token="${CI_JOB_TOKEN}" + + echoinfo "Downloading from ${package_url} ..." + + curl --fail --silent --retry 3 --header "${token_header}: ${token}" "${package_url}" +} + +function download_and_extract_gitlab_workhorse_package() { + read_curl_gitlab_workhorse_package | extract_gitlab_workhorse_package +} + +function select_gitlab_workhorse_essentials() { + local tmp_path="${CI_PROJECT_DIR}/tmp/${GITLAB_WORKHORSE_FOLDER}" + local original_gitlab_workhorse_path="${TMP_TEST_GITLAB_WORKHORSE_PATH}" + + mkdir -p ${tmp_path} + cd ${original_gitlab_workhorse_path} && mv ${GITLAB_WORKHORSE_PACKAGE_FILES_LIST} ${tmp_path} && cd - + rm -rf ${original_gitlab_workhorse_path} + + # Move the temp folder to its final destination + mv ${tmp_path} ${TMP_TEST_FOLDER} +} diff --git a/scripts/utils.sh b/scripts/utils.sh index c20508617b8..e896fe40e06 100644 --- a/scripts/utils.sh +++ b/scripts/utils.sh @@ -83,7 +83,7 @@ function install_junit_merge_gem() { function run_timed_command() { local cmd="${1}" - local metric_name="${2}" + local metric_name="${2:-no}" local timed_metric_file local start=$(date +%s) @@ -97,7 +97,7 @@ function run_timed_command() { if [[ $ret -eq 0 ]]; then echosuccess "==> '${cmd}' succeeded in ${runtime} seconds." - if [[ -n "${metric_name}" ]]; then + if [[ "${metric_name}" != "no" ]]; then timed_metric_file=$(timed_metric_file $metric_name) echo "# TYPE ${metric_name} gauge" > "${timed_metric_file}" echo "# UNIT ${metric_name} seconds" >> "${timed_metric_file}" @@ -132,9 +132,9 @@ function timed_metric_file() { } function echoerr() { - local header="${2}" + local header="${2:-no}" - if [ -n "${header}" ]; then + if [ "${header}" != "no" ]; then printf "\n\033[0;31m** %s **\n\033[0m" "${1}" >&2; else printf "\033[0;31m%s\n\033[0m" "${1}" >&2; @@ -142,9 +142,9 @@ function echoerr() { } function echoinfo() { - local header="${2}" + local header="${2:-no}" - if [ -n "${header}" ]; then + if [ "${header}" != "no" ]; then printf "\n\033[0;33m** %s **\n\033[0m" "${1}" >&2; else printf "\033[0;33m%s\n\033[0m" "${1}" >&2; @@ -152,9 +152,9 @@ function echoinfo() { } function echosuccess() { - local header="${2}" + local header="${2:-no}" - if [ -n "${header}" ]; then + if [ "${header}" != "no" ]; then printf "\n\033[0;32m** %s **\n\033[0m" "${1}" >&2; else printf "\033[0;32m%s\n\033[0m" "${1}" >&2; |