diff --git a/changelog.md b/changelog.md index 5048c20e1d..5d81fc8135 100644 --- a/changelog.md +++ b/changelog.md @@ -25,6 +25,7 @@ ### Changes +- [#4457](https://github.com/ignite/cli/pull/4457) Add `ski-build` flag to `chain serve` command to avoid building the chain - [#4094](https://github.com/ignite/cli/pull/4094) Scaffolding a multi-index map using `ignite s map foo bar baz --index foobar,foobaz` is no longer supported. Use one index instead of use `collections.IndexedMap`. - [#4058](https://github.com/ignite/cli/pull/4058) Simplify scaffolded modules by including `ValidateBasic()` logic in message handler. - [#4058](https://github.com/ignite/cli/pull/4058) Use `address.Codec` instead of `AccAddressFromBech32`. diff --git a/ignite/cmd/chain_serve.go b/ignite/cmd/chain_serve.go index bf23a6575c..27c6ede0d6 100644 --- a/ignite/cmd/chain_serve.go +++ b/ignite/cmd/chain_serve.go @@ -71,6 +71,7 @@ production, you may want to run "appd start" manually. c.Flags().AddFlagSet(flagSetHome()) c.Flags().AddFlagSet(flagSetCheckDependencies()) c.Flags().AddFlagSet(flagSetSkipProto()) + c.Flags().AddFlagSet(flagSetSkipBuild()) c.Flags().AddFlagSet(flagSetVerbose()) c.Flags().BoolP(flagForceReset, "f", false, "force reset of the app state on start and every source change") c.Flags().BoolP(flagResetOnce, "r", false, "reset the app state once on init") @@ -183,6 +184,10 @@ func chainServe(cmd *cobra.Command, session *cliui.Session) error { serveOptions = append(serveOptions, chain.ServeSkipProto()) } + if flagGetSkipBuild(cmd) { + serveOptions = append(serveOptions, chain.ServeSkipBuild()) + } + if quitOnFail { serveOptions = append(serveOptions, chain.QuitOnFail()) } diff --git a/ignite/cmd/cmd.go b/ignite/cmd/cmd.go index e2ab8930b8..38f4cc1a76 100644 --- a/ignite/cmd/cmd.go +++ b/ignite/cmd/cmd.go @@ -37,6 +37,7 @@ const ( flagYes = "yes" flagClearCache = "clear-cache" flagSkipProto = "skip-proto" + flagSkipBuild = "skip-build" checkVersionTimeout = time.Millisecond * 600 cacheFileName = "ignite_cache.db" @@ -216,6 +217,17 @@ func flagGetSkipProto(cmd *cobra.Command) bool { return skip } +func flagSetSkipBuild() *flag.FlagSet { + fs := flag.NewFlagSet("", flag.ContinueOnError) + fs.Bool(flagSkipBuild, false, "skip initial build of the app (uses local binary)") + return fs +} + +func flagGetSkipBuild(cmd *cobra.Command) bool { + skip, _ := cmd.Flags().GetBool(flagSkipBuild) + return skip +} + func flagSetClearCache(cmd *cobra.Command) { cmd.PersistentFlags().Bool(flagClearCache, false, "clear the build cache (advanced)") } diff --git a/ignite/services/chain/serve.go b/ignite/services/chain/serve.go index 99df738b80..415b1ed5d2 100644 --- a/ignite/services/chain/serve.go +++ b/ignite/services/chain/serve.go @@ -69,6 +69,7 @@ type serveOptions struct { forceReset bool resetOnce bool skipProto bool + skipBuild bool quitOnFail bool generateClients bool buildTags []string @@ -119,6 +120,14 @@ func ServeSkipProto() ServeOption { } } +// ServeSkipBuild allows to serve the app without rebuilding it. +// It looks up the binary in the PATH. +func ServeSkipBuild() ServeOption { + return func(c *serveOptions) { + c.skipBuild = true + } +} + // BuildTags set the build tags for the go build. func BuildTags(buildTags ...string) ServeOption { return func(c *serveOptions) { @@ -190,6 +199,7 @@ func (c *Chain) Serve(ctx context.Context, cacheStorage cache.Storage, options . serveOptions.buildTags, shouldReset, serveOptions.skipProto, + serveOptions.skipBuild, serveOptions.generateClients, ) serveOptions.resetOnce = false @@ -324,7 +334,7 @@ func (c *Chain) serve( ctx context.Context, cacheStorage cache.Storage, buildTags []string, - forceReset, skipProto, generateClients bool, + forceReset, skipProto, skipBuild, generateClients bool, ) error { conf, err := c.Config() if err != nil { @@ -406,7 +416,13 @@ func (c *Chain) serve( } // build phase - if !isInit || appModified { + // if the app is not initialized or the source/binary has been modified + // and if the --skip-build flag is not set + if skipBuild { + c.ev.SendInfo("Skip building activated. Binary won't be rebuilt, nor refresh on changes") + } + + if (!isInit || appModified) && !skipBuild { // build the blockchain app if err := c.build(ctx, cacheStorage, buildTags, "", skipProto, generateClients, true); err != nil { return err