Skip to content

Commit

Permalink
Fix upgrade test coreum runner for darwin (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitryhil authored Dec 2, 2024
1 parent 081f5e3 commit d1f7e10
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
38 changes: 23 additions & 15 deletions build/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const (
Gaia Name = "gaia"
Osmosis Name = "osmosis"
Hermes Name = "hermes"
CoredV303 Name = "cored-v3.0.3"
CoredV401 Name = "cored-v4.0.1"
Mockgen = "mockgen"
Buf Name = "buf"
Expand Down Expand Up @@ -297,24 +296,32 @@ var tools = []Tool{
"bin/cored-v4.0.1": "cored-linux-arm64",
},
},
},
},
BinaryTool{
Name: CoredV303,
Version: "v3.0.3",
Sources: Sources{
TargetPlatformLinuxAMD64InDocker: {
URL: "https://github.com/CoreumFoundation/coreum/releases/download/v3.0.3/cored-linux-amd64",
Hash: "sha256:1719a32e6f8e8813d00cd86e1d8d02e893324d4f59fa7a1b8cedc5836140ecef",
TargetPlatformLinuxAMD64: {
URL: "https://github.com/CoreumFoundation/coreum/releases/download/v4.0.1/cored-linux-amd64",
Hash: "sha256:fdbb6a0c393f1cad0d03c6357b6af2e840508ef3be7ab186f2caeee10d13ae73",
Binaries: map[string]string{
"bin/cored-v3.0.3": "cored-linux-amd64",
"bin/cored-v4.0.1": "cored-linux-amd64",
},
},
TargetPlatformLinuxARM64InDocker: {
URL: "https://github.com/CoreumFoundation/coreum/releases/download/v3.0.3/cored-linux-arm64",
Hash: "sha256:cfbbad6803c0327407e4dd222a108505e6ff9e294d7c86e34b6b895b96b61bbd",
TargetPlatformLinuxARM64: {
URL: "https://github.com/CoreumFoundation/coreum/releases/download/v4.0.1/cored-linux-arm64",
Hash: "sha256:ade147bf5a63259dae1b69762e3295600b5acd9f748b3cfba4d885dfaff15f1e",
Binaries: map[string]string{
"bin/cored-v4.0.1": "cored-linux-arm64",
},
},
TargetPlatformDarwinAMD64: {
URL: "https://github.com/CoreumFoundation/coreum/releases/download/v4.0.1/cored-darwin-amd64",
Hash: "sha256:939ded112db693a3d929eaaec0814b8d318f0eed686491c1a9ddd07a09d82f44",
Binaries: map[string]string{
"bin/cored-v4.0.1": "cored-darwin-amd64",
},
},
TargetPlatformDarwinARM64: {
URL: "https://github.com/CoreumFoundation/coreum/releases/download/v4.0.1/cored-darwin-arm64",
Hash: "sha256:3e90d12dafdb5d03c68d4e99d3da0f1d8d1b9bafb9cc42648efb24656de6e7bd",
Binaries: map[string]string{
"bin/cored-v3.0.3": "cored-linux-arm64",
"bin/cored-v4.0.1": "cored-darwin-arm64",
},
},
},
Expand Down Expand Up @@ -522,6 +529,7 @@ func (p TargetPlatform) String() string {
var (
TargetPlatformLocal = TargetPlatform{BuildInDocker: false, OS: runtime.GOOS, Arch: runtime.GOARCH}
TargetPlatformLinuxAMD64 = TargetPlatform{BuildInDocker: false, OS: OSLinux, Arch: ArchAMD64}
TargetPlatformLinuxARM64 = TargetPlatform{BuildInDocker: false, OS: OSLinux, Arch: ArchARM64}
TargetPlatformDarwinAMD64 = TargetPlatform{BuildInDocker: false, OS: OSDarwin, Arch: ArchAMD64}
TargetPlatformDarwinARM64 = TargetPlatform{BuildInDocker: false, OS: OSDarwin, Arch: ArchARM64}
TargetPlatformLinuxAMD64InDocker = TargetPlatform{BuildInDocker: true, OS: OSLinux, Arch: ArchAMD64}
Expand Down
32 changes: 18 additions & 14 deletions infra/apps/cored/cored.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -43,6 +42,7 @@ import (
assetfttypes "github.com/CoreumFoundation/coreum/v5/x/asset/ft/types"
"github.com/CoreumFoundation/coreum/v5/x/dex"
dextypes "github.com/CoreumFoundation/coreum/v5/x/dex/types"
"github.com/CoreumFoundation/crust/build/tools"
"github.com/CoreumFoundation/crust/infra"
"github.com/CoreumFoundation/crust/infra/cosmoschain"
"github.com/CoreumFoundation/crust/infra/targets"
Expand Down Expand Up @@ -348,18 +348,18 @@ func (c Cored) Deployment() infra.Deployment {
return deployment
}

func (c Cored) localBinaryPath() string {
return filepath.Join(c.config.BinDir, "cored")
}

func (c Cored) dockerBinaryPath() string {
coredStandardBinName := "cored"
coredBinName := coredStandardBinName
coredStandardPath := filepath.Join(c.config.BinDir, ".cache", "cored", "docker.linux."+runtime.GOARCH, "bin")
coredStandardPath := filepath.Join(
c.config.BinDir, ".cache", "cored", tools.TargetPlatformLinuxLocalArchInDocker.String(), "bin",
)
coredPath := coredStandardPath
if c.config.DockerImage == DockerImageExtended {
coredBinName = "cored-ext"
coredPath = filepath.Join(c.config.BinDir, ".cache", "cored-ext", "docker.linux."+runtime.GOARCH, "bin")
coredPath = filepath.Join(
c.config.BinDir, ".cache", "cored-ext", tools.TargetPlatformLinuxLocalArchInDocker.String(), "bin",
)
}

// by default the binary version is latest, but if `BinaryVersion` is provided we take it as initial
Expand Down Expand Up @@ -414,7 +414,6 @@ func (c Cored) prepare(ctx context.Context) error {
return errors.WithStack(err)
}
// the path is defined by the build
dockerLinuxBinaryPath := filepath.Join(c.config.BinDir, ".cache", "cored", "docker.linux."+runtime.GOARCH, "bin")
if err := copyFile(
c.dockerBinaryPath(),
filepath.Join(c.config.HomeDir, "cosmovisor", "genesis", "bin", "cored"),
Expand All @@ -425,9 +424,11 @@ func (c Cored) prepare(ctx context.Context) error {
// upgrade to binary mapping
upgrades := map[string]string{
"v5": "cored",
"v4": "cored-v4.0.1",
"v3": "cored-v3.0.3",
"v4": string(tools.CoredV401),
}
dockerLinuxBinaryPath := filepath.Join(
c.config.BinDir, ".cache", "cored", tools.TargetPlatformLinuxLocalArchInDocker.String(), "bin",
)
for upgrade, binary := range upgrades {
err := copyFile(filepath.Join(dockerLinuxBinaryPath, binary),
filepath.Join(c.config.HomeDir, "cosmovisor", "upgrades", upgrade, "bin", "cored"), 0o755)
Expand All @@ -440,7 +441,7 @@ func (c Cored) prepare(ctx context.Context) error {
}

func (c Cored) saveClientWrapper(wrapperDir, hostname string) error {
client := `#!/bin/bash
clientWrapper := `#!/bin/bash
OPTS=""
if [ "$1" == "tx" ] || [ "$1" == "q" ] || [ "$1" == "query" ]; then
OPTS="$OPTS --node ""` + infra.JoinNetAddr("tcp", hostname, c.config.Ports.RPC) + `"""
Expand All @@ -457,7 +458,7 @@ exec "` +
filepath.Dir(c.config.HomeDir) +
`" "$@" $OPTS
`
return errors.WithStack(os.WriteFile(filepath.Join(wrapperDir, c.Name()), []byte(client), 0o700))
return errors.WithStack(os.WriteFile(filepath.Join(wrapperDir, c.Name()), []byte(clientWrapper), 0o700))
}

// SaveGenesis saves json encoded representation of the genesis config into file.
Expand Down Expand Up @@ -488,15 +489,18 @@ func (c Cored) SaveGenesis(ctx context.Context, homeDir string) error {
"--chain-id", string(c.config.GenesisInitConfig.ChainID),
}

binaryPath := c.localBinaryPath()
// get particular binary path from or run using the default(compiled) binary
var binaryPath string
if c.config.BinaryVersion != "" {
binaryPath = filepath.Join(
c.config.BinDir,
".cache",
"cored",
"docker.linux."+runtime.GOARCH, "bin",
tools.TargetPlatformLocal.String(), "bin",
"cored"+"-"+c.Config().BinaryVersion,
)
} else {
binaryPath = filepath.Join(c.config.BinDir, "cored")
}

return libexec.Exec(
Expand Down

0 comments on commit d1f7e10

Please sign in to comment.