Skip to content

Commit 6416b90

Browse files
committed
feat(cmd/rofl): Move debug flag to manifest
1 parent c7090a5 commit 6416b90

File tree

6 files changed

+21
-31
lines changed

6 files changed

+21
-31
lines changed

build/rofl/manifest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ type Deployment struct {
187187
ParaTime string `yaml:"paratime" json:"paratime"`
188188
// Admin is the identifier of the admin account.
189189
Admin string `yaml:"admin,omitempty" json:"admin,omitempty"`
190+
// Debug is a flag denoting whether this is a debuggable deployment.
191+
Debug bool `yaml:"debug,omitempty" json:"debug,omitempty"`
190192
// TrustRoot is the optional trust root configuration.
191193
TrustRoot *TrustRootConfig `yaml:"trust_root,omitempty" json:"trust_root,omitempty"`
192194
// Policy is the ROFL app policy.

cmd/rofl/build/build.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/oasisprotocol/oasis-core/go/common/cbor"
1414
"github.com/oasisprotocol/oasis-core/go/common/sgx"
1515
"github.com/oasisprotocol/oasis-core/go/common/version"
16-
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
1716
"github.com/oasisprotocol/oasis-core/go/runtime/bundle"
1817
"github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
1918

@@ -27,7 +26,6 @@ import (
2726
const (
2827
buildModeProduction = "production"
2928
buildModeUnsafe = "unsafe"
30-
buildModeAuto = "auto"
3129
)
3230

3331
var (
@@ -50,12 +48,20 @@ var (
5048
fmt.Printf("Deployment: %s\n", deploymentName)
5149
fmt.Printf("Network: %s\n", deployment.Network)
5250
fmt.Printf("ParaTime: %s\n", deployment.ParaTime)
51+
fmt.Printf("Debug: %v\n", deployment.Debug)
5352
fmt.Printf("App ID: %s\n", deployment.AppID)
5453
fmt.Printf("Name: %s\n", manifest.Name)
5554
fmt.Printf("Version: %s\n", manifest.Version)
5655
fmt.Printf("TEE: %s\n", manifest.TEE)
5756
fmt.Printf("Kind: %s\n", manifest.Kind)
5857

58+
switch deployment.Debug {
59+
case true:
60+
buildMode = buildModeUnsafe
61+
case false:
62+
buildMode = buildModeProduction
63+
}
64+
5965
// Prepare temporary build directory.
6066
tmpDir, err := os.MkdirTemp("", "oasis-build")
6167
if err != nil {
@@ -171,29 +177,6 @@ var (
171177
}
172178
)
173179

174-
func detectBuildMode(npa *common.NPASelection) {
175-
// Configure build mode. In case auto is selected and not offline, query the network. If
176-
// autodetection fails, default to production mode.
177-
switch {
178-
case buildMode == buildModeAuto && !offline:
179-
ctx := context.Background()
180-
conn, err := connection.Connect(ctx, npa.Network)
181-
if err != nil {
182-
cobra.CheckErr(fmt.Errorf("unable to autodetect build mode, please provide --mode flag manually (failed to connect to GRPC endpoint: %w)", err))
183-
}
184-
185-
params, err := conn.Consensus().Registry().ConsensusParameters(ctx, consensus.HeightLatest)
186-
if err != nil {
187-
cobra.CheckErr(fmt.Errorf("unable to autodetect build mode, please provide --mode flag manually (failed to get consensus parameters: %w)", err))
188-
}
189-
190-
if params.DebugAllowTestRuntimes {
191-
buildMode = buildModeUnsafe
192-
}
193-
default:
194-
}
195-
}
196-
197180
func setupBuildEnv(deployment *buildRofl.Deployment, npa *common.NPASelection) {
198181
// Configure app ID.
199182
os.Setenv("ROFL_APP_ID", deployment.AppID)
@@ -267,7 +250,6 @@ func fetchTrustRoot(npa *common.NPASelection, cfg *buildRofl.TrustRootConfig) (s
267250

268251
func init() {
269252
buildFlags := flag.NewFlagSet("", flag.ContinueOnError)
270-
buildFlags.StringVar(&buildMode, "mode", "auto", "build mode [production, unsafe, auto]")
271253
buildFlags.BoolVar(&offline, "offline", false, "do not perform any operations requiring network access")
272254
buildFlags.StringVar(&outputFn, "output", "", "output bundle filename")
273255
buildFlags.BoolVar(&doUpdate, "update-manifest", false, "automatically update the manifest")

cmd/rofl/build/container.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func tdxBuildContainer(
4545
)
4646
tdxOverrideArtifacts(manifest, wantedArtifacts)
4747
artifacts := tdxFetchArtifacts(wantedArtifacts)
48-
detectBuildMode(npa)
4948

5049
// Use the pre-built container runtime.
5150
initPath := artifacts[artifactContainerRuntime]

cmd/rofl/build/sgx.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ func sgxBuild(
3232
) {
3333
fmt.Println("Building an SGX-based Rust ROFL application...")
3434

35-
detectBuildMode(npa)
3635
features := sgxSetupBuildEnv(deployment, npa)
3736

3837
// First build for the default target.
@@ -218,7 +217,7 @@ func sgxSetupBuildEnv(deployment *buildRofl.Deployment, npa *common.NPASelection
218217
setupBuildEnv(deployment, npa)
219218

220219
switch buildMode {
221-
case buildModeProduction, buildModeAuto:
220+
case buildModeProduction:
222221
// Production builds.
223222
fmt.Println("Building in production mode.")
224223

cmd/rofl/build/tdx.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func tdxBuildRaw(
4747

4848
fmt.Println("Building a TDX-based Rust ROFL application...")
4949

50-
detectBuildMode(npa)
5150
tdxSetupBuildEnv(deployment, npa)
5251

5352
// Obtain package metadata.
@@ -308,7 +307,7 @@ func tdxSetupBuildEnv(deployment *buildRofl.Deployment, npa *common.NPASelection
308307
setupBuildEnv(deployment, npa)
309308

310309
switch buildMode {
311-
case buildModeProduction, buildModeAuto:
310+
case buildModeProduction:
312311
// Production builds.
313312
fmt.Println("Building in production mode.")
314313

cmd/rofl/mgmt.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,19 @@ var (
8383
height, err := common.GetActualHeight(ctx, conn.Consensus())
8484
cobra.CheckErr(err)
8585

86+
// Determine debug mode.
87+
var debugMode bool
88+
params, err := conn.Consensus().Registry().ConsensusParameters(ctx, height)
89+
if err == nil {
90+
debugMode = params.DebugAllowTestRuntimes
91+
}
92+
8693
// Generate manifest and a default policy which does not accept any enclaves.
8794
deployment := &buildRofl.Deployment{
8895
Network: npa.NetworkName,
8996
ParaTime: npa.ParaTimeName,
9097
Admin: npa.AccountName,
98+
Debug: debugMode,
9199
Policy: &rofl.AppAuthPolicy{
92100
Quotes: quote.Policy{
93101
PCS: &pcs.QuotePolicy{
@@ -134,6 +142,7 @@ var (
134142
fmt.Printf("Deployment '%s':\n", buildRofl.DefaultDeploymentName)
135143
fmt.Printf(" Network: %s\n", deployment.Network)
136144
fmt.Printf(" ParaTime: %s\n", deployment.ParaTime)
145+
fmt.Printf(" Debug: %v\n", deployment.Debug)
137146
fmt.Printf(" Admin: %s\n", deployment.Admin)
138147

139148
// Serialize manifest and write it to file.

0 commit comments

Comments
 (0)