From 75c005020dff678889cf0be030f339f333efe68f Mon Sep 17 00:00:00 2001 From: Neveh Allon <34620850+nevehallon@users.noreply.github.com> Date: Thu, 27 May 2021 14:26:43 +0300 Subject: [PATCH 1/4] include check for multi-arch support in case proccess times out --- cli.sh | 35 ++++++++++++++++++++++++----------- spec/cli_spec.sh | 8 ++++---- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cli.sh b/cli.sh index 16bf0e9..c636217 100755 --- a/cli.sh +++ b/cli.sh @@ -26,7 +26,7 @@ lokl_log() { timestamp="$(date '+%H:%M:%S')" echo "$timestamp: $1" >> /tmp/lokldebuglog -} +} set_docker_tag() { # shellcheck disable=SC2154 @@ -131,6 +131,18 @@ test_docker_available() { fi } +test_multi_arch_available() { + if ! grep -q 'arm64' /var/lib/dpkg/arch > /dev/null 2>&1 + then + echo "\033[0;33m" # color change + echo "â„šī¸ You're system might not support this docker image architecture." + echo "\033[0;32m" # color change + echo "Try again with lokl/lokl:latest as your lokl version." + echo "--> See 🔗 https://github.com/leonstafford/lokl#container-parameters." + echo "\033[0m" # revert color changes + fi +} + create_site_choose_php_version() { clear echo "" @@ -189,7 +201,7 @@ create_site_choose_name() { if [ "$LOKL_TEST_MODE" ]; then lokl_log "Empty or invalid site name entered" # early exit when testing for easier assertion - exit 1 + exit 1 fi # re-ask for name entry if input was invalid @@ -219,9 +231,9 @@ create_wordpress_docker_container() { if [ "$LOKL_NONINTERACTIVE_MODE" ]; then lokl_log "Site successfully launched non-interactively" - exit 0 + exit 0 fi - + clear echo "Your new Lokl WordPress site, $LOKL_NAME, is ready at:" @@ -233,7 +245,7 @@ create_wordpress_docker_container() { # return for assertion while testing if [ "$LOKL_TEST_MODE" ]; then lokl_log "Returning early for assertion under test runner" - exit 0 + exit 0 fi read -r "" @@ -251,12 +263,13 @@ wait_for_site_reachable() { max_attempts="$(set_curl_timeout_max_attempts "$LOKL_TEST_MODE")" site_poll_sleep_duration="$(set_site_poll_sleep_duration "$LOKL_TEST_MODE")" - lokl_log "Waiting for: $max_attempts curl timeout attempts" + lokl_log "Waiting for: $max_attempts curl timeout attempts" until curl --output /dev/null --silent --head --fail "http://localhost:$lokl_port"; do if [ ${attempt_counter} -eq "${max_attempts}" ]; then echo "Timed out waiting for site to come online..." + test_multi_arch_available exit 1 fi @@ -277,7 +290,7 @@ manage_sites_menu() { echo "" LOKL_CONTAINERS="$(get_lokl_container_ids)" - + # handle no container if [ -z "$LOKL_CONTAINERS" ]; then echo "" @@ -310,7 +323,7 @@ manage_sites_menu() { if [ ! -f "/tmp/lokl_containers_cache/$site_to_manage_choice" ]; then echo "Requested site not found, try again" manage_sites_menu - else + else manage_single_site fi } @@ -373,7 +386,7 @@ manage_single_site() { clear # load lokl container info from cache file - CONTAINER_INFO=$(cat "/tmp/lokl_containers_cache/$site_to_manage_choice") + CONTAINER_INFO=$(cat "/tmp/lokl_containers_cache/$site_to_manage_choice") CONTAINER_ID=$(echo "$CONTAINER_INFO" | cut -f1 -d,) CONTAINER_NAME=$(echo "$CONTAINER_INFO" | cut -f2 -d,) CONTAINER_PORT=$(echo "$CONTAINER_INFO" | cut -f3 -d,) @@ -443,7 +456,7 @@ take_site_backup() { if [ ! -f "/tmp/${CONTAINER_NAME}_SITE_BACKUP.tar.gz" ]; then echo "Failed to save backup, try again" exit 1 - else + else echo "Backup complete" echo "" exit 0 @@ -582,7 +595,7 @@ generate_site_list() { # print choices for user echo "$SITE_COUNTER) $CONTAINER_NAME" - # append choices in cache file named for site counter (brittle internal ID) + # append choices in cache file named for site counter (brittle internal ID) echo "$CONTAINER_ID,$CONTAINER_NAME,$CONTAINER_PORT,$CONTAINER_STATE" >> /tmp/lokl_containers_cache/$SITE_COUNTER SITE_COUNTER=$((SITE_COUNTER+1)) diff --git a/spec/cli_spec.sh b/spec/cli_spec.sh index 42ed91e..41244f7 100644 --- a/spec/cli_spec.sh +++ b/spec/cli_spec.sh @@ -180,7 +180,7 @@ Describe "cli.sh" It "returns random port between 4000 and 5000" # shellcheck disable=SC2154 acceptable_port_number() { - [ "$acceptable_port_number" -ge 3999 ] && [ "$acceptable_port_number" -le 5001 ] + [ "$acceptable_port_number" -ge 3999 ] && [ "$acceptable_port_number" -le 5001 ] } When call get_random_port @@ -315,7 +315,7 @@ f089aa00ac98 Describe "set_site_name()" It "remains empty if $lokl_site_name not set" When call set_site_name - The output should equal '' + The output should equal '' The status should be success End @@ -423,7 +423,7 @@ f089aa00ac98 Describe "create_site_choose_name()" It "sets LOKL_NAME to site name when proper name is given" - # mock test_core_capabilities as not core to this test + # mock test_core_capabilities as not core to this test test_core_capabilities() { return 0 } @@ -488,7 +488,7 @@ f089aa00ac98 } When run wait_for_site_reachable "mywptestsitename" "4070" - The lines of stdout should equal 5 + The lines of stdout should equal 11 The stdout should include 'Timed out waiting for site to come online..' The status should be failure End From a0d2cd15e7407ed8ffddcd4f3337ef312fae92cf Mon Sep 17 00:00:00 2001 From: Neveh Allon <34620850+nevehallon@users.noreply.github.com> Date: Thu, 27 May 2021 15:25:23 +0300 Subject: [PATCH 2/4] check if either arcchitecture is misiing --- cli.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli.sh b/cli.sh index 326c053..931acca 100755 --- a/cli.sh +++ b/cli.sh @@ -132,7 +132,7 @@ test_docker_available() { } test_multi_arch_available() { - if ! grep -q 'arm64' /var/lib/dpkg/arch > /dev/null 2>&1 + if ! grep -q 'arm64 \|amd64' /var/lib/dpkg/arch > /dev/null 2>&1 then echo "\033[0;33m" # color change echo "â„šī¸ You're system might not support this docker image architecture." @@ -305,8 +305,8 @@ choose_lokl_site_template() { lokl_log "Concatenated volumes to mount:" lokl_log "$VOLUMES_TO_MOUNT" - - # set Lokl PHP version variable + + # set Lokl PHP version variable # set mount paths break From 8f3323d2c03a79b9f7362b0fbcc1835f688d34d6 Mon Sep 17 00:00:00 2001 From: Neveh Allon <34620850+nevehallon@users.noreply.github.com> Date: Tue, 1 Jun 2021 11:40:28 +0300 Subject: [PATCH 3/4] use more compatible uname command --- cli.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli.sh b/cli.sh index 0454dc7..6f78791 100755 --- a/cli.sh +++ b/cli.sh @@ -132,7 +132,7 @@ test_docker_available() { } test_multi_arch_available() { - if ! grep -q 'arm64 \|amd64' /var/lib/dpkg/arch > /dev/null 2>&1 + if ! uname -m | grep -q 'arm64 \|x86_64' > /dev/null 2>&1 then echo "\033[0;33m" # color change echo "â„šī¸ You're system might not support this docker image architecture." @@ -315,13 +315,13 @@ choose_lokl_site_template() { # set Lokl PHP version variable # set mount paths - + done < "$TEMPLATE_FILE" lokl_log "Concatenated volumes to mount:" lokl_log "$VOLUMES_TO_MOUNT" - - # set Lokl PHP version variable + + # set Lokl PHP version variable # set mount paths break From 6174f7550e620f204bbeaa28ee9097fceaf916b2 Mon Sep 17 00:00:00 2001 From: Neveh Allon <34620850+nevehallon@users.noreply.github.com> Date: Tue, 1 Jun 2021 13:04:54 +0300 Subject: [PATCH 4/4] refactor --- cli.sh | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cli.sh b/cli.sh index 6f78791..e542659 100755 --- a/cli.sh +++ b/cli.sh @@ -132,14 +132,16 @@ test_docker_available() { } test_multi_arch_available() { - if ! uname -m | grep -q 'arm64 \|x86_64' > /dev/null 2>&1 + if + ( ( ! uname -m | grep -q 'arm64 \|x86_64 \|aarch64_be \|aarch64 \|arm8b \|arm8l') ) || + ( ( ! docker buildx ls | grep -q 'arm64 \|amd64' ) ) then - echo "\033[0;33m" # color change - echo "â„šī¸ You're system might not support this docker image architecture." - echo "\033[0;32m" # color change - echo "Try again with lokl/lokl:latest as your lokl version." - echo "--> See 🔗 https://github.com/leonstafford/lokl#container-parameters." - echo "\033[0m" # revert color changes + echo "\033[0;33m" # color change + echo "â„šī¸ You're system might not support this docker image architecture." + echo "\033[0;32m" # color change + echo "Try again with lokl/lokl:latest as your lokl version." + echo "--> See 🔗 https://github.com/leonstafford/lokl#container-parameters." + echo "\033[0m" # revert color changes fi }