Skip to content

Commit 7c6a48f

Browse files
committed
feat: Add --reset flag to rofl init
1 parent e99d389 commit 7c6a48f

File tree

2 files changed

+42
-23
lines changed

2 files changed

+42
-23
lines changed

cmd/rofl/mgmt.go

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141

4242
appTEE string
4343
appKind string
44+
reset bool
4445

4546
//go:embed init_artifacts/compose.yaml
4647
initArtifactCompose []byte
@@ -64,31 +65,44 @@ var (
6465
err = os.Chdir(appPath)
6566
cobra.CheckErr(err)
6667

67-
// Fail in case there is an existing manifest.
68-
if buildRofl.ManifestExists() {
69-
cobra.CheckErr("refusing to overwrite existing manifest")
70-
}
68+
var manifest *buildRofl.Manifest
69+
if !reset {
70+
// Fail in case there is an existing manifest.
71+
if buildRofl.ManifestExists() {
72+
cobra.CheckErr("Refusing to overwrite existing manifest.\nHint: To reset existing ROFL manifest, pass --reset flag.")
73+
}
7174

72-
// Create a default manifest without any deployments.
73-
// TODO: Extract author and repository from Git configuration if available.
74-
manifest := buildRofl.Manifest{
75-
Name: appName,
76-
Version: "0.1.0",
77-
TEE: appTEE,
78-
Kind: appKind,
79-
Resources: buildRofl.ResourcesConfig{
80-
Memory: 512,
81-
CPUCount: 1,
82-
Storage: &buildRofl.StorageConfig{
83-
Kind: buildRofl.StorageKindDiskPersistent,
84-
Size: 512,
75+
fmt.Printf("Creating a new app with default policy...\n")
76+
77+
// Create a default manifest without any deployments.
78+
manifest = &buildRofl.Manifest{
79+
Name: appName,
80+
Version: "0.1.0",
81+
TEE: appTEE,
82+
Kind: appKind,
83+
Resources: buildRofl.ResourcesConfig{
84+
Memory: 512,
85+
CPUCount: 1,
8586
},
86-
},
87+
}
88+
} else {
89+
manifest, err = buildRofl.LoadManifest()
90+
cobra.CheckErr(err)
91+
92+
fmt.Printf("\n")
93+
if !common.GetAnswerYes() {
94+
common.Confirm("Reset existing app manifest file by removing all configured ROFL deployments, secrets and policies", "not resetting")
95+
}
96+
97+
manifest.Name = appName
98+
manifest.Deployments = make(map[string]*buildRofl.Deployment)
8799
}
100+
101+
// TODO: Extract author and repository from Git configuration if available.
102+
88103
err = manifest.Validate()
89104
cobra.CheckErr(err)
90105

91-
fmt.Printf("Creating a new ROFL app with default policy...\n")
92106
fmt.Printf("Name: %s\n", manifest.Name)
93107
fmt.Printf("Version: %s\n", manifest.Version)
94108
fmt.Printf("TEE: %s\n", manifest.TEE)
@@ -828,6 +842,8 @@ func detectOrCreateComposeFile() string {
828842
func init() {
829843
initCmd.Flags().StringVar(&appTEE, "tee", "tdx", "TEE kind [tdx, sgx]")
830844
initCmd.Flags().StringVar(&appKind, "kind", "container", "ROFL app kind [container, raw]")
845+
initCmd.Flags().BoolVar(&reset, "reset", false, "reset the existing ROFL manifest")
846+
initCmd.Flags().AddFlagSet(common.AnswerYesFlag)
831847

832848
createCmd.Flags().AddFlagSet(common.SelectorFlags)
833849
createCmd.Flags().AddFlagSet(common.RuntimeTxFlags)

docs/rofl.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,20 @@ OFfchain Logic (ROFL)][rofl] apps:
1818

1919
## Initialize a new ROFL app manifest {#init}
2020

21-
The `rofl init` command will prepare a new ROFL app manifest in the given
22-
directory (defaults to the current directory). The manifest is a YAML file named
21+
The `rofl init` command will prepare a new ROFL manifest in the given directory
22+
(defaults to the current directory). The manifest is a YAML file named
2323
`rofl.yaml` which defines the versions of all components, upgrade policies, etc.
2424
needed to manage, build and deploy the ROFL app.
2525

2626
![code shell](../examples/rofl/init.in.static)
2727

2828
![code](../examples/rofl/init.out.static)
2929

30-
Note that by default the manifest will not contain any deployments. In order to
31-
create deployments, use `rofl create`.
30+
You can create a new ROFL manifest file based on the existing one by passing
31+
`--reset` flag. This is useful if you want to make your own deployment of
32+
the existing ROFL project. It will remove information on previous user-specific
33+
deployments but keep information such as the minimum CPU, memory and storage
34+
requirements.
3235

3336
## Create a new ROFL app on the network {#create}
3437

0 commit comments

Comments
 (0)