From d46b63768f0d5cb6abfaafcf77bf9026e31bade2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Fri, 26 Apr 2024 14:51:22 +0200 Subject: [PATCH] Fix demo script --- cmd/demo.go | 12 +++++++- cmd/demo_scripts/create_qovery_demo.sh | 38 ++++++++++++++++++++------ 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/cmd/demo.go b/cmd/demo.go index ef605f4d..ad8747aa 100644 --- a/cmd/demo.go +++ b/cmd/demo.go @@ -8,6 +8,9 @@ import ( "os" "os/exec" "os/user" + "regexp" + "runtime" + "strings" ) var demoCmd = &cobra.Command{ @@ -34,13 +37,20 @@ var demoCmd = &cobra.Command{ } if args[0] == "up" { + regex := "^[a-zA-Z][-a-z]+[a-zA-Z]$" + match, _ := regexp.MatchString(regex, demoClusterName) + if !match { + log.Errorf("cluster name must match regex %s: got %s", regex, demoClusterName) + os.Exit(1) + } + err := os.WriteFile("create_demo_cluster.sh", demoScriptsCreate, 0700) if err != nil { log.Errorf("Cannot write file to disk: %s", err) os.Exit(1) } - cmd := exec.Command("/bin/sh", "create_demo_cluster.sh", demoClusterName, organizationId, string(token)) + cmd := exec.Command("/bin/sh", "create_demo_cluster.sh", demoClusterName, strings.ToUpper(runtime.GOARCH), organizationId, string(token)) cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { diff --git a/cmd/demo_scripts/create_qovery_demo.sh b/cmd/demo_scripts/create_qovery_demo.sh index 9c15e84f..1fa312d8 100755 --- a/cmd/demo_scripts/create_qovery_demo.sh +++ b/cmd/demo_scripts/create_qovery_demo.sh @@ -1,15 +1,19 @@ #!/bin/sh -set -euo pipefail +set -eu CLUSTER_NAME=$1 -ORGANIZATION_ID=$2 -if [ "${3:0:4}" = "qov_" ] -then - AUTHORIZATION_HEADER="Authorization: Token $3" -else - AUTHORIZATION_HEADER="Authorization: Bearer $3" -fi +ARCH=$2 +ORGANIZATION_ID=$3 +case $3 in + qov_*) + AUTHORIZATION_HEADER="Authorization: Token $4" + ;; + + *) + AUTHORIZATION_HEADER="Authorization: Bearer $4" + ;; +esac get_or_create_on_premise_account() { accountId=$(curl -s --fail-with-body -H "${AUTHORIZATION_HEADER}" -H 'Content-Type: application/json' https://api.qovery.com/organization/"${ORGANIZATION_ID}"/onPremise/credentials | jq -r .results[0].id) @@ -74,18 +78,35 @@ install_deps() { echo "jq already installed" else echo "jq command is missing. Please use your package manager to install it" + exit 1 fi if which grep >/dev/null; then echo "grep already installed" else echo "grep command is missing. Please use your package manager to install it" + exit 1 + fi + + if which sed >/dev/null; then + echo "sed already installed" + else + echo "sed command is missing. Please use your package manager to install it" + exit 1 fi if which curl >/dev/null; then echo "curl already installed" else echo "curl command is missing. Please use your package manager to install it" + exit 1 + fi + + if which docker >/dev/null; then + echo "docker already installed" + else + echo "docker command is missing. Please use your package manager to install it" + exit 1 fi if which k3d >/dev/null; then @@ -120,6 +141,7 @@ echo 'Fetching Qovery values to setup your cluster' echo '""""""""""""""""""""""""""""""""""""""""""""' get_cluster_values "${clusterId}" > values.yaml echo "" >> values.yaml +sed -i 's/AMD64/'"$ARCH"'/g' values.yaml curl -s -L https://raw.githubusercontent.com/Qovery/qovery-chart/main/charts/qovery/values-demo-local.yaml | grep -vE 'set-by-customer|^qovery:' >> values.yaml echo 'Helm values written into values.yaml'