Skip to content

Commit 954cd3f

Browse files
authored
Merge pull request #396 from oasisprotocol/matevz/feature/rofl-deploy
`oasis rofl deploy` instructions
2 parents d3af94d + 26db766 commit 954cd3f

File tree

6 files changed

+106
-18
lines changed

6 files changed

+106
-18
lines changed

cmd/rofl/build/build.go

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ import (
1414
"github.com/oasisprotocol/oasis-core/go/common/cbor"
1515
"github.com/oasisprotocol/oasis-core/go/common/sgx"
1616
"github.com/oasisprotocol/oasis-core/go/runtime/bundle"
17-
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
1817
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
19-
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl"
2018

2119
buildRofl "github.com/oasisprotocol/cli/build/rofl"
2220
"github.com/oasisprotocol/cli/cmd/common"
@@ -120,7 +118,7 @@ var (
120118
runScript(manifest, buildRofl.ScriptBuildPost)
121119

122120
// Write the bundle out.
123-
outFn := fmt.Sprintf("%s.%s.orc", manifest.Name, deploymentName)
121+
outFn := roflCommon.GetOrcFilename(manifest, deploymentName)
124122
if outputFn != "" {
125123
outFn = outputFn
126124
}
@@ -184,24 +182,12 @@ var (
184182

185183
// When not in offline mode, also verify on-chain enclave identities.
186184
if !offline {
187-
var conn connection.Connection
188185
ctx := context.Background()
189-
conn, err = connection.Connect(ctx, npa.Network)
186+
var cfgEnclaves map[sgx.EnclaveIdentity]struct{}
187+
cfgEnclaves, err = roflCommon.GetRegisteredEnclaves(ctx, deployment.AppID, npa)
190188
cobra.CheckErr(err)
191189

192-
var appID rofl.AppID
193-
_ = appID.UnmarshalText([]byte(deployment.AppID)) // Already verified.
194-
195-
var appCfg *rofl.AppConfig
196-
appCfg, err = conn.Runtime(npa.ParaTime).ROFL.App(ctx, client.RoundLatest, appID)
197-
cobra.CheckErr(err)
198-
199-
cfgEnclaves := make(map[sgx.EnclaveIdentity]struct{})
200-
for _, eid := range appCfg.Policy.Enclaves {
201-
cfgEnclaves[eid] = struct{}{}
202-
}
203-
204-
if !maps.Equal(manifestEnclaves, cfgEnclaves) {
190+
if !maps.Equal(buildEnclaves, cfgEnclaves) {
205191
fmt.Println("Built enclave identities DIFFER from on-chain enclave identities!")
206192
showIdentityDiff(buildEnclaves, cfgEnclaves, "On-chain")
207193
cobra.CheckErr(fmt.Errorf("enclave identity verification failed"))

cmd/rofl/common/enclave.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package common
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/oasisprotocol/oasis-core/go/common/sgx"
8+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
9+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
10+
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl"
11+
12+
"github.com/oasisprotocol/cli/cmd/common"
13+
)
14+
15+
// GetRegisteredEnclaves retrieves currently registered on-chain enclaves for the given deployment.
16+
func GetRegisteredEnclaves(ctx context.Context, rawAppID string, npa *common.NPASelection) (map[sgx.EnclaveIdentity]struct{}, error) {
17+
var conn connection.Connection
18+
var err error
19+
if conn, err = connection.Connect(ctx, npa.Network); err != nil {
20+
return nil, err
21+
}
22+
23+
var appID rofl.AppID
24+
if err = appID.UnmarshalText([]byte(rawAppID)); err != nil {
25+
return nil, fmt.Errorf("unable to extract app id: %v", err)
26+
}
27+
28+
var appCfg *rofl.AppConfig
29+
if appCfg, err = conn.Runtime(npa.ParaTime).ROFL.App(ctx, client.RoundLatest, appID); err != nil {
30+
return nil, err
31+
}
32+
33+
cfgEnclaves := make(map[sgx.EnclaveIdentity]struct{})
34+
for _, eid := range appCfg.Policy.Enclaves {
35+
cfgEnclaves[eid] = struct{}{}
36+
}
37+
38+
return cfgEnclaves, nil
39+
}

cmd/rofl/common/manifest.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,8 @@ func MaybeLoadManifestAndSetNPA(cfg *config.Config, npa *common.NPASelection, de
8787
}
8888
return manifest, d, nil
8989
}
90+
91+
// GetOrcFilename generates a filename based on the project name and deployment.
92+
func GetOrcFilename(manifest *rofl.Manifest, deploymentName string) string {
93+
return fmt.Sprintf("%s.%s.orc", manifest.Name, deploymentName)
94+
}

cmd/rofl/mgmt.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"maps"
89
"os"
910
"path/filepath"
1011

1112
"github.com/spf13/cobra"
1213
flag "github.com/spf13/pflag"
1314

15+
"github.com/oasisprotocol/oasis-core/go/common/sgx"
1416
"github.com/oasisprotocol/oasis-core/go/common/sgx/pcs"
1517
"github.com/oasisprotocol/oasis-core/go/common/sgx/quote"
1618
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
@@ -455,6 +457,53 @@ var (
455457
},
456458
}
457459

460+
deployCmd = &cobra.Command{
461+
Use: "deploy",
462+
Short: "Deploy ROFL to a specified instance",
463+
Args: cobra.NoArgs,
464+
Run: func(_ *cobra.Command, _ []string) {
465+
cfg := cliConfig.Global()
466+
npa := common.GetNPASelection(cfg)
467+
468+
manifest, deployment := roflCommon.LoadManifestAndSetNPA(cfg, npa, deploymentName, &roflCommon.ManifestOptions{
469+
NeedAppID: true,
470+
NeedAdmin: true,
471+
})
472+
473+
manifestEnclaves := make(map[sgx.EnclaveIdentity]struct{})
474+
for _, eid := range deployment.Policy.Enclaves {
475+
manifestEnclaves[eid] = struct{}{}
476+
}
477+
478+
ctx := context.Background()
479+
cfgEnclaves, err := roflCommon.GetRegisteredEnclaves(ctx, deployment.AppID, npa)
480+
cobra.CheckErr(err)
481+
482+
if !maps.Equal(manifestEnclaves, cfgEnclaves) {
483+
// TODO: Generate and run Update TX automatically.
484+
cobra.CheckErr("Local enclave identities DIFFER from on-chain enclave identities! Run `oasis rofl update` first")
485+
}
486+
487+
orcFilename := roflCommon.GetOrcFilename(manifest, deploymentName)
488+
cfgSnippet := " runtime:\n" +
489+
" paths:\n" +
490+
" - /node/rofls/" + orcFilename + "\n"
491+
fmt.Printf(
492+
"To deploy your ROFL app, you can decide between one of the two options:\n"+
493+
"\nA. RUN YOUR OWN OASIS NODE\n\n"+
494+
" 1. Follow https://docs.oasis.io/node/run-your-node/paratime-client-node\n"+
495+
" and configure your TDX Oasis node\n"+
496+
" 2. Copy '%s' to your node, for example:\n\n"+
497+
" scp %s mynode.com:/node/rofls\n\n"+
498+
" 3. Add the following snippet to your Oasis node config.yml:\n\n%s\n"+
499+
" 4. Restart your node\n"+
500+
"\nB. DEPLOY YOUR ROFL TO THE OASIS PROVIDER\n\n"+
501+
" 1. Upload '%s' to a publicly accessible file server\n"+
502+
" 2. Reach out to us at https://oasis.io/discord #dev-central channel and we\n"+
503+
" will run your ROFL app on our TDX Oasis nodes\n", orcFilename, orcFilename, cfgSnippet, orcFilename)
504+
},
505+
}
506+
458507
upgradeCmd = &cobra.Command{
459508
Use: "upgrade",
460509
Short: "Upgrade all artifacts to their latest default versions",
@@ -676,6 +725,10 @@ func init() {
676725
updateCmd.Flags().AddFlagSet(deploymentFlags)
677726
updateCmd.Flags().AddFlagSet(updateFlags)
678727

728+
deployCmd.Flags().AddFlagSet(common.SelectorFlags)
729+
deployCmd.Flags().AddFlagSet(common.RuntimeTxFlags)
730+
deployCmd.Flags().AddFlagSet(deploymentFlags)
731+
679732
removeCmd.Flags().AddFlagSet(common.SelectorFlags)
680733
removeCmd.Flags().AddFlagSet(common.RuntimeTxFlags)
681734
removeCmd.Flags().AddFlagSet(deploymentFlags)

cmd/rofl/rofl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func init() {
1616
Cmd.AddCommand(initCmd)
1717
Cmd.AddCommand(createCmd)
1818
Cmd.AddCommand(updateCmd)
19+
Cmd.AddCommand(deployCmd)
1920
Cmd.AddCommand(removeCmd)
2021
Cmd.AddCommand(showCmd)
2122
Cmd.AddCommand(trustRootCmd)

docs/rofl.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ account, staked amount, current ROFL policy and running instances:
127127

128128
![code](../examples/rofl/show.out.static)
129129

130+
## Deploy ROFL app {#deploy}
131+
132+
Run `rofl deploy` to automatically deploy your app to the provider on-chain.
133+
130134
## Advanced
131135

132136
### Show ROFL identity {#identity}

0 commit comments

Comments
 (0)