2023-03-14 08:57:39 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# This script is run from the user's Constellation workspace (BUILD_WORKING_DIRECTORY).
|
|
|
|
# It prepares the workspace by symlinking all required binaries into folder.
|
|
|
|
|
2023-03-29 08:13:26 -04:00
|
|
|
###### script header ######
|
|
|
|
|
2023-03-14 08:57:39 -04:00
|
|
|
lib=$(realpath @@BASE_LIB@@) || exit 1
|
2023-03-29 08:13:26 -04:00
|
|
|
stat "${lib}" >> /dev/null || exit 1
|
2023-03-14 08:57:39 -04:00
|
|
|
|
2023-03-16 09:24:53 -04:00
|
|
|
# shellcheck source=../sh/lib.bash
|
2023-03-14 08:57:39 -04:00
|
|
|
if ! source "${lib}"; then
|
|
|
|
echo "Error: could not find import"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-12-14 02:18:48 -05:00
|
|
|
if [[ ${BUILD_WORKSPACE_DIRECTORY} == "${BUILD_WORKING_DIRECTORY}" ]]; then
|
|
|
|
echo "Error: You are trying to run a devbuild in the project root directory."
|
|
|
|
echo "You probably want to run it in a subdirectory instead:"
|
|
|
|
echo "mkdir -p build && cd build && bazel run //:devbuild"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
goos=@@GOOS@@
|
|
|
|
goarch=@@GOARCH@@
|
2023-08-21 05:46:10 -04:00
|
|
|
yq=$(realpath @@YQ@@)
|
|
|
|
stat "${yq}" >> /dev/null
|
2023-12-12 08:46:11 -05:00
|
|
|
sed=$(realpath @@SED@@)
|
|
|
|
stat "${sed}" >> /dev/null
|
2023-03-29 08:13:26 -04:00
|
|
|
bootstrapper=$(realpath @@BOOTSTRAPPER@@)
|
|
|
|
stat "${bootstrapper}" >> /dev/null
|
|
|
|
upgrade_agent=$(realpath @@UPGRADE_AGENT@@)
|
|
|
|
stat "${upgrade_agent}" >> /dev/null
|
|
|
|
cli=$(realpath @@CLI@@)
|
|
|
|
stat "${cli}" >> /dev/null
|
|
|
|
cdbg=$(realpath @@CDBG@@)
|
|
|
|
stat "${cdbg}" >> /dev/null
|
2023-04-03 12:13:17 -04:00
|
|
|
container_sums=$(realpath @@CONTAINER_SUMS@@)
|
|
|
|
stat "${container_sums}" >> /dev/null
|
2023-05-30 03:05:36 -04:00
|
|
|
edition=$(cat @@EDITION@@)
|
2023-12-22 02:38:28 -05:00
|
|
|
raw_provider="@@TERRAFORM_PROVIDER@@"
|
|
|
|
if [[ -n ${raw_provider} ]]; then
|
|
|
|
terraform_provider=$(realpath "${raw_provider}")
|
|
|
|
stat "${terraform_provider}" >> /dev/null
|
|
|
|
else
|
|
|
|
terraform_provider=""
|
|
|
|
fi
|
2023-12-14 02:18:48 -05:00
|
|
|
build_version=$(cat @@VERSION_FILE@@)
|
|
|
|
if [[ -z ${build_version} ]]; then
|
|
|
|
echo "Error: version file is empty"
|
|
|
|
exit 1
|
|
|
|
fi
|
2023-03-29 08:13:26 -04:00
|
|
|
|
|
|
|
cd "${BUILD_WORKING_DIRECTORY}"
|
|
|
|
|
|
|
|
###### script body ######
|
2023-03-14 08:57:39 -04:00
|
|
|
|
2023-04-12 11:29:55 -04:00
|
|
|
replace_prefix() {
|
|
|
|
local host_cache=$1
|
|
|
|
local builder_cache=$2
|
|
|
|
local dir=$3
|
|
|
|
if [[ ${dir#"${builder_cache}"} == "${dir}" ]]; then
|
|
|
|
echo "${dir}"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
relpath=${dir#"${builder_cache}"}
|
|
|
|
realpath -m "${host_cache}/${relpath}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set HOST_CACHE when running in a container with mounted cache.
|
|
|
|
host_cache="${HOST_CACHE:-${HOME}/.cache}"
|
|
|
|
builder_cache="${HOME}/.cache"
|
|
|
|
|
2023-03-14 09:37:58 -04:00
|
|
|
if [[ $# -eq 0 ]]; then
|
|
|
|
workdir="."
|
2023-03-14 08:57:39 -04:00
|
|
|
else
|
2023-03-14 09:37:58 -04:00
|
|
|
workdir="$1"
|
2023-03-14 08:57:39 -04:00
|
|
|
fi
|
|
|
|
|
2023-05-30 03:05:36 -04:00
|
|
|
echo "Using ${edition} cli edition"
|
|
|
|
|
2023-04-12 11:29:55 -04:00
|
|
|
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${bootstrapper}")" "${workdir}/bootstrapper"
|
|
|
|
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${upgrade_agent}")" "${workdir}/upgrade-agent"
|
|
|
|
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cdbg}")" "${workdir}/cdbg"
|
2023-04-03 12:13:17 -04:00
|
|
|
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${container_sums}")" "${workdir}/container_sums.sha256"
|
2023-05-30 03:05:36 -04:00
|
|
|
ln -sf "$(replace_prefix "${host_cache}" "${builder_cache}" "${cli}")" "${workdir}/constellation"
|
2023-07-06 02:46:06 -04:00
|
|
|
|
2023-12-22 02:38:28 -05:00
|
|
|
if [[ -n ${terraform_provider} ]]; then
|
|
|
|
terraform_provider_dir=${HOME}/.terraform.d/plugins/registry.terraform.io/edgelesssys/constellation/${build_version#v}/${goos}_${goarch}/
|
|
|
|
mkdir -p "${terraform_provider_dir}"
|
|
|
|
ln -sf "${terraform_provider}" "${terraform_provider_dir}/terraform-provider-constellation_${build_version}"
|
|
|
|
fi
|
2023-11-24 09:58:21 -05:00
|
|
|
|
2023-07-06 02:46:06 -04:00
|
|
|
if [[ ! -f "${workdir}/constellation-conf.yaml" ]]; then
|
|
|
|
echo "constellation-conf.yaml not present in workspace"
|
|
|
|
echo "Build version: ${build_version}"
|
|
|
|
else
|
2023-07-24 05:15:29 -04:00
|
|
|
${yq} -i eval ".microserviceVersion=\"${build_version}\"" ./constellation-conf.yaml
|
2023-07-06 02:46:06 -04:00
|
|
|
echo "Microservice version updated to ${build_version} in constellation-conf.yaml"
|
|
|
|
fi
|