Skip to content

Commit 3de19c8

Browse files
fjlkaralabe
authored andcommitted
build: use SFTP for launchpad uploads (ethereum#19037)
* build: use sftp for launchpad uploads * .travis.yml: configure sftp export * build: update CI docs
1 parent 6cb7d52 commit 3de19c8

File tree

4 files changed

+60
-21
lines changed

4 files changed

+60
-21
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ matrix:
6868
- debhelper
6969
- dput
7070
- fakeroot
71+
- python-bzrlib
72+
- python-paramiko
7173
script:
72-
- go run build/ci.go debsrc -signer "Go Ethereum Linux Builder <[email protected]>" -upload ppa:ethereum/ethereum
74+
- go run build/ci.go debsrc -upload ppa:ethereum/ethereum -sftp-user geth-ci -signer "Go Ethereum Linux Builder <[email protected]>"
7375

7476
# This builder does the Linux Azure uploads
7577
- if: type = push

build/ci-notes.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ Canonical.
77
Packages of develop branch commits have suffix -unstable and cannot be installed alongside
88
the stable version. Switching between release streams requires user intervention.
99

10+
## Launchpad
11+
1012
The packages are built and served by launchpad.net. We generate a Debian source package
1113
for each distribution and upload it. Their builder picks up the source package, builds it
1214
and installs the new version into the PPA repository. Launchpad requires a valid signature
13-
by a team member for source package uploads. The signing key is stored in an environment
14-
variable which Travis CI makes available to certain builds.
15+
by a team member for source package uploads.
16+
17+
The signing key is stored in an environment variable which Travis CI makes available to
18+
certain builds. Since Travis CI doesn't support FTP, SFTP is used to transfer the
19+
packages. To set this up yourself, you need to create a Launchpad user and add a GPG key
20+
and SSH key to it. Then encode both keys as base64 and configure 'secret' environment
21+
variables `PPA_SIGNING_KEY` and `PPA_SSH_KEY` on Travis.
1522

1623
We want to build go-ethereum with the most recent version of Go, irrespective of the Go
1724
version that is available in the main Ubuntu repository. In order to make this possible,
@@ -27,7 +34,7 @@ Add the gophers PPA and install Go 1.10 and Debian packaging tools:
2734

2835
$ sudo apt-add-repository ppa:gophers/ubuntu/archive
2936
$ sudo apt-get update
30-
$ sudo apt-get install build-essential golang-1.10 devscripts debhelper
37+
$ sudo apt-get install build-essential golang-1.10 devscripts debhelper python-bzrlib python-paramiko
3138

3239
Create the source packages:
3340

build/ci.go

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,8 @@ func archiveBasename(arch string, archiveVersion string) string {
441441
func archiveUpload(archive string, blobstore string, signer string) error {
442442
// If signing was requested, generate the signature files
443443
if signer != "" {
444-
pgpkey, err := base64.StdEncoding.DecodeString(os.Getenv(signer))
445-
if err != nil {
446-
return fmt.Errorf("invalid base64 %s", signer)
447-
}
448-
if err := build.PGPSignFile(archive, archive+".asc", string(pgpkey)); err != nil {
444+
key := getenvBase64(signer)
445+
if err := build.PGPSignFile(archive, archive+".asc", string(key)); err != nil {
449446
return err
450447
}
451448
}
@@ -489,6 +486,7 @@ func doDebianSource(cmdline []string) {
489486
var (
490487
signer = flag.String("signer", "", `Signing key name, also used as package author`)
491488
upload = flag.String("upload", "", `Where to upload the source package (usually "ppa:ethereum/ethereum")`)
489+
sshUser = flag.String("sftp-user", "", `Username for SFTP upload (usually "geth-ci")`)
492490
workdir = flag.String("workdir", "", `Output directory for packages (uses temp dir if unset)`)
493491
now = time.Now()
494492
)
@@ -498,11 +496,7 @@ func doDebianSource(cmdline []string) {
498496
maybeSkipArchive(env)
499497

500498
// Import the signing key.
501-
if b64key := os.Getenv("PPA_SIGNING_KEY"); b64key != "" {
502-
key, err := base64.StdEncoding.DecodeString(b64key)
503-
if err != nil {
504-
log.Fatal("invalid base64 PPA_SIGNING_KEY")
505-
}
499+
if key := getenvBase64("PPA_SIGNING_KEY"); len(key) > 0 {
506500
gpg := exec.Command("gpg", "--import")
507501
gpg.Stdin = bytes.NewReader(key)
508502
build.MustRun(gpg)
@@ -523,12 +517,45 @@ func doDebianSource(cmdline []string) {
523517
build.MustRunCommand("debsign", changes)
524518
}
525519
if *upload != "" {
526-
build.MustRunCommand("dput", "--passive", "--no-upload-log", *upload, changes)
520+
uploadDebianSource(*workdir, *upload, *sshUser, changes)
527521
}
528522
}
529523
}
530524
}
531525

526+
func uploadDebianSource(workdir, ppa, sshUser, changes string) {
527+
// Create the dput config file.
528+
dputConfig := filepath.Join(workdir, "dput.cf")
529+
p := strings.Split(ppa, "/")
530+
if len(p) != 2 {
531+
log.Fatal("-upload PPA name must contain single /")
532+
}
533+
templateData := map[string]string{
534+
"LaunchpadUser": p[0],
535+
"LaunchpadPPA": p[1],
536+
"LaunchpadSSH": sshUser,
537+
}
538+
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+
}
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)
549+
}
550+
551+
func getenvBase64(variable string) []byte {
552+
dec, err := base64.StdEncoding.DecodeString(os.Getenv(variable))
553+
if err != nil {
554+
log.Fatal("invalid base64 " + variable)
555+
}
556+
return []byte(dec)
557+
}
558+
532559
func makeWorkdir(wdflag string) string {
533560
var err error
534561
if wdflag != "" {
@@ -800,15 +827,10 @@ func doAndroidArchive(cmdline []string) {
800827
os.Rename(archive, meta.Package+".aar")
801828
if *signer != "" && *deploy != "" {
802829
// Import the signing key into the local GPG instance
803-
b64key := os.Getenv(*signer)
804-
key, err := base64.StdEncoding.DecodeString(b64key)
805-
if err != nil {
806-
log.Fatalf("invalid base64 %s", *signer)
807-
}
830+
key := getenvBase64(*signer)
808831
gpg := exec.Command("gpg", "--import")
809832
gpg.Stdin = bytes.NewReader(key)
810833
build.MustRun(gpg)
811-
812834
keyID, err := build.PGPKeyID(string(key))
813835
if err != nil {
814836
log.Fatal(err)

build/dput-launchpad.cf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[{{.LaunchpadUser}}/{{.LaunchpadPPA}}]
2+
fqdn = ppa.launchpad.net
3+
method = sftp
4+
incoming = ~{{.LaunchpadUser}}/ubuntu/{{.LaunchpadPPA}}/
5+
login = {{.LaunchpadSSH}}
6+
{{ if .IdentityFile }}
7+
ssh_options = IdentityFile {{.IdentityFile}}
8+
{{ end }}

0 commit comments

Comments
 (0)