Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migration system for the config file #2792

Merged
merged 115 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 113 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
3c57492
Separate the struct definitions of the chainconfig from the parser
vinbrucelu May 28, 2022
cf8c19f
Move the struct Config into v0 package
vinbrucelu May 28, 2022
372c0cc
Add and implement the interface Config
vinbrucelu May 28, 2022
7f8bfd2
Parse the yaml based on the version
vinbrucelu May 28, 2022
aad2a3c
Move the filed Build into the common struct
vinbrucelu May 28, 2022
0e6ce31
Create the interface for validator
vinbrucelu May 28, 2022
929cfb6
Change the parameter for parse
vinbrucelu May 28, 2022
7cf49f4
Add the conversion
vinbrucelu May 28, 2022
efac007
Replace v0 with v1 after parsing
vinbrucelu May 28, 2022
fc796a2
Fix the getInit for v1
vinbrucelu May 28, 2022
fdc9084
Update the parser and the validator
vinbrucelu May 28, 2022
42c43bf
Replace v0 with v1 in env
vinbrucelu May 28, 2022
4830a14
Change the template
vinbrucelu May 28, 2022
116ef2e
Fixes the issue with the GetHost interface
vinbrucelu May 28, 2022
eeb5413
Add the method to increment the port number
vinbrucelu May 28, 2022
f1bd420
Move FaucetHost to the common package
vinbrucelu May 28, 2022
e2d3731
Remove the default() in config
vinbrucelu May 28, 2022
b89318d
Type the Version
vinbrucelu May 28, 2022
da50321
Refactor the function Parse
vinbrucelu May 28, 2022
a56989b
Add the test to verify the Parse with migration
vinbrucelu May 28, 2022
006300f
Clean up the interface of Config
vinbrucelu May 28, 2022
e9f3dc5
Update the subcommands for ignite chain
vinbrucelu May 28, 2022
d163f96
Add tests on the ConfigYaml an some comments
vinbrucelu May 28, 2022
a6c85e9
Add the struct defining Gentx
vinbrucelu May 28, 2022
d4add59
Remove the getters in BaseConfig
vinbrucelu May 31, 2022
f14b4cf
Fix the function ConvertLatest
vinbrucelu May 31, 2022
03615a5
Remove all getters
vinbrucelu May 31, 2022
06bcaa2
refactor createValidatorFromConfig
vinbrucelu May 31, 2022
f13ff23
Refactor the common pkg
vinbrucelu May 31, 2022
587a519
Change FillValidatorsDefaults and add tests
vinbrucelu May 31, 2022
fbfd109
a
ilgooz Jun 6, 2022
f2b9c23
chore: remove empty file
jeronimoalbi Aug 18, 2022
4161aff
refactor: simplify file names
jeronimoalbi Aug 18, 2022
b5f6ffc
refactor: improve tests layout
jeronimoalbi Aug 18, 2022
ebbed9c
refactor: add `config` package to `chainconfig`
jeronimoalbi Aug 22, 2022
e0500fd
refactor: rename `Config` interface to `Converter`
jeronimoalbi Aug 22, 2022
b54e484
chore: change testdata to give BaseConfig precedence
jeronimoalbi Aug 22, 2022
4752487
refactor: rename `Config.ConfigVersion` to `Config.Version`
jeronimoalbi Aug 22, 2022
a28a01e
chore: code cleanup for consistency
jeronimoalbi Aug 22, 2022
33690b9
chore: remove unused `BaseConfig.AccountByName` method
jeronimoalbi Aug 22, 2022
20f882f
refactor: move `ListAccounts()` into `BaseConfig`
jeronimoalbi Aug 23, 2022
215c248
refactor: rename `ErrCouldntLocateConfig` to `ErrConfigNotFound`
jeronimoalbi Aug 23, 2022
00cba50
chore: fix docstrings and broken test
jeronimoalbi Aug 23, 2022
5251f55
refactor: improve v0 to v1 conversion
jeronimoalbi Aug 25, 2022
a197b1a
feat: add `xnet` package
jeronimoalbi Aug 26, 2022
7c5f0a4
refactor: improve `v1` config implementation
jeronimoalbi Aug 26, 2022
c8dd687
refactor: remove global and rename var `Migration` to `Versions`
jeronimoalbi Aug 26, 2022
fa9978a
refactor: add default config function to `config`
jeronimoalbi Aug 26, 2022
5e46d12
refactor: change `ConvertLatest` to return `*v1.Config`
jeronimoalbi Aug 26, 2022
c3ade9d
refactor: move `ErrConfigNotFound` to `errors.go`
jeronimoalbi Aug 26, 2022
7751d98
fix: change v1 `ConvertNext` to assign 1 to the version
jeronimoalbi Aug 26, 2022
5216747
test: add `TestConvertV0ToV1` to `v0` convert tests
jeronimoalbi Aug 26, 2022
bf42bc9
test: change `v0` testdata to only return a v0 config with values
jeronimoalbi Aug 26, 2022
b4b42ad
fix: various fixes related to the refactor
jeronimoalbi Aug 26, 2022
4716c26
fix: parsing and migration now work using interfaces
jeronimoalbi Aug 28, 2022
7ad4b3f
refactor: change migration cmd verifier
jeronimoalbi Aug 28, 2022
81e2e66
fix: change config validation to validate "validators"
jeronimoalbi Aug 28, 2022
23f1cc0
chore: change `Seek` calls to use a constant argument
jeronimoalbi Aug 28, 2022
e0f71f5
refactor: change to use standard reader/writers instead of seeker
jeronimoalbi Aug 29, 2022
47e915b
test: add test for `MigrateLatest`
jeronimoalbi Aug 29, 2022
f396fbc
test: move testdata config files inside its corresponding version
jeronimoalbi Aug 29, 2022
94bb91a
refactor: rewrite `Parse()` tests
jeronimoalbi Aug 29, 2022
f90c424
fix: changed `v1` set defaults for don't ovewrite existing values
jeronimoalbi Aug 29, 2022
8971b69
chore: add more values to testdata config files
jeronimoalbi Aug 29, 2022
f56ef51
test: add `TestParseWithUnknownVersion` test
jeronimoalbi Aug 29, 2022
ba1b10f
chore: remove `GetConfigV0` from `v0` testdata
jeronimoalbi Aug 29, 2022
71a1b22
test: rewrite `v0` clone test
jeronimoalbi Aug 29, 2022
b4e4b5a
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Aug 29, 2022
7ee65d9
fix: change imports from "ignite-hq" to "ignite"
jeronimoalbi Aug 29, 2022
1cfe181
fix: change integration tests to work with the new config
jeronimoalbi Aug 29, 2022
42a80e6
chore: update changelog
jeronimoalbi Aug 29, 2022
abaa325
chore: fix integration test argument for `IsAppServed`
jeronimoalbi Aug 29, 2022
3388a46
test: fix broken integration tests
jeronimoalbi Aug 29, 2022
15f7b98
chore(pkg/xnet): add `MustIncreasePortBy` to simplify tests
jeronimoalbi Aug 30, 2022
3c80052
refactor: use struct to manage config's server addresses
jeronimoalbi Aug 31, 2022
488a640
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Aug 31, 2022
9a5bb1c
chore: minor corrections
jeronimoalbi Aug 31, 2022
7191c78
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Aug 31, 2022
1d31670
chore: remove unneeded `SetDefaults` call
jeronimoalbi Sep 1, 2022
b9aeaba
fix: change init chain to support merging YAML generated maps
jeronimoalbi Sep 1, 2022
4acd104
refactor: remove merge transformer in favor of a custom map type
jeronimoalbi Sep 2, 2022
ecc3b31
refactor: change chain's init to update app config files only once
jeronimoalbi Sep 2, 2022
0bc483c
test: fix broken integration test
jeronimoalbi Sep 2, 2022
ede171b
refactor: trigger config migration verifier from a pre run handler
jeronimoalbi Sep 2, 2022
f1ae0eb
refactor: change config migration cmd handler to use `cliui` package
jeronimoalbi Sep 2, 2022
876ed83
refactor: add a type alias for the latest config version
jeronimoalbi Sep 2, 2022
a6d171e
ci: fix typo
jeronimoalbi Sep 2, 2022
99e237b
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 2, 2022
dab938b
chore: rename variables to follow standard
jeronimoalbi Sep 2, 2022
ea528fb
refactor: change `addGitChangesVerifier` to a cmd pre run handler
jeronimoalbi Sep 2, 2022
53afcd9
refactor: add confirmation before migrating config in unclean state
jeronimoalbi Sep 2, 2022
998f7bc
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 2, 2022
3f04f51
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 8, 2022
ef354cb
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 8, 2022
b7ff910
fix: change config clonning to copy using mergo package
jeronimoalbi Sep 14, 2022
cc2ebcf
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 14, 2022
5362403
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 19, 2022
0451b29
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 20, 2022
0435812
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 22, 2022
f090c3f
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 25, 2022
a44858d
chore: replace deprecated call to ReadFile
jeronimoalbi Sep 25, 2022
219d8d2
chore: fix formatting
jeronimoalbi Sep 26, 2022
79a846d
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 26, 2022
0bad475
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Sep 28, 2022
360a7c1
tests: change `IsAppServed` to receive the API address
jeronimoalbi Sep 29, 2022
a953084
fix: change `pkg/yaml` to convert keys in slice of map
jeronimoalbi Sep 29, 2022
ce30e2b
tests: fix broken network publish integration test
jeronimoalbi Sep 29, 2022
4aa3b34
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Oct 3, 2022
c86b47a
Merge branch 'develop' into ilgooz/migration-refactor
Oct 3, 2022
6d057dc
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Oct 3, 2022
6183a05
Merge branch 'develop' into ilgooz/migration-refactor
jeronimoalbi Oct 4, 2022
4189baf
chore: add `gitChangesConfirmPreRunHandler` to `ts-client` cmd
jeronimoalbi Oct 4, 2022
e7594ae
test: fix broken TS client bank module integration test
jeronimoalbi Oct 4, 2022
72f84db
Merge branch 'develop' into ilgooz/migration-refactor
Oct 4, 2022
9283e92
Merge branch 'develop' into ilgooz/migration-refactor
Oct 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
- Add `--skip-proto` flag to `build`, `init` and `serve` commands to build the chain without building proto files
- Add `node query tx` command to query a transaction in any chain.
- Add `node query bank` command to query an account's bank balance in any chain.
- Add `node tx bank send` command to send funds from one account to an other in any chain.
- Add migration system for the config file to allow config versioning
- Add `node tx bank send` command to send funds from one account to another in any chain.
- Implement `network profile` command
- Add `generate ts-client` command to generate a stand-alone modular TypeScript client.
Expand Down
89 changes: 89 additions & 0 deletions ignite/chainconfig/chainconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package chainconfig

import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/ignite/cli/ignite/chainconfig/config"
v0 "github.com/ignite/cli/ignite/chainconfig/v0"
v1 "github.com/ignite/cli/ignite/chainconfig/v1"
"github.com/ignite/cli/ignite/pkg/xfilepath"
)

var (
// ConfigDirPath returns the path of configuration directory of Ignite.
ConfigDirPath = xfilepath.JoinFromHome(xfilepath.Path(".ignite"))

// ConfigFileNames is a list of recognized names as for Ignite's config file.
ConfigFileNames = []string{"config.yml", "config.yaml"}

// DefaultTSClientPath defines the default relative path to use when generating the TS client.
// The path is relative to the app's directory.
DefaultTSClientPath = "ts-client"

// LatestVersion defines the latest version of the config.
LatestVersion config.Version = 1

// Versions holds config types for the supported versions.
Versions = map[config.Version]config.Converter{
0: &v0.Config{},
1: &v1.Config{},
}
)

// Config defines the latest config.
type Config = v1.Config

// DefaultConfig returns a config for the latest version initialized with default values.
func DefaultConfig() *Config {
return v1.DefaultConfig()
}

// FaucetHost returns the faucet host to use.
func FaucetHost(cfg *Config) string {
// We keep supporting Port option for backward compatibility
// TODO: drop this option in the future
host := cfg.Faucet.Host
if cfg.Faucet.Port != 0 {
host = fmt.Sprintf(":%d", cfg.Faucet.Port)
}

return host
}

// TSClientPath returns the relative path to the Typescript client directory.
// Path is relative to the app's directory.
func TSClientPath(conf *Config) string {
if path := strings.TrimSpace(conf.Client.Typescript.Path); path != "" {
return filepath.Clean(path)
}

return DefaultTSClientPath
}

// CreateConfigDir creates config directory if it is not created yet.
func CreateConfigDir() error {
path, err := ConfigDirPath()
if err != nil {
return err
}

return os.MkdirAll(path, 0o755)
}

// LocateDefault locates the default path for the config file.
// Returns ErrConfigNotFound when no config file found.
func LocateDefault(root string) (path string, err error) {
for _, name := range ConfigFileNames {
path = filepath.Join(root, name)
if _, err := os.Stat(path); err == nil {
return path, nil
} else if !os.IsNotExist(err) {
return "", err
}
}

return "", ErrConfigNotFound
}
293 changes: 0 additions & 293 deletions ignite/chainconfig/config.go

This file was deleted.

Loading