Skip to content

Commit

Permalink
feat(demo): Add destroy command (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
erebe authored Apr 30, 2024
1 parent 14f0bfe commit 5e95713
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 4 deletions.
18 changes: 17 additions & 1 deletion cmd/demo.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,23 @@ var demoCmd = &cobra.Command{
}

if args[0] == "destroy" {
panic("Destroy is not yet implemented")
err := os.WriteFile("destroy_demo_cluster.sh", 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, organizationId, string(token))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Errorf("Error executing the command %s", err)
}
os.Exit(0)
}

log.Errorf("Unknown command %s. Only `up` and `destroy` are supported", args[0])
os.Exit(1)
},
}
var (
Expand All @@ -73,6 +86,9 @@ var (
//go:embed demo_scripts/create_qovery_demo.sh
var demoScriptsCreate []byte

//go:embed demo_scripts/destroy_qovery_demo.sh
var demoScriptsDestroy []byte

func init() {
var userName string
currentUser, err := user.Current()
Expand Down
4 changes: 2 additions & 2 deletions cmd/demo_scripts/create_qovery_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ setup_network() {
if [ "$(uname -s)" = 'Darwin' ]; then
# MacOs
set -x
sudo ifconfig lo0 alias 172.42.0.3/32 up || exit 1
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 || exit 1
sudo ip addr add 172.42.0.3/32 dev lo || true
fi
set +x
}
Expand Down
69 changes: 69 additions & 0 deletions cmd/demo_scripts/destroy_qovery_demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/bin/sh

set -eu

CLUSTER_NAME=$1
ORGANIZATION_ID=$2
#case $2 in
# qov_*)
# AUTHORIZATION_HEADER="Authorization: Token $3"
# ;;
#
# *)
# AUTHORIZATION_HEADER="Authorization: Bearer $3"
# ;;
#esac

delete_cluster() {
clusterName=$1
clusterExist=$(k3d cluster list -o json | jq '.[] | select(.name=="'"$clusterName"'") | .name')
if [ -n "$clusterExist" ]
then
k3d cluster delete "$clusterName" || true
fi
docker network rm "k3d-${clusterName}" || true
}

teardown_network() {
if [ "$(uname -s)" = 'Darwin' ]; then
# MacOs
set -x
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
fi
set +x
}


echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
echo 'Removing Qovery helm repositories'
echo '""""""""""""""""""""""""""""""""""""""""""""'
helm repo remove qovery || true

echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
echo "Removing $CLUSTER_NAME kube cluster"
echo '""""""""""""""""""""""""""""""""""""""""""""'
delete_cluster "$CLUSTER_NAME"

echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
echo 'Removing network config'
echo '""""""""""""""""""""""""""""""""""""""""""""'
teardown_network


echo ''
echo '""""""""""""""""""""""""""""""""""""""""""""'
echo "Qovery local demo cluster is now deleted"
echo "Your created environments still exits !"
echo "Go to https://console.qovery.com/organization/${ORGANIZATION_ID}/clusters/general to delete Qovery cluster config"
echo '""""""""""""""""""""""""""""""""""""""""""""'
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.90.4" // ci-version-check
return "0.90.5" // ci-version-check
}

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

0 comments on commit 5e95713

Please sign in to comment.