From ba153765a76d32ab8d527db2c40f28891b2f9be5 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Mon, 20 Mar 2023 12:58:33 -0400 Subject: [PATCH] Load cached lxd images if any. --- create_lxc_base.sh | 13 ++++++------- www/go.sh | 2 +- www/stop_docker_stacks.sh | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/create_lxc_base.sh b/create_lxc_base.sh index 740db66..8137954 100755 --- a/create_lxc_base.sh +++ b/create_lxc_base.sh @@ -7,13 +7,12 @@ bash -c "./stub_lxc_profile.sh --lxd-hostname=$BASE_IMAGE_VM_NAME" # let's download our base image. if ! lxc image list --format csv --columns l | grep -q "$UBUNTU_BASE_IMAGE_NAME"; then - # if the image doesn't exist, download it from Ubuntu's image server - # TODO see if we can fetch this file from a more censorship-resistant source, e.g., ipfs - # we don't really need to cache this locally since it gets continually updated upstream. - if [ -d "$SS_JAMMY_PATH" ]; then - lxc image import "$SS_JAMMY_PATH/meta-bf1a2627bdddbfb0a9bf1f8ae146fa794800c6c91281d3db88c8d762f58bd057.tar.xz" \ - "$SS_JAMMY_PATH/bf1a2627bdddbfb0a9bf1f8ae146fa794800c6c91281d3db88c8d762f58bd057.qcow2" \ - --alias "$UBUNTU_BASE_IMAGE_NAME" + # if the image if cached locally, import it from disk, otherwise download it from ubuntu + IMAGE_IDENTIFIER=$(find "$SS_JAMMY_PATH" | grep ".qcow2" | head -n1 | cut -d "." -f1) + METADATA_FILE="$SS_JAMMY_PATH/meta-$IMAGE_IDENTIFIER.tar.xz" + IMAGE_FILE="$SS_JAMMY_PATH/$IMAGE_IDENTIFIER.qcow2" + if [ -d "$SS_JAMMY_PATH" ] && [ -f "$METADATA_FILE" ] && [ -f "$IMAGE_FILE" ]; then + lxc image import "$METADATA_FILE" "$IMAGE_FILE" --alias "$UBUNTU_BASE_IMAGE_NAME" else # copy the image down from canonical. lxc image copy "images:$BASE_LXC_IMAGE" "$REMOTE_NAME": --alias "$UBUNTU_BASE_IMAGE_NAME" --public --vm --auto-update diff --git a/www/go.sh b/www/go.sh index a8513f2..f980664 100755 --- a/www/go.sh +++ b/www/go.sh @@ -90,7 +90,7 @@ if [ "$RESTART_FRONT_END" = true ]; then if docker stack list --format "{{.Name}}" | grep -q reverse-proxy; then sleep 2 - docker stack down reverse-proxy + docker stack rm reverse-proxy # wait for all docker containers to stop. # TODO see if there's a way to check for this. diff --git a/www/stop_docker_stacks.sh b/www/stop_docker_stacks.sh index eaceecb..95b8817 100755 --- a/www/stop_docker_stacks.sh +++ b/www/stop_docker_stacks.sh @@ -20,7 +20,7 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do STACK_NAME="$DOMAIN_IDENTIFIER-$APP-$LANGUAGE_CODE" if docker stack list --format "{{.Name}}" | grep -q "$STACK_NAME"; then - docker stack down "$STACK_NAME" + docker stack rm "$STACK_NAME" sleep 2 fi