func UndeployStackHandler()

in worker/api/stack.go [27:74]


func UndeployStackHandler(w http.ResponseWriter, r *http.Request) {
	query := r.URL.Query()
	args := make([]string, 0)
	verbose := false
	verbose, _ = strconv.ParseBool(query.Get("verbose"))
	if verbose {
		args = append(args, "--verbose")
	}
	commit := query.Get("commit")

	vars := mux.Vars(r)
	sandboxId := vars["sandboxId"]
	stackId := vars["stackId"]

	log.Println("Undeploying", stackId)

	dir := filepath.Join(config.GitDir, stackId)
	err := checkout(dir, commit)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	stackDir := filepath.Join(dir, sandboxId)

	_, err = os.Stat(stackDir)
	if os.IsNotExist(err) {
		log.Printf("Sandbox type '%s' not found", sandboxId)
		w.WriteHeader(http.StatusNotFound)
		w.Write([]byte(fmt.Sprint(err)))
		return
	}

	_, err = os.Stat(filepath.Join(stackDir, "hub.yaml"))
	if os.IsNotExist(err) {
		log.Printf("File hub.yaml for sandbox type '%s' not found", sandboxId)
		w.WriteHeader(http.StatusNotFound)
		return
	}

	err = undeploy(stackDir, stackId, args...)
	if err != nil {
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusNoContent)
}