1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
package main
import (
"context"
"fmt"
"os"
"github.com/pkg/errors"
"go.uber.org/zap"
"github.com/grindlemire/gothem-stack/magefiles/cmd"
)
func destroy(ctx context.Context) error {
zap.S().Info("Starting destroy process...")
config, err := GetConfig(ctx)
if err != nil {
return errors.Wrap(err, "failed to get config")
}
if err := cmd.Run(ctx,
cmd.WithCMD("firebase", "hosting:disable", "--project", config.Env, "--force"),
); err != nil {
zap.S().Warnf("failed to disable firebase hosting (might already be disabled): %v", err)
}
if err := cmd.Run(ctx,
cmd.WithCMD("gcloud", "run", "services", "delete", "gothem-stack",
"--platform", "managed",
"--region", "us-central1",
"--project", config.Env,
"--quiet"),
); err != nil {
zap.S().Warnf("failed to delete cloud run service: %v", err)
}
projectID := os.Getenv("GOOGLE_CLOUD_PROJECT")
if projectID == "" {
return errors.New("GOOGLE_CLOUD_PROJECT environment variable not set")
}
serviceName := os.Getenv("CLOUD_RUN_SERVICE_NAME")
if serviceName == "" {
return errors.New("CLOUD_RUN_SERVICE_NAME environment variable not set")
}
region := os.Getenv("GOOGLE_CLOUD_REGION")
if region == "" {
region = "us-central1"
}
err = cmd.Run(ctx,
cmd.WithCMD("gcloud", "artifacts", "repositories", "delete", serviceName,
"--project", config.Env,
"--location", region,
"--quiet"),
)
if err != nil {
zap.S().Warnf("failed to delete artifacts repository: %v", err)
}
bucketName := fmt.Sprintf("%s_cloudbuild", projectID)
err = cmd.Run(ctx,
cmd.WithCMD("gsutil", "rm", "-r", fmt.Sprintf("gs://%s", bucketName)),
)
if err != nil {
zap.S().Warnf("failed to delete cloudbuild bucket: %v", err)
}
zap.S().Info("successfully destroyed cloud infrastructure")
return nil
}
|