Skip to content

Commit 2d0fc9f

Browse files
fjldshulyak
authored andcommitted
build: avoid dput and upload with sftp directly (ethereum#19067)
(cherry picked from commit a8ddf7a)
1 parent 821740f commit 2d0fc9f

File tree

3 files changed

+53
-27
lines changed

3 files changed

+53
-27
lines changed

build/ci.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -511,41 +511,44 @@ func doDebianSource(cmdline []string) {
511511
debuild.Dir = pkgdir
512512
build.MustRun(debuild)
513513

514-
changes := fmt.Sprintf("%s_%s_source.changes", meta.Name(), meta.VersionString())
515-
changes = filepath.Join(*workdir, changes)
514+
var (
515+
basename = fmt.Sprintf("%s_%s", meta.Name(), meta.VersionString())
516+
source = filepath.Join(*workdir, basename+".tar.xz")
517+
dsc = filepath.Join(*workdir, basename+".dsc")
518+
changes = filepath.Join(*workdir, basename+"_source.changes")
519+
)
516520
if *signer != "" {
517521
build.MustRunCommand("debsign", changes)
518522
}
519523
if *upload != "" {
520-
uploadDebianSource(*workdir, *upload, *sshUser, changes)
524+
ppaUpload(*workdir, *upload, *sshUser, []string{source, dsc, changes})
521525
}
522526
}
523527
}
524528
}
525529

526-
func uploadDebianSource(workdir, ppa, sshUser, changes string) {
527-
// Create the dput config file.
528-
dputConfig := filepath.Join(workdir, "dput.cf")
530+
func ppaUpload(workdir, ppa, sshUser string, files []string) {
529531
p := strings.Split(ppa, "/")
530532
if len(p) != 2 {
531533
log.Fatal("-upload PPA name must contain single /")
532534
}
533-
templateData := map[string]string{
534-
"LaunchpadUser": p[0],
535-
"LaunchpadPPA": p[1],
536-
"LaunchpadSSH": sshUser,
535+
if sshUser == "" {
536+
sshUser = p[0]
537537
}
538+
incomingDir := fmt.Sprintf("~%s/ubuntu/%s", p[0], p[1])
539+
// Create the SSH identity file if it doesn't exist.
540+
var idfile string
538541
if sshkey := getenvBase64("PPA_SSH_KEY"); len(sshkey) > 0 {
539-
idfile := filepath.Join(workdir, "sshkey")
540-
ioutil.WriteFile(idfile, sshkey, 0600)
541-
templateData["IdentityFile"] = idfile
542+
idfile = filepath.Join(workdir, "sshkey")
543+
if _, err := os.Stat(idfile); os.IsNotExist(err) {
544+
ioutil.WriteFile(idfile, sshkey, 0600)
545+
}
546+
}
547+
// Upload
548+
dest := sshUser + "@ppa.launchpad.net"
549+
if err := build.UploadSFTP(idfile, dest, incomingDir, files); err != nil {
550+
log.Fatal(err)
542551
}
543-
build.Render("build/dput-launchpad.cf", dputConfig, 0644, templateData)
544-
545-
// Run dput to do the upload.
546-
dput := exec.Command("dput", "-c", dputConfig, "--no-upload-log", ppa, changes)
547-
dput.Stdin = strings.NewReader("Yes\n") // accept SSH host key
548-
build.MustRun(dput)
549552
}
550553

551554
func getenvBase64(variable string) []byte {

build/dput-launchpad.cf

Lines changed: 0 additions & 8 deletions
This file was deleted.

internal/build/util.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,34 @@ func ExpandPackagesNoVendor(patterns []string) []string {
177177
}
178178
return patterns
179179
}
180+
181+
// UploadSFTP uploads files to a remote host using the sftp command line tool.
182+
// The destination host may be specified either as [user@]host[: or as a URI in
183+
// the form sftp://[user@]host[:port].
184+
func UploadSFTP(identityFile, host, dir string, files []string) error {
185+
sftp := exec.Command("sftp")
186+
sftp.Stdout = nil
187+
sftp.Stderr = os.Stderr
188+
if identityFile != "" {
189+
sftp.Args = append(sftp.Args, "-i", identityFile)
190+
}
191+
sftp.Args = append(sftp.Args, host)
192+
fmt.Println(">>>", strings.Join(sftp.Args, " "))
193+
if *DryRunFlag {
194+
return nil
195+
}
196+
197+
stdin, err := sftp.StdinPipe()
198+
if err != nil {
199+
return fmt.Errorf("can't create stdin pipe for sftp: %v", err)
200+
}
201+
if err := sftp.Start(); err != nil {
202+
return err
203+
}
204+
in := io.MultiWriter(stdin, os.Stdout)
205+
for _, f := range files {
206+
fmt.Fprintln(in, "put", f, path.Join(dir, filepath.Base(f)))
207+
}
208+
stdin.Close()
209+
return sftp.Wait()
210+
}

0 commit comments

Comments
 (0)