Skip to content

Commit

Permalink
Merge pull request #289 from kaleido-io/limit-upgrade
Browse files Browse the repository at this point in the history
Limit upgrade command
  • Loading branch information
peterbroadhurst authored Feb 28, 2024
2 parents 9b9a05c + 426b0ec commit c1379b3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
6 changes: 5 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package cmd

import (
"errors"
"fmt"
"os"

Expand Down Expand Up @@ -114,7 +115,10 @@ func initConfig() {

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err != nil {
fmt.Println(err.Error())
var e viper.ConfigFileNotFoundError
if !errors.As(err, &e) {
fmt.Println(err.Error())
}
}

}
18 changes: 18 additions & 0 deletions internal/core/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/hyperledger/firefly-cli/internal/constants"
"github.com/hyperledger/firefly-cli/internal/docker"
Expand Down Expand Up @@ -123,3 +124,20 @@ func ReadManifestFile(p string) (*types.VersionManifest, error) {
}
return manifest, err
}

func ValidateVersionUpgrade(oldVersion, newVersion string) error {
oldSemVer := strings.Split(strings.Trim(oldVersion, "v"), ".")
newSemVer := strings.Split(strings.Trim(newVersion, "v"), ".")
if len(oldSemVer) < 3 || len(newSemVer) < 3 {
return fmt.Errorf("FireFly CLI only supports updating local development environments between patch versions")
}
// Only upgrading between patch versions is supported
// e.g. 1.3.0 -> 1.3.1
if oldSemVer[0] == newSemVer[0] && oldSemVer[1] == newSemVer[1] {
if oldSemVer[2] > newSemVer[2] {
return fmt.Errorf("FireFly CLI does not support downgrading local development environments")
}
return nil
}
return fmt.Errorf("FireFly CLI only supports updating local development environments between patch versions")
}
11 changes: 11 additions & 0 deletions internal/core/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ func TestGetLatestReleaseManifest(t *testing.T) {
assert.NotNil(t, manifest.TokensERC1155)
assert.NotNil(t, manifest.TokensERC20ERC721)
}

func TestIsSupportedVersionUpgrade(t *testing.T) {
assert.NoError(t, ValidateVersionUpgrade("v1.2.1", "v1.2.2"))
assert.NoError(t, ValidateVersionUpgrade("v1.2.0", "v1.2.2"))
assert.NoError(t, ValidateVersionUpgrade("1.2.1", "v1.2.2"))
assert.NoError(t, ValidateVersionUpgrade("v1.2.1", "1.2.2"))

assert.Error(t, ValidateVersionUpgrade("v1.2.2", "v1.3.0"))
assert.Error(t, ValidateVersionUpgrade("latest", "v1.3.0"))
assert.Error(t, ValidateVersionUpgrade("v1.2.2", "latest"))
}
17 changes: 14 additions & 3 deletions internal/stacks/stack_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,14 @@ func (s *StackManager) UpgradeStack(version string) error {
return err
}
oldManifest := s.Stack.VersionManifest
oldVersion, err := docker.GetImageLabel(fmt.Sprintf("%s@sha256:%s", oldManifest.FireFly.Image, oldManifest.FireFly.SHA), "tag")
if err != nil {
return err
}

if err := core.ValidateVersionUpgrade(oldVersion, version); err != nil {
return err
}

// get the version manifest for the new version
newManifest, err := core.GetManifestForRelease(version)
Expand Down Expand Up @@ -1091,9 +1099,12 @@ func replaceVersions(oldManifest, newManifest *types.VersionManifest, filename s
new = newManifest.Evmconnect.GetDockerImageString()
s = strings.ReplaceAll(s, old, new)

old = oldManifest.Tezosconnect.GetDockerImageString()
new = newManifest.Tezosconnect.GetDockerImageString()
s = strings.ReplaceAll(s, old, new)
// v1.2.x stacks may not have had a tezosconnect entry because it's new
if oldManifest.Tezosconnect != nil {
old = oldManifest.Tezosconnect.GetDockerImageString()
new = newManifest.Tezosconnect.GetDockerImageString()
s = strings.ReplaceAll(s, old, new)
}

old = oldManifest.Fabconnect.GetDockerImageString()
new = newManifest.Fabconnect.GetDockerImageString()
Expand Down

0 comments on commit c1379b3

Please sign in to comment.