From 85e0b87c99ca5e340fa51b4982e5711a582bca8b Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 26 Feb 2018 11:24:56 +0000 Subject: [PATCH] build: add .deb and .rpm output for the build This uses https://github.com/goreleaser/nfpm to create the .deb and .rpm packages from the standard build output. --- .travis.yml | 2 + Makefile | 1 + bin/cross-compile.go | 97 ++++++++++++++++++++++---- bin/nfpm.yaml | 23 ++++++ docs/content/downloads.md | 32 ++++----- docs/layouts/shortcodes/cdownload.html | 2 +- docs/layouts/shortcodes/download.html | 2 +- 7 files changed, 126 insertions(+), 33 deletions(-) create mode 100644 bin/nfpm.yaml diff --git a/.travis.yml b/.travis.yml index 6bfa7f5da..71f9621c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,7 @@ addons: packages: - fuse - libfuse-dev + - rpm matrix: allow_failures: - go: tip @@ -38,6 +39,7 @@ matrix: deploy: provider: script script: make travis_beta + skip_cleanup: true on: all_branches: true go: "1.10" diff --git a/Makefile b/Makefile index a9848c30c..07d32b7bf 100644 --- a/Makefile +++ b/Makefile @@ -136,6 +136,7 @@ endif @echo Beta release ready at $(BETA_URL) travis_beta: + go run bin/get-github-release.go -extract nfpm goreleaser/nfpm 'nfpm_.*_Linux_x86_64.tar.gz' git log $(LAST_TAG).. > /tmp/git-log.txt go run bin/cross-compile.go -release beta-latest -git-log /tmp/git-log.txt -exclude "^windows/" -parallel 8 $(BUILDTAGS) $(TAG)β rclone --config bin/travis.rclone.conf -v copy --exclude '*beta-latest*' build/ memstore:beta-rclone-org/$(TAG) diff --git a/bin/cross-compile.go b/bin/cross-compile.go index 90beff4d6..f2e8fbb5b 100644 --- a/bin/cross-compile.go +++ b/bin/cross-compile.go @@ -11,11 +11,13 @@ import ( "log" "os" "os/exec" + "path" "path/filepath" "regexp" "runtime" "strings" "sync" + "text/template" "time" ) @@ -88,6 +90,76 @@ func run(args ...string) { runEnv(args, nil) } +// chdir or die +func chdir(dir string) { + err := os.Chdir(dir) + if err != nil { + log.Fatalf("Couldn't cd into %q: %v", dir, err) + } +} + +// substitute data from go template file in to file out +func substitute(inFile, outFile string, data interface{}) { + t, err := template.ParseFiles(inFile) + if err != nil { + log.Fatalf("Failed to read template file %q: %v %v", inFile, err) + } + out, err := os.Create(outFile) + if err != nil { + log.Fatalf("Failed to create output file %q: %v %v", outFile, err) + } + defer func() { + err := out.Close() + if err != nil { + log.Fatalf("Failed to close output file %q: %v %v", outFile, err) + } + }() + err = t.Execute(out, data) + if err != nil { + log.Fatalf("Failed to substitute template file %q: %v %v", inFile, err) + } +} + +// build the zip package return its name +func buildZip(dir string) string { + // Now build the zip + run("cp", "-a", "../MANUAL.txt", filepath.Join(dir, "README.txt")) + run("cp", "-a", "../MANUAL.html", filepath.Join(dir, "README.html")) + run("cp", "-a", "../rclone.1", dir) + if *gitLog != "" { + run("cp", "-a", *gitLog, dir) + } + zip := dir + ".zip" + run("zip", "-r9", zip, dir) + return zip +} + +// Build .deb and .rpm packages +// +// It returns a list of artifacts it has made +func buildDebAndRpm(dir, version, goarch string) []string { + // Make internal version number acceptable to .deb and .rpm + pkgVersion := version[1:] + pkgVersion = strings.Replace(pkgVersion, "β", "-beta", -1) + pkgVersion = strings.Replace(pkgVersion, "-", ".", -1) + + // Make nfpm.yaml from the template + substitute("../bin/nfpm.yaml", path.Join(dir, "nfpm.yaml"), map[string]string{ + "Version": pkgVersion, + "Arch": goarch, + }) + + // build them + var artifacts []string + for _, pkg := range []string{".deb", ".rpm"} { + artifact := dir + pkg + run("bash", "-c", "cd "+dir+" && nfpm -f nfpm.yaml pkg -t ../"+artifact) + artifacts = append(artifacts, artifact) + } + + return artifacts +} + // build the binary in dir func compileArch(version, goos, goarch, dir string) { log.Printf("Compiling %s/%s", goos, goarch) @@ -121,19 +193,17 @@ func compileArch(version, goos, goarch, dir string) { } runEnv(args, env) if !*compileOnly { - // Now build the zip - run("cp", "-a", "../MANUAL.txt", filepath.Join(dir, "README.txt")) - run("cp", "-a", "../MANUAL.html", filepath.Join(dir, "README.html")) - run("cp", "-a", "../rclone.1", dir) - if *gitLog != "" { - run("cp", "-a", *gitLog, dir) + artifacts := []string{buildZip(dir)} + // build a .deb and .rpm if appropriate + if goos == "linux" { + artifacts = append(artifacts, buildDebAndRpm(dir, version, goarch)...) } - zip := dir + ".zip" - run("zip", "-r9", zip, dir) if *copyAs != "" { - copyAsZip := strings.Replace(zip, "-"+version, "-"+*copyAs, 1) - run("ln", zip, copyAsZip) + for _, artifact := range artifacts { + run("ln", artifact, strings.Replace(artifact, "-"+version, "-"+*copyAs, 1)) + } } + // tidy up run("rm", "-rf", dir) } log.Printf("Done compiling %s/%s", goos, goarch) @@ -196,11 +266,8 @@ func main() { run("rm", "-rf", "build") run("mkdir", "build") } - err := os.Chdir("build") - if err != nil { - log.Fatalf("Couldn't cd into build dir: %v", err) - } - err = ioutil.WriteFile("version.txt", []byte(fmt.Sprintf("rclone %s\n", version)), 0666) + chdir("build") + err := ioutil.WriteFile("version.txt", []byte(fmt.Sprintf("rclone %s\n", version)), 0666) if err != nil { log.Fatalf("Couldn't write version.txt: %v", err) } diff --git a/bin/nfpm.yaml b/bin/nfpm.yaml new file mode 100644 index 000000000..454e14b68 --- /dev/null +++ b/bin/nfpm.yaml @@ -0,0 +1,23 @@ +name: "rclone" +arch: "{{.Arch}}" +platform: "linux" +version: "{{.Version}}" +section: "default" +priority: "extra" +provides: +- rclone +maintainer: "Nick Craig-Wood " +description: | + Rclone - "rsync for cloud storage" + is a command line program to sync files and directories to and + from most cloud providers. It can also mount, tree, ncdu and lots + of other useful things. +vendor: "rclone" +homepage: "https://rclone.org" +license: "MIT" +bindir: "/usr/bin" +files: + ./rclone: "/usr/bin/rclone" + ./README.html: "/usr/share/doc/rclone/README.html" + ./README.txt: "/usr/share/doc/rclone/README.txt" + ./rclone.1: "/usr/share/man/man1/rclone.1" diff --git a/docs/content/downloads.md b/docs/content/downloads.md index 11987ab3f..096f2f922 100644 --- a/docs/content/downloads.md +++ b/docs/content/downloads.md @@ -8,14 +8,14 @@ date: "2017-07-22" Rclone Download {{< version >}} ===================== -| Arch-OS | Windows | macOS | Linux | FreeBSD | NetBSD | OpenBSD | Plan9 | Solaris | -|:---:|:-------:|:-----:|:-----:|:-------:|:------:|:-------:|:-----:|:-------:| -| AMD64 - 64 Bit | {{< download windows amd64 >}} | {{< download osx amd64 >}} | {{< download linux amd64 >}} | {{< download freebsd amd64 >}} | {{< download netbsd amd64 >}} | {{< download openbsd amd64 >}} | {{< download plan9 amd64 >}} | {{< download solaris amd64 >}} | -| 386 - 32 Bit | {{< download windows 386 >}} | {{< download osx 386 >}} | {{< download linux 386 >}} | {{< download freebsd 386 >}} | {{< download netbsd 386 >}} | {{< download openbsd 386 >}} | {{< download plan9 386 >}} | - | -| ARM - 32 Bit | - | - | {{< download linux arm >}} | {{< download freebsd arm >}} | {{< download netbsd arm >}} | - | - | - | -| ARM - 64 Bit | - | - | {{< download linux arm64 >}} | - | - | - | - | - | -| MIPS - Big Endian | - | - | {{< download linux mips >}} | - | - | - | - | - | -| MIPS - Little Endian | - | - | {{< download linux mipsle >}} | - | - | - | - | - | +| Arch-OS | Windows | macOS | Linux | .deb | .rpm | FreeBSD | NetBSD | OpenBSD | Plan9 | Solaris | +|:-------:|:-------:|:-----:|:-----:|:----:|:----:|:-------:|:------:|:-------:|:-----:|:-------:| +| AMD64 - 64 Bit | {{< download windows amd64 >}} | {{< download osx amd64 >}} | {{< download linux amd64 >}} | {{< download linux amd64 deb >}} | {{< download linux amd64 rpm >}} | {{< download freebsd amd64 >}} | {{< download netbsd amd64 >}} | {{< download openbsd amd64 >}} | {{< download plan9 amd64 >}} | {{< download solaris amd64 >}} | +| 386 - 32 Bit | {{< download windows 386 >}} | {{< download osx 386 >}} | {{< download linux 386 >}} | {{< download linux amd64 deb >}} | {{< download linux amd64 rpm >}} | {{< download freebsd 386 >}} | {{< download netbsd 386 >}} | {{< download openbsd 386 >}} | {{< download plan9 386 >}} | - | +| ARM - 32 Bit | - | - | {{< download linux arm >}} | {{< download linux amd64 deb >}} | {{< download linux amd64 rpm >}} | {{< download freebsd arm >}} | {{< download netbsd arm >}} | - | - | - | +| ARM - 64 Bit | - | - | {{< download linux arm64 >}} | {{< download linux amd64 deb >}} | {{< download linux amd64 rpm >}} | - | - | - | - | - | +| MIPS - Big Endian | - | - | {{< download linux mips >}} | {{< download linux amd64 deb >}} | {{< download linux amd64 rpm >}} | - | - | - | - | - | +| MIPS - Little Endian | - | - | {{< download linux mipsle >}} | {{< download linux amd64 deb >}} | {{< download linux amd64 rpm >}} | - | - | - | - | - | You can also find a [mirror of the downloads on github](https://github.com/ncw/rclone/releases/tag/{{< version >}}). @@ -67,14 +67,14 @@ Downloads for scripting If you would like to download the current version (maybe from a script) from a URL which doesn't change then you can use these links. -| Arch-OS | Windows | macOS | Linux | FreeBSD | NetBSD | OpenBSD | Plan9 | Solaris | -|:---:|:-------:|:-----:|:-----:|:-------:|:------:|:-------:|:-----:|:-------:| -| AMD64 - 64 Bit | {{< cdownload windows amd64 >}} | {{< cdownload osx amd64 >}} | {{< cdownload linux amd64 >}} | {{< cdownload freebsd amd64 >}} | {{< cdownload netbsd amd64 >}} | {{< cdownload openbsd amd64 >}} | {{< cdownload plan9 amd64 >}} | {{< cdownload solaris amd64 >}} | -| 386 - 32 Bit | {{< cdownload windows 386 >}} | {{< cdownload osx 386 >}} | {{< cdownload linux 386 >}} | {{< cdownload freebsd 386 >}} | {{< cdownload netbsd 386 >}} | {{< cdownload openbsd 386 >}} | {{< cdownload plan9 386 >}} | - | -| ARM - 32 Bit | - | - | {{< cdownload linux arm >}} | {{< cdownload freebsd arm >}} | {{< cdownload netbsd arm >}} | - | - | - | -| ARM - 64 Bit | - | - | {{< cdownload linux arm64 >}} | - | - | - | - | - | -| MIPS - Big Endian | - | - | {{< cdownload linux mips >}} | - | - | - | - | - | -| MIPS - Little Endian | - | - | {{< cdownload linux mipsle >}} | - | - | - | - | - | +| Arch-OS | Windows | macOS | Linux | .deb | .rpm | FreeBSD | NetBSD | OpenBSD | Plan9 | Solaris | +|:-------:|:-------:|:-----:|:-----:|:----:|:----:|:-------:|:------:|:-------:|:-----:|:-------:| +| AMD64 - 64 Bit | {{< cdownload windows amd64 >}} | {{< cdownload osx amd64 >}} | {{< cdownload linux amd64 >}} | {{< cdownload linux amd64 deb >}} | {{< cdownload linux amd64 rpm >}} | {{< cdownload freebsd amd64 >}} | {{< cdownload netbsd amd64 >}} | {{< cdownload openbsd amd64 >}} | {{< cdownload plan9 amd64 >}} | {{< cdownload solaris amd64 >}} | +| 386 - 32 Bit | {{< cdownload windows 386 >}} | {{< cdownload osx 386 >}} | {{< cdownload linux 386 >}} | {{< cdownload linux amd64 deb >}} | {{< cdownload linux amd64 rpm >}} | {{< cdownload freebsd 386 >}} | {{< cdownload netbsd 386 >}} | {{< cdownload openbsd 386 >}} | {{< cdownload plan9 386 >}} | - | +| ARM - 32 Bit | - | - | {{< cdownload linux arm >}} | {{< cdownload linux amd64 deb >}} | {{< cdownload linux amd64 rpm >}} | {{< cdownload freebsd arm >}} | {{< cdownload netbsd arm >}} | - | - | - | +| ARM - 64 Bit | - | - | {{< cdownload linux arm64 >}} | {{< cdownload linux amd64 deb >}} | {{< cdownload linux amd64 rpm >}} | - | - | - | - | - | +| MIPS - Big Endian | - | - | {{< cdownload linux mips >}} | {{< cdownload linux amd64 deb >}} | {{< cdownload linux amd64 rpm >}} | - | - | - | - | - | +| MIPS - Little Endian | - | - | {{< cdownload linux mipsle >}} | {{< cdownload linux amd64 deb >}} | {{< cdownload linux amd64 rpm >}} | - | - | - | - | - | Older Downloads ============== diff --git a/docs/layouts/shortcodes/cdownload.html b/docs/layouts/shortcodes/cdownload.html index 8820aef2e..d8e43ec88 100644 --- a/docs/layouts/shortcodes/cdownload.html +++ b/docs/layouts/shortcodes/cdownload.html @@ -1 +1 @@ - + diff --git a/docs/layouts/shortcodes/download.html b/docs/layouts/shortcodes/download.html index 03156db49..54ec8423a 100644 --- a/docs/layouts/shortcodes/download.html +++ b/docs/layouts/shortcodes/download.html @@ -1 +1 @@ - +