Skip to content
Snippets Groups Projects

ci: Build workhorse binaries and upload/download as generic package

All threads resolved!
Compare and Show latest version
1 file
+ 43
21
Compare changes
  • Side-by-side
  • Inline
#!/usr/bin/env bash
export CURL_TOKEN_HEADER="${CURL_TOKEN_HEADER:-"JOB-TOKEN"}"
export GITLAB_WORKHORSE_FOLDER="gitlab-workhorse"
export TMP_GITLAB_WORKHORSE_FOLDER="${CI_PROJECT_DIR}/tmp/${GITLAB_WORKHORSE_FOLDER}"
export GITLAB_WORKHORSE_BINARIES_LIST="gitlab-resize-image gitlab-zip-cat gitlab-zip-metadata gitlab-workhorse"
@@ -12,11 +13,6 @@ function gitlab_workhorse_archive_doesnt_exist() {
[ ! -f "${GITLAB_WORKHORSE_ARCHIVE}" ]
}
function create_gitlab_workhorse_archive() {
compress_or_decompress "compress"
tar -czvf ${GITLAB_WORKHORSE_ARCHIVE} -C ${TMP_TEST_FOLDER} ${GITLAB_WORKHORSE_FOLDER}
}
function compress_or_decompress() {
local action="${1}"
local workhorse_folder="${2:${TMP_TEST_GITLAB_WORKHOSE_FOLDER}}"
@@ -44,40 +40,66 @@ function compress_or_decompress() {
fi
}
function create_gitlab_workhorse_archive() {
local archive_file="${1:-${GITLAB_WORKHORSE_ARCHIVE}}"
local archive_folder="${2:-${GITLAB_WORKHORSE_FOLDER}}"
local working_folder=$(dirname "${TMP_TEST_GITLAB_WORKHOSE_FOLDER}")
# Un-compressed
tar -czvf ${archive_file} -C ${working_folder} ${archive_folder}
# Compressed
compress_or_decompress "compress"
tar -czvf "upx-compressed-${archive_file}" -C ${working_folder} ${archive_folder}
}
function extract_gitlab_workhorse_archive() {
local destination_folder="${1:-${TMP_TEST_FOLDER}}"
echoinfo "Extracting archive to ${destination_folder}"
tar -xzv -C ${destination_folder} < /dev/stdin
}
function upload_gitlab_workhorse_package() {
echoinfo "Uploading ${GITLAB_WORKHORSE_ARCHIVE} to ${GITLAB_WORKHORSE_PACKAGE_URL} ..."
curl --fail --silent --retry 3 --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file "${GITLAB_WORKHORSE_ARCHIVE}" "${GITLAB_WORKHORSE_PACKAGE_URL}"
local archive_file="${1:-${GITLAB_WORKHORSE_ARCHIVE}}"
local package_url="${2:-${GITLAB_WORKHORSE_PACKAGE_URL}}"
local token_header="${3:-${CURL_TOKEN_HEADER}}"
local token="${4:-${CI_JOB_TOKEN}}"
echoinfo "Uploading ${archive_file} to ${package_url} ..."
curl --fail --silent --retry 3 --header "${token_header}: ${token}" --upload-file "${archive_file}" "${package_url}"
}
function download_gitlab_workhorse_package() {
local output_file="${1}"
local package_url="${2:-${GITLAB_WORKHORSE_PACKAGE_URL}}"
local token_header="${3:-${CURL_TOKEN_HEADER}}"
local token="${4:-${CI_JOB_TOKEN}}"
local extra_curl_args=""
if [ -n "${output_file}" ]; then
extra_curl_args=" -o \"${output_file}\""
fi
echoinfo "Downloading from ${GITLAB_WORKHORSE_PACKAGE_URL} ..."
eval "curl --fail --retry 3 --header \"JOB-TOKEN: ${CI_JOB_TOKEN}\" \"${GITLAB_WORKHORSE_PACKAGE_URL}\"${extra_curl_args}"
echoinfo "Downloading from ${package_url} ..."
eval "curl --fail --retry 3 --header \"${token_header}: ${token}\" \"${package_url}\"${extra_curl_args}"
}
function download_and_extract_gitlab_workhorse_package() {
download_gitlab_workhorse_package | extract_gitlab_workhorse_archive | compress_or_decompress "decompress"
}
function extract_gitlab_workhorse_archive() {
local destination_folder="${1:-${TMP_TEST_FOLDER}}"
echoinfo "Extracting archive to ${destination_folder}"
tar -xzv -C ${destination_folder} -
}
function filter_gitlab_workhorse_binaries() {
mkdir -p "${TMP_GITLAB_WORKHORSE_FOLDER}"
cd ${TMP_TEST_GITLAB_WORKHOSE_FOLDER} && cp ${GITLAB_WORKHORSE_PACKAGE_FILES_LIST} ${TMP_GITLAB_WORKHORSE_FOLDER} && cd -
rm -rf ${TMP_TEST_GITLAB_WORKHOSE_FOLDER}
local gitlab_workhose_tmp_folder="${1:-${TMP_GITLAB_WORKHORSE_FOLDER}}"
local gitlab_workhose_final_folder="${2:-${TMP_TEST_GITLAB_WORKHOSE_FOLDER}}"
local destination_folder="${3:-$(dirname "${TMP_TEST_GITLAB_WORKHOSE_FOLDER}")}"
mkdir -p "${gitlab_workhose_tmp_folder}"
cd ${gitlab_workhose_final_folder} && cp ${GITLAB_WORKHORSE_PACKAGE_FILES_LIST} ${gitlab_workhose_tmp_folder} && cd -
rm -rf ${gitlab_workhose_final_folder}
# Move the temp folder to its final destination
mv ${TMP_GITLAB_WORKHORSE_FOLDER} ${TMP_TEST_FOLDER};
mv ${gitlab_workhose_tmp_folder} ${destination_folder}
}
Loading