Skip to content

Commit

Permalink
fix: linux binary installation for mock (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemijspavlovs authored Sep 11, 2024
1 parent 00eb247 commit 70e9d46
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 61 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: release for roller
on:
push:
branches:
- 'main'
tags:
- 'v*'
jobs:
Expand All @@ -22,7 +20,7 @@ jobs:
release-type: go
package-name: roller
prerelease: true
prerelease-label: beta
prerelease-label: alpha
changelog-types: >-
[
Expand All @@ -36,20 +34,24 @@ jobs:
# token must have repo write permissions ( https://github.com/googleapis/release-please/blob/main/docs/cli.md#create-a-manifest-pull-request-deprecated )
token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v4
if: steps.release-please.outputs.release_created
with:
fetch-depth: '0'

- name: Set up Go
uses: actions/setup-go@v5
if: steps.release-please.outputs.release_created
with:
check-latest: true
go-version-file: go.mod

- name: Setup release environment
if: steps.release-please.outputs.release_created
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |-
echo 'GITHUB_TOKEN=${{secrets.GITHUB_TOKEN}}' > .release-env
- name: Release publish
if: steps.release-please.outputs.release_created
run: make release
21 changes: 3 additions & 18 deletions cmd/relayer/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
Expand All @@ -19,7 +18,6 @@ import (
"github.com/dymensionxyz/roller/relayer"
"github.com/dymensionxyz/roller/sequencer"
globalutils "github.com/dymensionxyz/roller/utils"
"github.com/dymensionxyz/roller/utils/bash"
configutils "github.com/dymensionxyz/roller/utils/config"
"github.com/dymensionxyz/roller/utils/config/tomlconfig"
"github.com/dymensionxyz/roller/utils/config/yamlconfig"
Expand Down Expand Up @@ -123,24 +121,11 @@ func Cmd() *cobra.Command {
pterm.Info.Println("removing old systemd services")
for _, svc := range consts.RelayerSystemdServices {
svcFileName := fmt.Sprintf("%s.service", svc)
pterm.Info.Printf("removing %s", svcFileName)
svcFilePath := filepath.Join("/etc/systemd/system/", svcFileName)
c := exec.Command("sudo", "systemctl", "stop", svcFileName)
_, err := bash.ExecCommandWithStdout(c)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
return
}
c = exec.Command("sudo", "systemctl", "disable", svcFileName)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
return
}
c = exec.Command("sudo", "rm", svcFilePath)
_, err = bash.ExecCommandWithStdout(c)

err := globalutils.RemoveFileIfExists(svcFilePath)
if err != nil {
pterm.Error.Printf("failed to remove systemd services: %v\n", err)
pterm.Error.Println("failed to remove systemd service: ", err)
return
}
}
Expand Down
66 changes: 40 additions & 26 deletions cmd/rollapp/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,36 @@ func Cmd() *cobra.Command {
var hd consts.HubData
var env string

dymdBinaryOptions := dependencies.Dependency{
Name: "dymension",
Repository: "https://github.com/artemijspavlovs/dymension",
Release: "3.1.0-pg04",
Binaries: []dependencies.BinaryPathPair{
{
Binary: "dymd",
BinaryDestination: consts.Executables.Dymension,
BuildCommand: exec.Command(
"make",
"build",
),
},
},
}

pterm.Info.Println("installing dependencies")
err = installBinaryFromRelease(dymdBinaryOptions)
if err != nil {
pterm.Error.Println("failed to install dymd: ", err)
return
}

if shouldUseMockBackend {
env := "mock"
err = installBinaries("mock", true)
if err != nil {
pterm.Error.Println("failed to install binaries: ", err)
return
}
err := runInit(cmd, env, raID)
if err != nil {
fmt.Println("failed to run init: ", err)
Expand All @@ -67,6 +95,11 @@ func Cmd() *cobra.Command {
Show()
hd = consts.Hubs[env]
if env == "mock" {
err = installBinaries("mock", true)
if err != nil {
pterm.Error.Println("failed to install binaries: ", err)
return
}
err := runInit(cmd, env, raID)
if err != nil {
fmt.Println("failed to run init: ", err)
Expand All @@ -77,28 +110,6 @@ func Cmd() *cobra.Command {
}

// ex binaries install
dymdBinaryOptions := dependencies.Dependency{
Name: "dymension",
Repository: "https://github.com/artemijspavlovs/dymension",
Release: "3.1.0-pg04",
Binaries: []dependencies.BinaryPathPair{
{
Binary: "dymd",
BinaryDestination: consts.Executables.Dymension,
BuildCommand: exec.Command(
"make",
"build",
),
},
},
}

pterm.Info.Println("installing dependencies")
err = installBinaryFromRelease(dymdBinaryOptions)
if err != nil {
pterm.Error.Println("failed to install dymd: ", err)
return
}

raID = strings.TrimSpace(raID)

Expand All @@ -121,7 +132,7 @@ func Cmd() *cobra.Command {
pterm.Error.Println("no bech")
return
}
err = installBinaries(raResponse.Rollapp.GenesisInfo.Bech32Prefix)
err = installBinaries(raResponse.Rollapp.GenesisInfo.Bech32Prefix, false)
if err != nil {
pterm.Error.Println("failed to install binaries: ", err)
return
Expand Down Expand Up @@ -177,7 +188,7 @@ func Cmd() *cobra.Command {
return cmd
}

func installBinaries(bech32 string) error {
func installBinaries(bech32 string, withMockDA bool) error {
c := exec.Command("sudo", "mkdir", "-p", consts.InternalBinsDir)
_, err := bash.ExecCommandWithStdout(c)
if err != nil {
Expand Down Expand Up @@ -223,7 +234,10 @@ func installBinaries(bech32 string) error {
},
},
},
"celestia": {
}

if !withMockDA {
buildableDeps["celestia"] = dependencies.Dependency{
Repository: "https://github.com/celestiaorg/celestia-node.git",
Release: "v0.16.0",
Binaries: []dependencies.BinaryPathPair{
Expand All @@ -244,7 +258,7 @@ func installBinaries(bech32 string) error {
),
},
},
},
}
}

goreleaserDeps := map[string]dependencies.Dependency{
Expand Down
16 changes: 2 additions & 14 deletions cmd/rollapp/init/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,9 @@ func runInit(cmd *cobra.Command, env string, raID string) error {
pterm.Info.Println("removing old systemd services")
for _, svc := range consts.RollappSystemdServices {
svcFileName := fmt.Sprintf("%s.service", svc)
pterm.Info.Printf("removing %s", svcFileName)

svcFilePath := filepath.Join("/etc/systemd/system/", svcFileName)
c := exec.Command("sudo", "systemctl", "stop", svcFileName)
_, err := bash.ExecCommandWithStdout(c)
if err != nil {
return err
}
c = exec.Command("sudo", "systemctl", "disable", svcFileName)
_, err = bash.ExecCommandWithStdout(c)
if err != nil {
return err
}
c = exec.Command("sudo", "rm", svcFilePath)
_, err = bash.ExecCommandWithStdout(c)

err := globalutils.RemoveFileIfExists(svcFilePath)
if err != nil {
return err
}
Expand Down
16 changes: 16 additions & 0 deletions utils/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,19 @@ func ExtractTarGz(sourcePath, destDir string) error {
spinner.Success("Archive extracted successfully")
return nil
}

func RemoveFileIfExists(filePath string) error {
_, err := os.Stat(filePath)
if err == nil {
err := os.Remove(filePath)
if err != nil {
return fmt.Errorf("failed to remove file: %w", err)
}
fmt.Printf("File %s has been removed\n", filePath)
} else if os.IsNotExist(err) {
fmt.Printf("File %s does not exist\n", filePath)
} else {
return fmt.Errorf("error checking file: %w", err)
}
return nil
}

0 comments on commit 70e9d46

Please sign in to comment.