From 71fff334049218d91ebbbabea62fbd2528b0ef6d Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 18:55:23 +0000 Subject: [PATCH 01/22] updating prestaged yamls command --- scripts/deploy_spacefx.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deploy_spacefx.sh b/scripts/deploy_spacefx.sh index b6d4434..d68baa0 100755 --- a/scripts/deploy_spacefx.sh +++ b/scripts/deploy_spacefx.sh @@ -226,7 +226,7 @@ function deploy_prestaged_yamls(){ else error_log "...'${yamlFile}' failed to deploy. See logs for more information." fi - done < <(find "${SPACEFX_DIR}/yamls" -iname "*.yaml") + done < <(find "${SPACEFX_DIR}/yamls" -maxdepth 1 -name "*.yaml") info_log "All pre-staged yaml files have been deployed." From a338ac4f27c4f218fe299302142a8b071d8e6170 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 20:24:50 +0000 Subject: [PATCH 02/22] updating to write files --- scripts/deploy/deploy_k3s.sh | 4 ++-- scripts/deploy_spacefx.sh | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/deploy/deploy_k3s.sh b/scripts/deploy/deploy_k3s.sh index 0f37fb2..eb6a650 100755 --- a/scripts/deploy/deploy_k3s.sh +++ b/scripts/deploy/deploy_k3s.sh @@ -82,10 +82,10 @@ SPACEFX_UPDATE_END" [[ ! -d "/usr/local/bin" ]] && create_directory "/usr/local/bin" - [[ ! -f "/usr/local/bin/k3s" ]] && run_a_script "cp ${SPACEFX_DIR}/bin/${ARCHITECTURE}/k3s/${VER_K3S}/k3s /usr/local/bin/k3s" + run_a_script "cp ${SPACEFX_DIR}/bin/${ARCHITECTURE}/k3s/${VER_K3S}/k3s /usr/local/bin/k3s" [[ ! -d "/var/lib/rancher/k3s/agent/images" ]] && create_directory "/var/lib/rancher/k3s/agent/images" - [[ ! -f "/var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar.gz" ]] && run_a_script "cp ${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.gz /var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar.gz" + run_a_script "cp ${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.gz /var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar.gz" export INSTALL_K3S_SKIP_DOWNLOAD=true diff --git a/scripts/deploy_spacefx.sh b/scripts/deploy_spacefx.sh index d68baa0..d7c862b 100755 --- a/scripts/deploy_spacefx.sh +++ b/scripts/deploy_spacefx.sh @@ -238,11 +238,16 @@ function main() { write_parameter_to_log ARCHITECTURE write_parameter_to_log DEV_ENVIRONMENT + info_log "Updating ownership of ${SPACEFX_DIR}..." + run_a_script "chown -R ${USER}:${USER} ${SPACEFX_DIR}" + info_log "...successfully updated ownership of ${SPACEFX_DIR}" + + check_and_create_certificate_authority + info_log "Deploying k3s..." run_a_script "${SPACEFX_DIR}/scripts/deploy/deploy_k3s.sh" info_log "...successfully deployed k3s" - check_and_create_certificate_authority deploy_namespaces run_a_script "${SPACEFX_DIR}/scripts/coresvc_registry.sh --start" From 0862559d7b4e4329125c58fbf7c9014a66f653db Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 20:31:54 +0000 Subject: [PATCH 03/22] adding 256sum and typo correction --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a8979c6..f8f9677 100644 --- a/README.md +++ b/README.md @@ -27,17 +27,18 @@ Production deploments are intended to run on a satellite with an emphasis on red # Create a clean output directory sudo mkdir -p ./output && sudo rm -rf ./output/* - sudo tar -czf ./output/msft_azure_orbital_space_sdk.tar.gz -C /var/spacedev . + sudo tar -czf ./output/msft_azure_orbital_framework.tar.gz -C /var/spacedev . + sudo sha256sum ./output/msft_azure_orbital_framework.tar.gz | awk '{print $1}' | sudo tee ./output/msft_azure_orbital_framework.tar.gz.sha256 ``` -1. Copy the `./output/msft_azure_orbital_space_sdk.tar.gz` to the target hardware / satellite / host +1. Copy the `./output/msft_azure_orbital_framework.tar.gz` to the target hardware / satellite / host 1. Deploy the Microsoft Azure Orbital Space SDK ```bash # Extract the Microsoft Azure Orbital Space SDK to /var/spacedev sudo mkdir -p /var/spacedev sudo chown -R "${USER:-$(id -un)}" /var/spacedev - sudo tar -xzvf msft_azure_orbital_space_sdk.tar.gz -C /var/spacedev + sudo tar -xzvf msft_azure_orbital_framework.tar.gz -C /var/spacedev # Deploy the Microsoft Azure Orbital Space SDK /var/spacedev/scripts/deploy_spacefx.sh From 5350a5e5fb5d45512a36115103f9c600a40c0a8b Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 20:53:17 +0000 Subject: [PATCH 04/22] escaping variable --- scripts/deploy_spacefx.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/deploy_spacefx.sh b/scripts/deploy_spacefx.sh index d7c862b..184245b 100755 --- a/scripts/deploy_spacefx.sh +++ b/scripts/deploy_spacefx.sh @@ -239,7 +239,7 @@ function main() { write_parameter_to_log DEV_ENVIRONMENT info_log "Updating ownership of ${SPACEFX_DIR}..." - run_a_script "chown -R ${USER}:${USER} ${SPACEFX_DIR}" + run_a_script "chown -R \${USER}:\${USER} ${SPACEFX_DIR}" info_log "...successfully updated ownership of ${SPACEFX_DIR}" check_and_create_certificate_authority From f9d2080513fad391eeda8b0779a0825495bcf403 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 20:55:48 +0000 Subject: [PATCH 05/22] fixing typo in cfssl staging --- scripts/stage/stage_3p_apps.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/stage/stage_3p_apps.sh b/scripts/stage/stage_3p_apps.sh index 2e255bb..2e471cc 100755 --- a/scripts/stage/stage_3p_apps.sh +++ b/scripts/stage/stage_3p_apps.sh @@ -136,7 +136,7 @@ function main() { # Download CFSSL, jq, yq, regctl local VER_CFSSL_no_v="${VER_CFSSL:1}" _app_install --app "cfssl" --source "${DEST_STAGE_DIR}/cfssl/${VER_CFSSL}/cfssl" --url "https://github.com/cloudflare/cfssl/releases/download/${VER_CFSSL}/cfssl_${VER_CFSSL_no_v}_linux_${ARCHITECTURE}" --destination "${DEST_STAGE_DIR}/cfssl/${VER_CFSSL}/cfssl" - _app_install --app "cfssljson" --source "${DEST_STAGE_DIR}/cfssl/${VER_CFSSL}/cfssljson" --url "https://github.com/cloudflare/cfssl/releases/download/${VER_CFSSL}/cfssl_${VER_CFSSL_no_v}_linux_${ARCHITECTURE}" --destination "${DEST_STAGE_DIR}/cfssl/${VER_CFSSL}/cfssljson" + _app_install --app "cfssljson" --source "${DEST_STAGE_DIR}/cfssl/${VER_CFSSL}/cfssljson" --url "https://github.com/cloudflare/cfssl/releases/download/${VER_CFSSL}/cfssljson_${VER_CFSSL_no_v}_linux_${ARCHITECTURE}" --destination "${DEST_STAGE_DIR}/cfssl/${VER_CFSSL}/cfssljson" _app_install --app "jq" --source "${DEST_STAGE_DIR}/jq/${VER_JQ}/jq" --url "https://github.com/jqlang/jq/releases/download/jq-${VER_JQ:?}/jq-linux-${ARCHITECTURE:?}" --destination "${DEST_STAGE_DIR}/jq/${VER_JQ}/jq" _app_install --app "yq" --source "${DEST_STAGE_DIR}/yq/${VER_YQ}/yq" --url "https://github.com/mikefarah/yq/releases/download/v${VER_YQ:?}/yq_linux_${ARCHITECTURE:?}" --destination "${DEST_STAGE_DIR}/yq/${VER_YQ}/yq" From 171133b2173f99a0e84f4ca9bd46cd0ef2cf5e38 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 21:16:26 +0000 Subject: [PATCH 06/22] adding symlinks --- README.md | 5 +++++ scripts/deploy/deploy_spacefx.sh | 1 + scripts/stage/stage_spacefx.sh | 1 + 3 files changed, 7 insertions(+) create mode 120000 scripts/deploy/deploy_spacefx.sh create mode 120000 scripts/stage/stage_spacefx.sh diff --git a/README.md b/README.md index f8f9677..ca6c594 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ Production deploments are intended to run on a satellite with an emphasis on red # Or specify the architecture to download a different architecture /var/spacedev/scripts/stage_spacefx.sh --architecture arm64 + # Clean out /var/spacedev of unnecessary logs and artifacts + sudo rm /var/spacedev/logs/* -rf + sudo rm /var/spacedev/tmp/* -rf + sudo find /var/spacedev/certs -type f ! -name '*.json' -delete + # Create a clean output directory sudo mkdir -p ./output && sudo rm -rf ./output/* sudo tar -czf ./output/msft_azure_orbital_framework.tar.gz -C /var/spacedev . diff --git a/scripts/deploy/deploy_spacefx.sh b/scripts/deploy/deploy_spacefx.sh new file mode 120000 index 0000000..d44d009 --- /dev/null +++ b/scripts/deploy/deploy_spacefx.sh @@ -0,0 +1 @@ +./scripts/deploy_spacefx.sh \ No newline at end of file diff --git a/scripts/stage/stage_spacefx.sh b/scripts/stage/stage_spacefx.sh new file mode 120000 index 0000000..08bb214 --- /dev/null +++ b/scripts/stage/stage_spacefx.sh @@ -0,0 +1 @@ +./scripts/stage_spacefx.sh \ No newline at end of file From c48c0fd828aede4fa277f9ba4f4a17001e6a63f9 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 21:28:14 +0000 Subject: [PATCH 07/22] adding symlink generation --- modules/m_15_directories.sh | 8 ++++++++ scripts/deploy/deploy_spacefx.sh | 1 - scripts/stage/stage_3p_apps.sh | 2 +- scripts/stage/stage_spacefx.sh | 1 - 4 files changed, 9 insertions(+), 3 deletions(-) delete mode 120000 scripts/deploy/deploy_spacefx.sh delete mode 120000 scripts/stage/stage_spacefx.sh diff --git a/modules/m_15_directories.sh b/modules/m_15_directories.sh index b1df7ed..c5e81ab 100755 --- a/modules/m_15_directories.sh +++ b/modules/m_15_directories.sh @@ -25,6 +25,14 @@ function _setup_initial_directories() { create_directory "${SPACEFX_DIR}/tmp" create_directory "${SPACEFX_DIR}/tmp/yamls" create_directory "${SPACEFX_DIR}/xfer" + + if [[ ! -L "${SPACEFX_DIR}/scripts/deploy/deploy_spacefx.sh" ]]; then + ln -s "${SPACEFX_DIR}/scripts/deploy_spacefx.sh" "${SPACEFX_DIR}/scripts/deploy/deploy_spacefx.sh" + fi + + if [[ ! -L "${SPACEFX_DIR}/scripts/stage/stage_spacefx.sh" ]]; then + ln -s "${SPACEFX_DIR}/scripts/stage_spacefx.sh" "${SPACEFX_DIR}/scripts/stage/stage_spacefx.sh" + fi } ############################################################ diff --git a/scripts/deploy/deploy_spacefx.sh b/scripts/deploy/deploy_spacefx.sh deleted file mode 120000 index d44d009..0000000 --- a/scripts/deploy/deploy_spacefx.sh +++ /dev/null @@ -1 +0,0 @@ -./scripts/deploy_spacefx.sh \ No newline at end of file diff --git a/scripts/stage/stage_3p_apps.sh b/scripts/stage/stage_3p_apps.sh index 2e471cc..ee6f784 100755 --- a/scripts/stage/stage_3p_apps.sh +++ b/scripts/stage/stage_3p_apps.sh @@ -87,7 +87,7 @@ function stage_k3s(){ _app_install --app "k3s_install.sh" --source "${DEST_STAGE_DIR}/k3s/${VER_K3S}/k3s_install.sh" --url "https://get.k3s.io/" --destination "${DEST_STAGE_DIR}/k3s/${VER_K3S}/k3s_install.sh" # Download k3s airgap images - _app_install --app "k3s-airgap-images-${ARCHITECTURE}.tar.gz" --source "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.gz" --url "https://github.com/k3s-io/k3s/releases/download/${url_encoded_k3s_vers}/k3s-airgap-images-${ARCHITECTURE}.tar.gz" --destination "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.gz" + _app_install --app "k3s-airgap-images-${ARCHITECTURE}.tar.zst" --source "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.zst" --url "https://github.com/k3s-io/k3s/releases/download/${url_encoded_k3s_vers}/k3s-airgap-images-${ARCHITECTURE}.tar.zst" --destination "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.zst" info_log "FINISHED: ${FUNCNAME[0]}" } diff --git a/scripts/stage/stage_spacefx.sh b/scripts/stage/stage_spacefx.sh deleted file mode 120000 index 08bb214..0000000 --- a/scripts/stage/stage_spacefx.sh +++ /dev/null @@ -1 +0,0 @@ -./scripts/stage_spacefx.sh \ No newline at end of file From 64a1320b1b0bce1830795fbb69f4ee90a1c8061f Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 21:31:33 +0000 Subject: [PATCH 08/22] updating path check for k3s --- scripts/deploy/deploy_k3s.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/deploy/deploy_k3s.sh b/scripts/deploy/deploy_k3s.sh index eb6a650..e04ef4d 100755 --- a/scripts/deploy/deploy_k3s.sh +++ b/scripts/deploy/deploy_k3s.sh @@ -76,7 +76,7 @@ SPACEFX_UPDATE_END" _check_for_file "${SPACEFX_DIR}/bin/${ARCHITECTURE}/k3s/${VER_K3S}/k3s" _check_for_file "${SPACEFX_DIR}/bin/${ARCHITECTURE}/k3s/${VER_K3S}/k3s_install.sh" - _check_for_file "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.gz" + _check_for_file "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.zst" info_log "...copying files to destinations..." @@ -85,7 +85,7 @@ SPACEFX_UPDATE_END" run_a_script "cp ${SPACEFX_DIR}/bin/${ARCHITECTURE}/k3s/${VER_K3S}/k3s /usr/local/bin/k3s" [[ ! -d "/var/lib/rancher/k3s/agent/images" ]] && create_directory "/var/lib/rancher/k3s/agent/images" - run_a_script "cp ${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.gz /var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar.gz" + run_a_script "cp ${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.zst /var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar.zst" export INSTALL_K3S_SKIP_DOWNLOAD=true From 354790bf36061e6f3b5ce82d940aca3db40267d6 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 21:59:08 +0000 Subject: [PATCH 09/22] updatings to only update if user is populated --- scripts/deploy_spacefx.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/deploy_spacefx.sh b/scripts/deploy_spacefx.sh index 184245b..7286e25 100755 --- a/scripts/deploy_spacefx.sh +++ b/scripts/deploy_spacefx.sh @@ -238,9 +238,13 @@ function main() { write_parameter_to_log ARCHITECTURE write_parameter_to_log DEV_ENVIRONMENT - info_log "Updating ownership of ${SPACEFX_DIR}..." - run_a_script "chown -R \${USER}:\${USER} ${SPACEFX_DIR}" - info_log "...successfully updated ownership of ${SPACEFX_DIR}" + if [[ -n "${USER}" ]]; then + info_log "Updating ownership of ${SPACEFX_DIR}..." + run_a_script "chown -R ${USER}:${USER} ${SPACEFX_DIR}" + info_log "...successfully updated ownership of ${SPACEFX_DIR}" + fi + + check_and_create_certificate_authority From 82ff2acca86ca3aba8cba4273a1f14bbd9354c7a Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 22:02:32 +0000 Subject: [PATCH 10/22] updating imgaes to stage tarball --- scripts/deploy/deploy_k3s.sh | 4 ++-- scripts/stage/stage_3p_apps.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/deploy/deploy_k3s.sh b/scripts/deploy/deploy_k3s.sh index e04ef4d..e10dc55 100755 --- a/scripts/deploy/deploy_k3s.sh +++ b/scripts/deploy/deploy_k3s.sh @@ -76,7 +76,7 @@ SPACEFX_UPDATE_END" _check_for_file "${SPACEFX_DIR}/bin/${ARCHITECTURE}/k3s/${VER_K3S}/k3s" _check_for_file "${SPACEFX_DIR}/bin/${ARCHITECTURE}/k3s/${VER_K3S}/k3s_install.sh" - _check_for_file "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.zst" + _check_for_file "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar" info_log "...copying files to destinations..." @@ -85,7 +85,7 @@ SPACEFX_UPDATE_END" run_a_script "cp ${SPACEFX_DIR}/bin/${ARCHITECTURE}/k3s/${VER_K3S}/k3s /usr/local/bin/k3s" [[ ! -d "/var/lib/rancher/k3s/agent/images" ]] && create_directory "/var/lib/rancher/k3s/agent/images" - run_a_script "cp ${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.zst /var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar.zst" + run_a_script "cp ${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar /var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar" export INSTALL_K3S_SKIP_DOWNLOAD=true diff --git a/scripts/stage/stage_3p_apps.sh b/scripts/stage/stage_3p_apps.sh index ee6f784..4790873 100755 --- a/scripts/stage/stage_3p_apps.sh +++ b/scripts/stage/stage_3p_apps.sh @@ -87,7 +87,7 @@ function stage_k3s(){ _app_install --app "k3s_install.sh" --source "${DEST_STAGE_DIR}/k3s/${VER_K3S}/k3s_install.sh" --url "https://get.k3s.io/" --destination "${DEST_STAGE_DIR}/k3s/${VER_K3S}/k3s_install.sh" # Download k3s airgap images - _app_install --app "k3s-airgap-images-${ARCHITECTURE}.tar.zst" --source "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.zst" --url "https://github.com/k3s-io/k3s/releases/download/${url_encoded_k3s_vers}/k3s-airgap-images-${ARCHITECTURE}.tar.zst" --destination "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar.zst" + _app_install --app "k3s-airgap-images-${ARCHITECTURE}.tar" --source "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar" --url "https://github.com/k3s-io/k3s/releases/download/${url_encoded_k3s_vers}/k3s-airgap-images-${ARCHITECTURE}.tar" --destination "${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar" info_log "FINISHED: ${FUNCNAME[0]}" } From 5e4f1965aa46a839e213718f8a66b72d6dcad07c Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sat, 27 Jul 2024 22:18:25 +0000 Subject: [PATCH 11/22] adding app removal to big_red --- scripts/big_red_button.sh | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/scripts/big_red_button.sh b/scripts/big_red_button.sh index ca62ada..579ffee 100755 --- a/scripts/big_red_button.sh +++ b/scripts/big_red_button.sh @@ -184,6 +184,33 @@ function prune_registry() { info_log "END: ${FUNCNAME[0]}" } +############################################################ +# Remove apps that we installed as part of setup +############################################################ +function remove_app(){ + local app="" + + while [[ "$#" -gt 0 ]]; do + case $1 in + --app) + shift + app=$1 + ;; + *) echo "Unknown parameter '$1'"; show_help ;; + esac + shift + done + + run_a_script "which -a ${app}" app_paths --ignore_error + for app_path in $app_paths; do + if [[ -f "$app_path" ]]; then + debug_log "Removing ${app} at $app_path" + run_a_script "sudo rm -f $app_path" + debug_log "...successfull removed old version of ${app} at $app_path" + fi + done +} + ############################################################ # Remove k3s data directory if its been changed ############################################################ @@ -214,17 +241,25 @@ function main() { show_header check_and_disable_k3s - stop_all_docker_containers remove_k3s prune_docker prune_registry + remove_k3s_data_dir info_log "Removing '${SPACEFX_DIR:?}'..." run_a_script "rm -rf ${SPACEFX_DIR:?}" info_log "...successfully removed '${SPACEFX_DIR:?}'" + remove_app --app "yq" + remove_app --app "jq" + remove_app --app "regctl" + remove_app --app "cfssl" + remove_app --app "cfssljson" + remove_app --app "helm" + + info_log "------------------------------------------" info_log "END: ${SCRIPT_NAME}" } From 377b038af173155d03a36b60cb500aa7b7a25437 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 00:41:42 +0000 Subject: [PATCH 12/22] adding spacefx.env to run_a_script --- env/spacefx.env | 4 ++++ modules/m_5_base.sh | 1 + 2 files changed, 5 insertions(+) diff --git a/env/spacefx.env b/env/spacefx.env index d52d237..c327241 100644 --- a/env/spacefx.env +++ b/env/spacefx.env @@ -11,3 +11,7 @@ VER_JQ=1.7.1 VER_YQ=4.44.2 VER_REGCTL=v0.5.7 KUBECONFIG=/etc/rancher/k3s/k3s.yaml + +INSTALL_K3S_SKIP_DOWNLOAD=true +INSTALL_K3S_SYMLINK=force +INSTALL_K3S_VERSION=v1.29.3+k3s1 \ No newline at end of file diff --git a/modules/m_5_base.sh b/modules/m_5_base.sh index 24d9ee0..e7dfe75 100755 --- a/modules/m_5_base.sh +++ b/modules/m_5_base.sh @@ -204,6 +204,7 @@ function run_a_script() { exec 0 >(tee $ROOT_TTY > "$script_temp_std_file") exec 2>&1 + [ -f "${SPACEFX_DIR}/env/spacefx.env" ] && source ${SPACEFX_DIR}/env/spacefx.env eval "${run_cmd}" > $script_temp_file echo $? > $script_temp_exit_code ) & From ab8029bf7e57742ce72aaf61ac4dff69100c14f8 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 01:32:44 +0000 Subject: [PATCH 13/22] updating to load ctr due to k3s bug --- env/spacefx.env | 6 +----- modules/m_5_base.sh | 1 - scripts/deploy/deploy_k3s.sh | 37 ++++++++++++++++++++++++++++++++++++ tests/dev_cluster.sh | 2 +- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/env/spacefx.env b/env/spacefx.env index c327241..0a22569 100644 --- a/env/spacefx.env +++ b/env/spacefx.env @@ -10,8 +10,4 @@ VER_K3S=v1.29.3+k3s1 VER_JQ=1.7.1 VER_YQ=4.44.2 VER_REGCTL=v0.5.7 -KUBECONFIG=/etc/rancher/k3s/k3s.yaml - -INSTALL_K3S_SKIP_DOWNLOAD=true -INSTALL_K3S_SYMLINK=force -INSTALL_K3S_VERSION=v1.29.3+k3s1 \ No newline at end of file +KUBECONFIG=/etc/rancher/k3s/k3s.yaml \ No newline at end of file diff --git a/modules/m_5_base.sh b/modules/m_5_base.sh index e7dfe75..24d9ee0 100755 --- a/modules/m_5_base.sh +++ b/modules/m_5_base.sh @@ -204,7 +204,6 @@ function run_a_script() { exec 0 >(tee $ROOT_TTY > "$script_temp_std_file") exec 2>&1 - [ -f "${SPACEFX_DIR}/env/spacefx.env" ] && source ${SPACEFX_DIR}/env/spacefx.env eval "${run_cmd}" > $script_temp_file echo $? > $script_temp_exit_code ) & diff --git a/scripts/deploy/deploy_k3s.sh b/scripts/deploy/deploy_k3s.sh index e10dc55..ec22d0a 100755 --- a/scripts/deploy/deploy_k3s.sh +++ b/scripts/deploy/deploy_k3s.sh @@ -111,6 +111,43 @@ SPACEFX_UPDATE_END" function wait_for_k3s_to_finish_initializing(){ info_log "START: ${FUNCNAME[0]}" + + + start_time=$(date +%s) + is_cmd_available "ctr" has_ctr_cmd + while [[ "${has_ctr_cmd}" == "false" ]]; do + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + if [[ $elapsed_time -ge $MAX_WAIT_SECS ]]; then + exit_with_error "Timed out waiting for k3s to come online." + fi + + info_log "...ctr not available yet. Rechecking in 5 seconds..." + sleep 5 + is_cmd_available "ctr" has_ctr_cmd + done + + info_log "ctr is available. Checking if images are needed..." + k3s_images=("klipper-helm" "klipper-lb" "local-path-provisioner" "mirrored-coredns-coredns" "mirrored-library-busybox" "mirrored-library-traefik" "mirrored-metrics-server" "mirrored-pause") + + run_a_script "ctr images list" ctr_images + + needs_images="false" + + for k3s_image in "${k3s_images[@]}"; do + if [[ "$ctr_images" != *"$k3s_image"* ]]; then + needs_images="true" + fi + done + + if [[ "${needs_images}" == "true" ]]; then + info_log "Detected missing mirrored images. Loading from '/var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar'..." + run_a_script "ctr images import /var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar" + info_log "Images successfully imported" + else + info_log "All k3s images are already loaded. Nothing to do." + fi + info_log "Waiting for k3s to finish initializing (max 5 mins)..." start_time=$(date +%s) diff --git a/tests/dev_cluster.sh b/tests/dev_cluster.sh index 99a7a42..5080281 100755 --- a/tests/dev_cluster.sh +++ b/tests/dev_cluster.sh @@ -67,7 +67,7 @@ devcontainer features package --force-clean-output-folder ${WORKING_DIR}/.devcon echo "Pushing the devcontainer feature '${REGISTRY}/${FEATURE}:${VERSION}'..." # Push the devcontainer feature tarball to the registry -oras push ${REGISTRY}/${FEATURE}:${VERSION} \ +oras push --disable-path-validation ${REGISTRY}/${FEATURE}:${VERSION} \ --config /dev/null:application/vnd.devcontainers \ --annotation org.opencontainers.image.source=https://github.com/microsoft/azure-orbital-space-sdk-setup \ ${ARTIFACT_PATH}:application/vnd.devcontainers.layer.v1+tar From bbd69ac1c87c23d8099df43d46a09db0a40845d0 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 01:37:12 +0000 Subject: [PATCH 14/22] moving k3s-uninstall to background due to environment override --- scripts/big_red_button.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/big_red_button.sh b/scripts/big_red_button.sh index 579ffee..83fcb40 100755 --- a/scripts/big_red_button.sh +++ b/scripts/big_red_button.sh @@ -122,7 +122,10 @@ function remove_k3s() { fi info_log "...k3s found. Uninstalling..." - [[ -f "/usr/local/bin/k3s-uninstall.sh" ]] && run_a_script "/usr/local/bin/k3s-uninstall.sh" + if [[ -f "/usr/local/bin/k3s-uninstall.sh" ]]; then + run_a_script "/usr/local/bin/k3s-uninstall.sh" k3s_uninstall_pid --background + wait $((k3s_uninstall_pid)) + fi info_log "...k3s successfully uninstalled" From 7d80deb0ca4cd40dc319457c5f90cd7c5c98a283 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 02:02:39 +0000 Subject: [PATCH 15/22] update to check for images loaded in docker or ctr --- scripts/deploy/deploy_k3s.sh | 80 +++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/scripts/deploy/deploy_k3s.sh b/scripts/deploy/deploy_k3s.sh index ec22d0a..0b772f8 100755 --- a/scripts/deploy/deploy_k3s.sh +++ b/scripts/deploy/deploy_k3s.sh @@ -104,16 +104,44 @@ SPACEFX_UPDATE_END" info_log "FINISHED: ${FUNCNAME[0]}" } - ############################################################ -# Wait for k3s to finish deploying by checking for running pods +# Check if the images need to be loaded into k3s ############################################################ -function wait_for_k3s_to_finish_initializing(){ +function load_images_to_k3s(){ info_log "START: ${FUNCNAME[0]}" + info_log "Validating images are loaded for k3s..." + + if [[ ! -f "/etc/systemd/system/k3s.service" ]]; then + info_log "/etc/systemd/system/k3s.service not found. Nothing to do." + info_log "FINISHED: ${FUNCNAME[0]}" + return + fi + + run_a_script "cat /etc/systemd/system/k3s.service" k3s_service_file + if [[ "$k3s_service_file" == *"--docker"* ]]; then + info_log "...docker detected. Validating images via docker..." + load_images_to_k3s_docker + else + info_log "...docker not detected. Validating images via ctr..." + load_images_to_k3s_ctr + fi + + info_log "Validated images are loaded" + info_log "FINISHED: ${FUNCNAME[0]}" +} + + +############################################################ +# Check if the images need to be loaded into k3s (via docker) +############################################################ +function load_images_to_k3s_ctr(){ + info_log "START: ${FUNCNAME[0]}" start_time=$(date +%s) + + is_cmd_available "ctr" has_ctr_cmd while [[ "${has_ctr_cmd}" == "false" ]]; do current_time=$(date +%s) @@ -141,13 +169,54 @@ function wait_for_k3s_to_finish_initializing(){ done if [[ "${needs_images}" == "true" ]]; then - info_log "Detected missing mirrored images. Loading from '/var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar'..." - run_a_script "ctr images import /var/lib/rancher/k3s/agent/images/k3s-airgap-images-${ARCHITECTURE}.tar" + info_log "Detected missing mirrored images. Loading from '${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar'..." + run_a_script "ctr images import ${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar" info_log "Images successfully imported" else info_log "All k3s images are already loaded. Nothing to do." fi + + info_log "FINISHED: ${FUNCNAME[0]}" +} + +############################################################ +# Check if the images need to be loaded into k3s (via docker) +############################################################ +function load_images_to_k3s_docker(){ + info_log "START: ${FUNCNAME[0]}" + + info_log "Checking if images are needed (docker)..." + k3s_images=("klipper-helm" "klipper-lb" "local-path-provisioner" "mirrored-coredns-coredns" "mirrored-library-busybox" "mirrored-library-traefik" "mirrored-metrics-server" "mirrored-pause") + + run_a_script "docker images" ctr_images + + needs_images="false" + + for k3s_image in "${k3s_images[@]}"; do + if [[ "$ctr_images" != *"$k3s_image"* ]]; then + needs_images="true" + fi + done + + if [[ "${needs_images}" == "true" ]]; then + info_log "Detected missing k3s images. Loading from '${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar'..." + run_a_script "docker load --input ${SPACEFX_DIR}/images/${ARCHITECTURE}/k3s-airgap-images-${ARCHITECTURE}.tar" + info_log "Images successfully imported" + else + info_log "All k3s images are already loaded. Nothing to do." + fi + + + info_log "FINISHED: ${FUNCNAME[0]}" +} + +############################################################ +# Wait for k3s to finish deploying by checking for running pods +############################################################ +function wait_for_k3s_to_finish_initializing(){ + info_log "START: ${FUNCNAME[0]}" + info_log "Waiting for k3s to finish initializing (max 5 mins)..." start_time=$(date +%s) @@ -198,6 +267,7 @@ function wait_for_k3s_to_finish_initializing(){ function main() { deploy_k3s_cluster + load_images_to_k3s wait_for_k3s_to_finish_initializing info_log "------------------------------------------" From 66338f1abcfc236c27740e7cf90234011f9c5e6a Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 02:32:22 +0000 Subject: [PATCH 16/22] updating coresvc_registry k3s check --- scripts/coresvc_registry.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/coresvc_registry.sh b/scripts/coresvc_registry.sh index 153d96b..4f535ba 100755 --- a/scripts/coresvc_registry.sh +++ b/scripts/coresvc_registry.sh @@ -72,7 +72,7 @@ function check_prerequisites(){ if [[ "${HAS_K3S}" == true ]]; then # We have k3s, so we need to check if it's running - run_a_script "pgrep \"k3s\"" k3s_status --ignore_error + run_a_script "ps | grep \"k3s server\"" k3s_status --ignore_error if [[ -z "${k3s_status}" ]]; then # k3s is installed but not running @@ -92,6 +92,10 @@ function check_prerequisites(){ DESTINATION_HOST="k3s" fi + if [[ "${HAS_DOCKER}" == false ]] && [[ "${HAS_K3S}" == false ]]; then + exit_with_error "No suitable environment found (HAS_DOCKER = 'false'. HAS_K#s = 'false'). Please install either Docker or K3s" + fi + [[ ! -d "${SPACEFX_DIR}/registry/data" ]] && create_directory "${SPACEFX_DIR}/registry/data" [[ ! -d "${SPACEFX_DIR}/registry/pypiserver" ]] && create_directory "${SPACEFX_DIR}/registry/pypiserver" [[ ! -d "${SPACEFX_DIR}/certs/registry" ]] && create_directory "${SPACEFX_DIR}/certs/registry" From 93eb5e18302ea16a8f4cc4746ccb880b9b47bd54 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 02:36:57 +0000 Subject: [PATCH 17/22] adding logging for k3s removal --- scripts/big_red_button.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/big_red_button.sh b/scripts/big_red_button.sh index 83fcb40..87f42b3 100755 --- a/scripts/big_red_button.sh +++ b/scripts/big_red_button.sh @@ -124,6 +124,7 @@ function remove_k3s() { info_log "...k3s found. Uninstalling..." if [[ -f "/usr/local/bin/k3s-uninstall.sh" ]]; then run_a_script "/usr/local/bin/k3s-uninstall.sh" k3s_uninstall_pid --background + debug_log "...wating for k3s to finish uninstalling (pid $k3s_uninstall_pid)..." wait $((k3s_uninstall_pid)) fi From 0243e0ada29bcff578a5d7785aa7c0e3a0defec5 Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 03:06:36 +0000 Subject: [PATCH 18/22] adjusting path array to remove k3s references on big_red --- scripts/big_red_button.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/big_red_button.sh b/scripts/big_red_button.sh index 87f42b3..cb16e1d 100755 --- a/scripts/big_red_button.sh +++ b/scripts/big_red_button.sh @@ -128,6 +128,22 @@ function remove_k3s() { wait $((k3s_uninstall_pid)) fi + info_log "Cleaning \$PATH array of any k3s references" + + #Loop through the PATH array and remove any paths that contain 'k3s' + IFS=':' read -r -a path_array <<< "$PATH" + + cleaned_paths=() + for path in "${path_array[@]}"; do + if [[ "$path" != *k3s* ]]; then + cleaned_paths+=("$path") + fi + done + + # Rebuild the PATH array and export it back out + cleaned_path=$(IFS=:; echo "${cleaned_paths[*]}") + export PATH=$cleaned_path + info_log "...k3s successfully uninstalled" From ead9cdf721ef60966b15599de43236c35929f41d Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 03:14:43 +0000 Subject: [PATCH 19/22] adding pgrep check --- scripts/coresvc_registry.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/coresvc_registry.sh b/scripts/coresvc_registry.sh index 4f535ba..adc076d 100755 --- a/scripts/coresvc_registry.sh +++ b/scripts/coresvc_registry.sh @@ -65,6 +65,7 @@ function check_prerequisites(){ is_cmd_available "docker" HAS_DOCKER is_cmd_available "kubectl" HAS_K3S + is_cmd_available "pgrep" HAS_PGREP if [[ "${HAS_K3S}" == true ]]; then # if we have kubectl, then check if we have k3s @@ -72,7 +73,12 @@ function check_prerequisites(){ if [[ "${HAS_K3S}" == true ]]; then # We have k3s, so we need to check if it's running - run_a_script "ps | grep \"k3s server\"" k3s_status --ignore_error + if [[ "${HAS_PGREP}" == true ]]; then + run_a_script "pgrep \"k3s\"" k3s_status --ignore_error + else + run_a_script "ps | grep \"k3s server\"" k3s_status --ignore_error + fi + if [[ -z "${k3s_status}" ]]; then # k3s is installed but not running From 38eff1d0d3663384192d2725b277b5b2e0c6e47a Mon Sep 17 00:00:00 2001 From: BigTallCampbell Date: Sun, 28 Jul 2024 03:22:22 +0000 Subject: [PATCH 20/22] updating for hosts that dont have pgrep --- scripts/big_red_button.sh | 17 +++++++++++------ scripts/coresvc_registry.sh | 12 ++++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/big_red_button.sh b/scripts/big_red_button.sh index cb16e1d..a9a9b8a 100755 --- a/scripts/big_red_button.sh +++ b/scripts/big_red_button.sh @@ -179,9 +179,14 @@ function prune_docker() { function prune_registry() { info_log "START: ${FUNCNAME[0]}" + is_cmd_available "pgrep" HAS_PGREP info_log "Stopping registry processes (if still running)" - run_a_script "pgrep '^registry'" pids --ignore_error + if [[ "${HAS_PGREP}" == true ]]; then + run_a_script "pgrep '^registry'" pids --ignore_error + else + run_a_script "ps aux | grep '^registry' | grep -v grep | awk '{print \$2}'" pids --ignore_error + fi for pid in $pids; do debug_log "...terminating process id '${pid}'" @@ -192,12 +197,12 @@ function prune_registry() { info_log "Stopping pypiserver processes (if still running)" - run_a_script "pgrep '^pypiserver'" pids --ignore_error + if [[ "${HAS_PGREP}" == true ]]; then + run_a_script "pgrep '^pypiserver'" pids --ignore_error + else + run_a_script "ps aux | grep '^pypiserver' | grep -v grep | awk '{print \$2}'" pids --ignore_error + fi - for pid in $pids; do - debug_log "...terminating process id '${pid}'" - run_a_script "kill -9 ${pid}" --disable_log --ignore_error - done info_log "...successfully stopped pypiserver processes." diff --git a/scripts/coresvc_registry.sh b/scripts/coresvc_registry.sh index adc076d..977c859 100755 --- a/scripts/coresvc_registry.sh +++ b/scripts/coresvc_registry.sh @@ -202,7 +202,11 @@ function stop_registry(){ fi info_log "Stopping registry processes (if still running)" - run_a_script "pgrep '^registry'" pids --ignore_error + if [[ "${HAS_PGREP}" == true ]]; then + run_a_script "pgrep '^registry'" pids --ignore_error + else + run_a_script "ps aux | grep '^registry' | grep -v grep | awk '{print \$2}'" pids --ignore_error + fi for pid in $pids; do debug_log "...terminating process id '${pid}'" @@ -213,7 +217,11 @@ function stop_registry(){ info_log "Stopping pypiserver processes (if still running)" - run_a_script "pgrep '^pypiserver'" pids --ignore_error + if [[ "${HAS_PGREP}" == true ]]; then + run_a_script "pgrep '^pypiserver'" pids --ignore_error + else + run_a_script "ps aux | grep '^pypiserver' | grep -v grep | awk '{print \$2}'" pids --ignore_error + fi for pid in $pids; do debug_log "...terminating process id '${pid}'" From 26525cf578fd7ff56d5c8fee8ae9c04cd6451e18 Mon Sep 17 00:00:00 2001 From: Ryan Campbell Date: Sun, 28 Jul 2024 13:49:25 -0500 Subject: [PATCH 21/22] typo in pypi-server pruning --- scripts/big_red_button.sh | 4 ++-- scripts/coresvc_registry.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/big_red_button.sh b/scripts/big_red_button.sh index a9a9b8a..6ab921b 100755 --- a/scripts/big_red_button.sh +++ b/scripts/big_red_button.sh @@ -198,9 +198,9 @@ function prune_registry() { info_log "Stopping pypiserver processes (if still running)" if [[ "${HAS_PGREP}" == true ]]; then - run_a_script "pgrep '^pypiserver'" pids --ignore_error + run_a_script "pgrep '^pypi-server'" pids --ignore_error else - run_a_script "ps aux | grep '^pypiserver' | grep -v grep | awk '{print \$2}'" pids --ignore_error + run_a_script "ps aux | grep '^pypi-server' | grep -v grep | awk '{print \$2}'" pids --ignore_error fi diff --git a/scripts/coresvc_registry.sh b/scripts/coresvc_registry.sh index 977c859..fb5ba20 100755 --- a/scripts/coresvc_registry.sh +++ b/scripts/coresvc_registry.sh @@ -218,9 +218,9 @@ function stop_registry(){ info_log "Stopping pypiserver processes (if still running)" if [[ "${HAS_PGREP}" == true ]]; then - run_a_script "pgrep '^pypiserver'" pids --ignore_error + run_a_script "pgrep '^pypi-server'" pids --ignore_error else - run_a_script "ps aux | grep '^pypiserver' | grep -v grep | awk '{print \$2}'" pids --ignore_error + run_a_script "ps aux | grep '^pypi-server' | grep -v grep | awk '{print \$2}'" pids --ignore_error fi for pid in $pids; do From 0145845e1ac4fa6f3241ccbf4054874d52780341 Mon Sep 17 00:00:00 2001 From: Ryan Campbell Date: Sun, 28 Jul 2024 13:53:04 -0500 Subject: [PATCH 22/22] updating typo in big_red that pypi server was not enumerated --- scripts/big_red_button.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/big_red_button.sh b/scripts/big_red_button.sh index 6ab921b..22f1b83 100755 --- a/scripts/big_red_button.sh +++ b/scripts/big_red_button.sh @@ -203,6 +203,11 @@ function prune_registry() { run_a_script "ps aux | grep '^pypi-server' | grep -v grep | awk '{print \$2}'" pids --ignore_error fi + for pid in $pids; do + debug_log "...terminating process id '${pid}'" + run_a_script "kill -9 ${pid}" --disable_log --ignore_error + done + info_log "...successfully stopped pypiserver processes."