Skip to content

Commit

Permalink
Stage and deploy sdk services (#34)
Browse files Browse the repository at this point in the history
* adding logging to auto added artifacts and adjusting big_red to disable k3s before docker prune

* Adding sdkservice deployment

* setting DEV_Environment to true temporarily

* adding all SDK services to tests

* adding all.sh to tests and updating for working directory

* Updating all to _all

---------

Co-authored-by: Ryan Campbell <rycampbe@microsoft.com>
  • Loading branch information
bigtallcampbell and Ryan Campbell authored Jun 19, 2024
1 parent 5b446c3 commit f96371a
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 105 deletions.
17 changes: 0 additions & 17 deletions .vscode/launch.json

This file was deleted.

35 changes: 0 additions & 35 deletions .vscode/tasks.json

This file was deleted.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ 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

[[ ! -d "./output" ]] && sudo mkdir ./output
# 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 .
```

Expand Down
8 changes: 7 additions & 1 deletion modules/m_110_debugshim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ function _auto_add_downloads() {
case "${APP_TYPE}" in
"sdk-service")
DOWNLOAD_ARTIFACTS+=("Microsoft.Azure.SpaceSDK.Core.${SPACEFX_VERSION}.nupkg")
DOWNLOAD_ARTIFACTS+=("Common.proto")
;;
esac

Expand All @@ -127,5 +126,12 @@ function _auto_add_downloads() {
# EXTRA_PACKAGES+=("nuget")
# fi

debug_log "Artifacts queued to download:"
for i in "${!DOWNLOAD_ARTIFACTS[@]}"; do
DOWNLOAD_ARTIFACT=${DOWNLOAD_ARTIFACTS[i]}
debug_log "...Artifact: ${DOWNLOAD_ARTIFACT}"
done


info_log "END: ${FUNCNAME[0]}"
}
100 changes: 60 additions & 40 deletions scripts/big_red_button.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,48 +51,21 @@ function show_header() {
info_log " |___/ "
}




############################################################
# Uninstall k3s
# Stops the k3s service if it's running
############################################################
function remove_k3s() {
info_log "START: ${FUNCNAME[0]}"

info_log "Removing k3s..."

is_cmd_available "k3s" has_cmd
# shellcheck disable=SC2154
if [[ "${has_cmd}" == false ]]; then
info_log "...k3s not found. Nothing do to"
info_log "END: ${FUNCNAME[0]}"
return
fi

run_a_script "systemctl is-active k3s" K3S_STATUS --ignore_error
if [[ "${K3S_STATUS}" == "active" ]]; then
info_log "...stopping k3s..."
function check_and_disable_k3s() {
if [[ -f "/etc/systemd/system/k3s.service" ]]; then
info_log "Disabling k3s service"
run_a_script "systemctl disable k3s"
run_a_script "systemctl stop k3s"
fi

info_log "...uninstalling k3s..."
[[ -f "/usr/local/bin/k3s-uninstall.sh" ]] && run_a_script "/usr/local/bin/k3s-uninstall.sh"

info_log "...k3s successfully removed"

info_log "...cleaned docker containers (if applicable)..."
purge_docker
info_log "...successfully cleaned docker containers (if applicable)."

info_log "END: ${FUNCNAME[0]}"
}


############################################################
# Remove everything in docker
# Stops and removes all docker containers
############################################################
function purge_docker() {
function stop_all_docker_containers() {
info_log "START: ${FUNCNAME[0]}"

is_cmd_available "docker" has_cmd
Expand All @@ -104,14 +77,15 @@ function purge_docker() {
return
fi

info_log "Pausing all docker containers..."
run_a_script "docker ps -q" all_docker_containers --disable_log

for container_id in $all_docker_containers; do
info_log "...pausing container id ${container_id}..."
run_a_script "docker pause ${container_id}" --ignore_error --disable_log
done

info_log "Stoping all docker containers..."
info_log "...stopping container processes..."

docker_pids=$(ps -e | grep 'containerd-shim' | awk '{print $1}')

Expand All @@ -120,7 +94,7 @@ function purge_docker() {
run_a_script "kill -9 $pid" --disable_log
done

info_log "Removing all docker containers...."
info_log "...removing containers...."
run_a_script "docker ps -a -q" all_docker_containers --disable_log

for container_id in $all_docker_containers; do
Expand All @@ -130,21 +104,67 @@ function purge_docker() {

info_log "...all docker containers removed."

info_log "Purging docker..."
info_log "END: ${FUNCNAME[0]}"
}

############################################################
# Uninstall k3s
############################################################
function remove_k3s() {
info_log "START: ${FUNCNAME[0]}"

is_cmd_available "k3s" has_cmd
# shellcheck disable=SC2154
if [[ "${has_cmd}" == false ]]; then
info_log "...k3s not found. Nothing do to"
info_log "END: ${FUNCNAME[0]}"
return
fi

info_log "...k3s found. Uninstalling..."
[[ -f "/usr/local/bin/k3s-uninstall.sh" ]] && run_a_script "/usr/local/bin/k3s-uninstall.sh"

info_log "...k3s successfully uninstalled"


info_log "END: ${FUNCNAME[0]}"
}


############################################################
# Prune Docker
############################################################
function prune_docker() {
info_log "START: ${FUNCNAME[0]}"

is_cmd_available "docker" has_cmd

# shellcheck disable=SC2154
if [[ "${has_cmd}" == false ]]; then
info_log "...docker not found. Nothing do to"
info_log "END: ${FUNCNAME[0]}"
return
fi

info_log "Pruning docker..."
run_a_script "docker system prune --all --volumes --force"
info_log "...docker purged."
info_log "...docker pruned."

info_log "END: ${FUNCNAME[0]}"
}

function main() {
show_header

purge_docker
remove_k3s
check_and_disable_k3s

stop_all_docker_containers
remove_k3s
prune_docker

info_log "Removing '${SPACEFX_DIR:?}'..."
run_a_script "rm -rf ${SPACEFX_DIR:?}"
info_log "...successfully removed '${SPACEFX_DIR:?}'"

info_log "------------------------------------------"
info_log "END: ${SCRIPT_NAME}"
Expand Down
19 changes: 19 additions & 0 deletions scripts/coresvc_registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ SPACEFX_UPDATE_END"
function start_registry_docker(){
info_log "START: ${FUNCNAME[0]}"

info_log "Checking if '${REGISTRY_REPO}' is already running in Docker..."

run_a_script "docker container ls -a --format '{{json .}}' | jq -r 'if any(.Names; .== \"${REGISTRY_REPO}\") then .State else empty end'" container_status

if [[ "${container_status}" == "running" ]]; then
info_log "...found previous instance of '${REGISTRY_REPO}' in running in Docker. Nothing to do"
info_log "END: ${FUNCNAME[0]}"
return
fi

# Container status is not empty, but not "running" either. There's a stopped container that we need to remove
if [[ -n "${container_status}" ]]; then
info_log "...found non-running instance of '${REGISTRY_REPO}' in Docker. Removing..."
run_a_script "docker container rm ${REGISTRY_REPO} -f"
info_log "...successfully removed ${REGISTRY_REPO} in Docker"
fi

# Calculate the image tag based on the channel and then check the registries to find it
info_log "Locating parent registry and calculating tags for '${REGISTRY_REPO}'..."
calculate_tag_from_channel --tag "${SPACEFX_VERSION}" --result spacefx_version_tag
Expand All @@ -243,6 +260,8 @@ function start_registry_docker(){
fi




info_log "Starting '${REGISTRY_REPO}'..."
run_a_script "docker run -d \
-p 5000:5000 \
Expand Down
32 changes: 31 additions & 1 deletion scripts/deploy_spacefx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function show_help() {
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--help) show_help ;;
--dev-environment) DEV_ENVIRONMENT=true ;;
*) echo "Unknown parameter '$1'"; show_help ;;
esac
shift
Expand Down Expand Up @@ -69,7 +70,6 @@ function deploy_spacefx_service_group(){
info_log "START: ${FUNCNAME[0]}"

local service_group=""
local stage_container_img_cmd=""
local deploy_group_cmd=""
local wait_for_deployment=false

Expand Down Expand Up @@ -192,6 +192,33 @@ function deploy_regctl_to_deployment_service(){
info_log "FINISHED: ${FUNCNAME[0]}"
}

############################################################
# Run any yaml files found in yamls/deploy directory
############################################################
function deploy_prestaged_yamls(){
info_log "START: ${FUNCNAME[0]}"

info_log "Deploying any pre-staged yaml files found in '${SPACEFX_DIR}/yamls/deploy'..."
if [[ ! -d "${SPACEFX_DIR}/yamls/deploy" ]]; then
info_log "'${SPACEFX_DIR}/yamls/deploy' doesn't exist. Nothing to do."
info_log "FINISHED: ${FUNCNAME[0]}"
return
fi
while read -r yamlFile; do
info_log "Deploying '${yamlFile}'..."
run_a_script "kubectl --kubeconfig ${KUBECONFIG} apply -f ${yamlFile}" --ignore_error
if [[ "${RETURN_CODE}" == 0 ]]; then
info_log "...'${yamlFile}' successfully deployed."
else
error_log "...'${yamlFile}' failed to deploy. See logs for more information."
fi
done < <(find "${SPACEFX_DIR}/yamls/deploy" -iname "*.yaml")

info_log "All pre-staged yaml files have been deployed."

info_log "FINISHED: ${FUNCNAME[0]}"
}


function main() {
write_parameter_to_log ARCHITECTURE
Expand All @@ -207,8 +234,11 @@ function main() {
run_a_script "${SPACEFX_DIR}/scripts/deploy/deploy_chart_dependencies.sh"

deploy_spacefx_service_group --service_group core --wait_for_deployment
deploy_spacefx_service_group --service_group platform
deploy_spacefx_service_group --service_group host

deploy_regctl_to_deployment_service
deploy_prestaged_yamls


info_log "------------------------------------------"
Expand Down
Loading

0 comments on commit f96371a

Please sign in to comment.