Skip to content

Commit d6944ca

Browse files
cagedmantisgopherbot
authored andcommitted
cmd/gomote: implements GRPC puttar command
This change adds the implementation for GRPC puttar command to the gomote client. Updates golang/go#48737 For golang/go#47521 Change-Id: I9b500b2f3ca70c78c3f288d0280eba02a1c59554 Reviewed-on: https://go-review.googlesource.com/c/build/+/407878 Auto-Submit: Carlos Amedee <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Run-TryBot: Carlos Amedee <[email protected]> Reviewed-by: Alex Rakoczy <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent ac7906f commit d6944ca

File tree

2 files changed

+104
-3
lines changed

2 files changed

+104
-3
lines changed

cmd/gomote/gomote.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func registerCommands() {
158158
registerCommand("push", "sync your GOROOT directory to the buildlet", push)
159159
registerCommand("put", "put files on a buildlet", legacyPut)
160160
registerCommand("put14", "put Go 1.4 in place", put14)
161-
registerCommand("puttar", "extract a tar.gz to a buildlet", putTar)
161+
registerCommand("puttar", "extract a tar.gz to a buildlet", legacyPutTar)
162162
registerCommand("rdp", "RDP (Remote Desktop Protocol) to a Windows buildlet", rdp)
163163
registerCommand("rm", "delete files or directories", legacyRm)
164164
registerCommand("run", "run a command on a buildlet", legacyRun)
@@ -226,6 +226,7 @@ func version2(args []string) error {
226226
"rm": rm,
227227
"gettar": getTar,
228228
"put": put,
229+
"puttar": putTar,
229230
}
230231
if len(args) == 0 {
231232
usage()

cmd/gomote/put.go

+102-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"golang.org/x/build/tarutil"
2424
)
2525

26-
// put a .tar.gz
27-
func putTar(args []string) error {
26+
// legacyPutTar a .tar.gz
27+
func legacyPutTar(args []string) error {
2828
fs := flag.NewFlagSet("put", flag.ContinueOnError)
2929
fs.Usage = func() {
3030
fmt.Fprintln(os.Stderr, "puttar usage: gomote puttar [put-opts] <buildlet-name> [tar.gz file or '-' for stdin]")
@@ -93,6 +93,106 @@ func putTar(args []string) error {
9393
return bc.PutTar(ctx, tgz, dir)
9494
}
9595

96+
// putTar a .tar.gz
97+
func putTar(args []string) error {
98+
fs := flag.NewFlagSet("put", flag.ContinueOnError)
99+
fs.Usage = func() {
100+
fmt.Fprintln(os.Stderr, "puttar usage: gomote puttar [put-opts] <buildlet-name> [tar.gz file or '-' for stdin]")
101+
fs.PrintDefaults()
102+
os.Exit(1)
103+
}
104+
var rev string
105+
fs.StringVar(&rev, "gorev", "", "If non-empty, git hash to download from gerrit and put to the buildlet. e.g. 886b02d705ff for Go 1.4.1. This just maps to the --URL flag, so the two options are mutually exclusive.")
106+
var dir string
107+
fs.StringVar(&dir, "dir", "", "relative directory from buildlet's work dir to extra tarball into")
108+
var tarURL string
109+
fs.StringVar(&tarURL, "url", "", "URL of tarball, instead of provided file.")
110+
111+
fs.Parse(args)
112+
if fs.NArg() < 1 || fs.NArg() > 2 {
113+
fs.Usage()
114+
}
115+
if rev != "" && tarURL != "" {
116+
fmt.Fprintln(os.Stderr, "--gorev and --url are mutually exclusive")
117+
fs.Usage()
118+
}
119+
name := fs.Arg(0)
120+
ctx := context.Background()
121+
client := gomoteServerClient(ctx)
122+
123+
if rev != "" {
124+
tarURL = "https://go.googlesource.com/go/+archive/" + rev + ".tar.gz"
125+
}
126+
if tarURL != "" {
127+
if fs.NArg() != 1 {
128+
fs.Usage()
129+
}
130+
_, err := client.WriteTGZFromURL(ctx, &protos.WriteTGZFromURLRequest{
131+
GomoteId: name,
132+
Directory: dir,
133+
Url: tarURL,
134+
})
135+
if err != nil {
136+
return fmt.Errorf("unable to write tar to instance: %s", statusFromError(err))
137+
}
138+
if rev != "" {
139+
// Put a VERSION file there too, to avoid git usage.
140+
version := strings.NewReader("devel " + rev)
141+
var vtar tarutil.FileList
142+
vtar.AddRegular(&tar.Header{
143+
Name: "VERSION",
144+
Mode: 0644,
145+
Size: int64(version.Len()),
146+
}, int64(version.Len()), version)
147+
tgz := vtar.TarGz()
148+
defer tgz.Close()
149+
150+
resp, err := client.UploadFile(ctx, &protos.UploadFileRequest{})
151+
if err != nil {
152+
return fmt.Errorf("unable to request credentials for a file upload: %s", statusFromError(err))
153+
}
154+
if err := uploadToGCS(ctx, resp.GetFields(), tgz, resp.GetObjectName(), resp.GetUrl()); err != nil {
155+
return fmt.Errorf("unable to upload version file to GCS: %s", err)
156+
}
157+
if _, err = client.WriteTGZFromURL(ctx, &protos.WriteTGZFromURLRequest{
158+
GomoteId: name,
159+
Directory: dir,
160+
Url: fmt.Sprintf("%s%s", resp.GetUrl(), resp.GetObjectName()),
161+
}); err != nil {
162+
return fmt.Errorf("unable to write tar to instance: %s", statusFromError(err))
163+
}
164+
}
165+
return nil
166+
}
167+
var tgz io.Reader = os.Stdin
168+
if fs.NArg() != 2 {
169+
fs.Usage()
170+
}
171+
if fs.Arg(1) != "-" {
172+
f, err := os.Open(fs.Arg(1))
173+
if err != nil {
174+
return err
175+
}
176+
defer f.Close()
177+
tgz = f
178+
}
179+
resp, err := client.UploadFile(ctx, &protos.UploadFileRequest{})
180+
if err != nil {
181+
return fmt.Errorf("unable to request credentials for a file upload: %s", statusFromError(err))
182+
}
183+
if err := uploadToGCS(ctx, resp.GetFields(), tgz, resp.GetObjectName(), resp.GetUrl()); err != nil {
184+
return fmt.Errorf("unable to upload file to GCS: %s", err)
185+
}
186+
if _, err := client.WriteTGZFromURL(ctx, &protos.WriteTGZFromURLRequest{
187+
GomoteId: name,
188+
Directory: dir,
189+
Url: fmt.Sprintf("%s%s", resp.GetUrl(), resp.GetObjectName()),
190+
}); err != nil {
191+
return fmt.Errorf("unable to write tar to instance: %s", statusFromError(err))
192+
}
193+
return nil
194+
}
195+
96196
// put go1.4 in the workdir
97197
func put14(args []string) error {
98198
fs := flag.NewFlagSet("put14", flag.ContinueOnError)

0 commit comments

Comments
 (0)