You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

  1. package main
  2. import (
  3. "errors"
  4. "fmt"
  5. "os"
  6. "path/filepath"
  7. e2e "github.com/tendermint/tendermint/test/e2e/pkg"
  8. )
  9. // Cleanup removes the Docker Compose containers and testnet directory.
  10. func Cleanup(testnet *e2e.Testnet) error {
  11. if testnet.Dir == "" {
  12. return errors.New("no directory set")
  13. }
  14. _, err := os.Stat(testnet.Dir)
  15. if os.IsNotExist(err) {
  16. return nil
  17. } else if err != nil {
  18. return err
  19. }
  20. logger.Info("Removing Docker containers and networks")
  21. err = execCompose(testnet.Dir, "stop")
  22. if err != nil {
  23. return err
  24. }
  25. // On Linux, some local files in the volume will be owned by root since Tendermint
  26. // runs as root inside the container, so we need to clean them up from within a
  27. // container running as root too.
  28. absDir, err := filepath.Abs(testnet.Dir)
  29. if err != nil {
  30. return err
  31. }
  32. err = execDocker("run", "--entrypoint", "", "-v", fmt.Sprintf("%v:/network", absDir),
  33. "tendermint/e2e-node", "sh", "-c", "rm -rf /network/*/")
  34. if err != nil {
  35. return err
  36. }
  37. err = execCompose(testnet.Dir, "down")
  38. if err != nil {
  39. return err
  40. }
  41. logger.Info(fmt.Sprintf("Removing testnet directory %q", testnet.Dir))
  42. err = os.RemoveAll(testnet.Dir)
  43. if err != nil {
  44. return err
  45. }
  46. return nil
  47. }