From 63c3a6eecaea9ab8cdee8a6e1d9419e79b9cbea0 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 14 Sep 2020 15:32:10 -0600 Subject: [PATCH] feat: allow "any" to specify a "binary" with no arch/os deps (#7230) --- cosmovisor/README.md | 1 + cosmovisor/upgrade.go | 5 ++++- cosmovisor/upgrade_test.go | 8 ++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cosmovisor/README.md b/cosmovisor/README.md index 00e9a02719..3892efd0db 100644 --- a/cosmovisor/README.md +++ b/cosmovisor/README.md @@ -122,6 +122,7 @@ as JSON under the `"binaries"` key, eg: } } ``` +The `"any"` key, if it exists, will be used as a default if there is not a specific os/architecture key. 2. Store a link to a file that contains all information in the above format (eg. if you want to specify lots of binaries, changelog info, etc without filling up the blockchain). diff --git a/cosmovisor/upgrade.go b/cosmovisor/upgrade.go index 9c1cae8dae..38b6c9f81f 100644 --- a/cosmovisor/upgrade.go +++ b/cosmovisor/upgrade.go @@ -121,7 +121,10 @@ func GetDownloadURL(info *UpgradeInfo) (string, error) { if err := json.Unmarshal([]byte(doc), &config); err == nil { url, ok := config.Binaries[osArch()] if !ok { - return "", fmt.Errorf("cannot find binary for os/arch: %s", osArch()) + url, ok = config.Binaries["any"] + } + if !ok { + return "", fmt.Errorf("cannot find binary for os/arch: neither %s, nor any", osArch()) } return url, nil diff --git a/cosmovisor/upgrade_test.go b/cosmovisor/upgrade_test.go index c954f270f8..3e628bb7ff 100644 --- a/cosmovisor/upgrade_test.go +++ b/cosmovisor/upgrade_test.go @@ -159,6 +159,14 @@ func TestGetDownloadURL(t *testing.T) { info: `{"binaries": {"linux/amd64": "https://foo.bar/", "windows/amd64": "https://something.else"}}`, url: "https://foo.bar/", }, + "any architecture not used": { + info: `{"binaries": {"linux/amd64": "https://foo.bar/", "*": "https://something.else"}}`, + url: "https://foo.bar/", + }, + "any architecture used": { + info: `{"binaries": {"linux/arm": "https://foo.bar/arm-only", "any": "https://foo.bar/portable"}}`, + url: "https://foo.bar/portable", + }, "missing binary": { info: `{"binaries": {"linux/arm": "https://foo.bar/"}}`, isErr: true,