Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve demo command #290

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions cmd/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"os/user"
"path/filepath"
"regexp"
"runtime"
"strconv"
Expand All @@ -28,6 +29,7 @@ var demoCmd = &cobra.Command{

orgId, _, err := utils.CurrentOrganization(true)
if err != nil {
log.Errorf("Cannot get Bearer or Token to access Qovery API. Please use `qovery auth` first: %s", err)
utils.PrintlnError(err)
os.Exit(1)
}
Expand All @@ -40,13 +42,21 @@ var demoCmd = &cobra.Command{
os.Exit(1)
}

err := os.WriteFile("create_demo_cluster.sh", demoScriptsCreate, 0700)
scriptDir := filepath.Join(os.TempDir(), "qovery-demo")
err := os.MkdirAll(scriptDir, os.FileMode(0700))
if err != nil {
log.Fatal(err)
os.Exit(1)
}

scriptPath := filepath.Join(scriptDir, "create_demo_cluster.sh")
err = os.WriteFile(scriptPath, 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, strings.ToUpper(runtime.GOARCH), string(orgId), string(token))
cmd := exec.Command("/bin/sh", scriptPath, demoClusterName, strings.ToUpper(runtime.GOARCH), string(orgId), string(token))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand All @@ -56,13 +66,26 @@ var demoCmd = &cobra.Command{
}

if args[0] == "destroy" {
err := os.WriteFile("destroy_demo_cluster.sh", demoScriptsDestroy, 0700)
scriptDir := filepath.Join(os.TempDir(), "qovery-demo")
err := os.MkdirAll(scriptDir, os.FileMode(0700))
if err != nil {
log.Fatal(err)
os.Exit(1)
}

scriptPath := filepath.Join(scriptDir, "destroy_demo_cluster.sh")
err = os.WriteFile(scriptPath, demoScriptsCreate, 0700)
if err != nil {
log.Errorf("Cannot write file to disk: %s", err)
os.Exit(1)
}
err = os.WriteFile(scriptPath, demoScriptsDestroy, 0700)
if err != nil {
log.Errorf("Cannot write file to disk: %s", err)
os.Exit(1)
}

cmd := exec.Command("/bin/sh", "destroy_demo_cluster.sh", demoClusterName, string(orgId), string(token), strconv.FormatBool(demoDeleteQoveryConfig))
cmd := exec.Command("/bin/sh", scriptPath, demoClusterName, string(orgId), string(token), strconv.FormatBool(demoDeleteQoveryConfig))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/demo_scripts/create_qovery_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ setup_network() {
sudo ifconfig lo0 alias 172.42.0.3/32 up || true
elif grep -qi microsoft /proc/version; then
# Wsl
echo '******** PLEASE READ ********'
echo 'For Qovery url to work outside WSL (from your windows host). You need to run this command within an administrator terminal'
echo 'netsh interface ipv4 add address name="Loopback Pseudo-Interface 1" address=172.42.0.3 mask=255.255.255.255 skipassource=true'
echo '******** PLEASE READ ********'
set -x
sudo ip addr add 172.42.0.3/32 dev lo || true
powershell.exe -Command "Start-Process powershell -Verb RunAs -ArgumentList \"netsh interface ipv3 add address name='Loopback Pseudo-Interface 1' address=172.42.0.3 mask=255.255.255.255 skipassource=true\""
fi
set +x
}
Expand Down Expand Up @@ -149,6 +146,9 @@ install_deps() {
echo "All dependencies are installed"
}

# shellcheck disable=SC2046
# shellcheck disable=SC2086
cd "$(dirname $(realpath $0))"

echo '""""""""""""""""""""""""""""""""""""""""""""'
echo 'Checking and installing dependencies'
Expand Down
12 changes: 6 additions & 6 deletions cmd/demo_scripts/destroy_qovery_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ delete_k3d_cluster() {
then
k3d cluster delete "$clusterName" || true
fi
docker network rm "k3d-${clusterName}" || true
k3d registry delete qovery-registry.lan || true
docker network rm "k3d-${clusterName}" > /dev/null 2>&1 || true
k3d registry delete qovery-registry.lan > /dev/null 2>&1 || true
}

teardown_network() {
Expand All @@ -43,16 +43,16 @@ teardown_network() {
sudo ifconfig lo0 -alias 172.42.0.3/32 up || true
elif grep -qi microsoft /proc/version; then
# Wsl
echo '******** PLEASE READ ********'
echo 'You must run this command from an administrator terminal to finish the cleanup'
echo 'netsh interface ipv4 delete address name="Loopback Pseudo-Interface 1" address=172.42.0.3'
echo '******** PLEASE READ ********'
set -x
sudo ip addr del 172.42.0.3/32 dev lo || true
powershell.exe -Command "Start-Process powershell -Verb RunAs -ArgumentList \"netsh interface ipv4 delete address name='Loopback Pseudo-Interface 1' address=172.42.0.3\""
fi
set +x
}

# shellcheck disable=SC2046
# shellcheck disable=SC2086
cd "$(dirname $(realpath $0))"

echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
Expand Down
2 changes: 1 addition & 1 deletion pkg/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func GetCurrentVersion() string {
return "0.92.6" // ci-version-check
return "0.92.7" // ci-version-check
}

func GetLatestOnlineVersionUrl() (string, error) {
Expand Down
Loading