Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/gpctl/cmd/workspaces-snapshot.go
2498 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"context"
9
"strings"
10
11
"github.com/spf13/cobra"
12
13
"github.com/gitpod-io/gitpod/common-go/log"
14
"github.com/gitpod-io/gitpod/ws-manager/api"
15
)
16
17
// workspacesSnapshotCmd listens for workspace updates
18
var workspacesSnapshotCmd = &cobra.Command{
19
Use: "snapshot <instanceID>",
20
Short: "takes a snapshot of a workspace and uploads it to the remote storage",
21
Run: func(cmd *cobra.Command, args []string) {
22
ctx, cancel := context.WithCancel(context.Background())
23
defer cancel()
24
25
conn, client, err := getWorkspacesClient(ctx)
26
if err != nil {
27
log.WithError(err).Fatal("cannot connect")
28
}
29
defer conn.Close()
30
31
instanceID := args[0]
32
if strings.ContainsAny(instanceID, ".") || strings.HasPrefix(instanceID, "http://") || strings.HasPrefix(instanceID, "https://") {
33
s, err := getStatusByURL(ctx, client, instanceID)
34
if err != nil {
35
log.Fatal(err)
36
}
37
instanceID = s.Id
38
}
39
40
resp, err := client.TakeSnapshot(context.Background(), &api.TakeSnapshotRequest{
41
Id: instanceID,
42
})
43
44
if err != nil {
45
log.WithError(err).Fatal("error during RPC call")
46
}
47
48
err = getOutputFormat("{{ .Url }}\n", "{.url}").Print(resp)
49
if err != nil {
50
log.Fatal(err)
51
}
52
},
53
}
54
55
func init() {
56
workspacesCmd.AddCommand(workspacesSnapshotCmd)
57
}
58
59