Skip to content

Commit

Permalink
Fix demo script
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe committed Apr 26, 2024
1 parent 430f6d5 commit d46b637
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
12 changes: 11 additions & 1 deletion cmd/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"os"
"os/exec"
"os/user"
"regexp"
"runtime"
"strings"
)

var demoCmd = &cobra.Command{
Expand All @@ -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 {
Expand Down
38 changes: 30 additions & 8 deletions cmd/demo_scripts/create_qovery_demo.sh
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'

Expand Down

0 comments on commit d46b637

Please sign in to comment.