Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 build/rofl/scheduler/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ const (
MetadataKeyORCReference = "net.oasis.deployment.orc.ref"
// MetadataKeyProxyCustomDomains is the name of the metadata key that stores the proxy custom domains.
MetadataKeyProxyCustomDomains = "net.oasis.proxy.custom_domains"
// MetadataKeyProxyProtocol is the name of the metadata key that stores the PROXY protocol version.
MetadataKeyProxyProtocol = "net.oasis.proxy.proxy_protocol"
)
49 changes: 49 additions & 0 deletions cmd/rofl/build/tdx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,55 @@ func TestValidateAppFallsBackToGlobalCompose(t *testing.T) {
require.Equal(t, "global.example.com", cfg.Ports[0].CustomDomain)
}

func TestValidateAppProxyProtocol(t *testing.T) {
tmpDir := t.TempDir()
t.Chdir(tmpDir)

manifest := testContainerManifest()
manifest.Artifacts = &buildRofl.ArtifactsConfig{
Container: buildRofl.ContainerArtifactsConfig{
Compose: globalComposeFile,
},
}
manifest.Deployments = map[string]*buildRofl.Deployment{
"testnet": {
Network: "testnet",
ParaTime: "sapphire",
},
}

for _, tc := range []struct {
annotation string
expected string
valid bool
}{
{`"net.oasis.proxy.ports.8080.proxy_protocol": v2`, "v2", true},
{`"net.oasis.proxy.ports.8080.mode": passthrough`, "", true},
{`"net.oasis.proxy.ports.8080.proxy_protocol": v1`, "", false},
} {
compose := []byte(`services:
web:
image: ghcr.io/oasisprotocol/test:latest
ports:
- target: 80
published: "8080"
protocol: tcp
annotations:
` + tc.annotation + `
`)
require.NoError(t, os.WriteFile(filepath.Join(tmpDir, globalComposeFile), compose, 0o600))

cfg, err := ValidateApp(manifest, "testnet", ValidationOpts{Offline: true})
if !tc.valid {
require.ErrorContains(t, err, "invalid PROXY protocol version")
continue
}
require.NoError(t, err)
require.Len(t, cfg.Ports, 1)
require.Equal(t, tc.expected, cfg.Ports[0].ProxyProtocol)
}
}

func testContainerManifest() *buildRofl.Manifest {
return &buildRofl.Manifest{
Name: "test-app",
Expand Down
11 changes: 11 additions & 0 deletions cmd/rofl/build/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type PortMapping struct {
GenericDomain string
// CustomDomain is the custom domain name (if any).
CustomDomain string
// ProxyProtocol is the PROXY protocol version that the service expects on the port (if any).
ProxyProtocol string
}

// ValidateApp validates the ROFL app manifest for the selected deployment.
Expand Down Expand Up @@ -193,12 +195,14 @@ func validateComposeFile(composeFile string, manifest *buildRofl.Manifest, opts
}
customDomains[customDomain] = struct{}{}
}
proxyProtocol := service.Annotations[fmt.Sprintf("net.oasis.proxy.ports.%s.proxy_protocol", port.Published)]
appCfg.Ports = append(appCfg.Ports, &PortMapping{
ServiceName: serviceName,
Port: port.Published,
ProxyMode: proxyMode,
GenericDomain: genericDomain,
CustomDomain: customDomain,
ProxyProtocol: proxyProtocol,
})
}

Expand Down Expand Up @@ -227,6 +231,13 @@ func validateComposeFile(composeFile string, manifest *buildRofl.Manifest, opts
return nil, fmt.Errorf("proxy port annotation of service '%s', port '%d' has an invalid mode: %s", serviceName, port, value)
}
case "custom_domain":
case "proxy_protocol":
// Validate supported versions.
switch value {
case "v2":
default:
return nil, fmt.Errorf("proxy port annotation of service '%s', port '%d' has an invalid PROXY protocol version: %s", serviceName, port, value)
}
default:
}
default:
Expand Down
16 changes: 16 additions & 0 deletions cmd/rofl/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ var (
if customDomains := extractCustomDomains(extraCfg); customDomains != "" {
machineDeployment.Metadata[scheduler.MetadataKeyProxyCustomDomains] = customDomains
}
if proxyProtocol := extractProxyProtocol(extraCfg); proxyProtocol != "" {
machineDeployment.Metadata[scheduler.MetadataKeyProxyProtocol] = proxyProtocol
}

var acc wallet.Account
switch common.TxUnsigned {
Expand Down Expand Up @@ -491,6 +494,19 @@ func extractCustomDomains(extraCfg *roflCmdBuild.AppExtraConfig) string {
return strings.Join(customDomains, " ")
}

func extractProxyProtocol(extraCfg *roflCmdBuild.AppExtraConfig) string {
if extraCfg == nil {
return ""
}

for _, p := range extraCfg.Ports {
if p.ProxyProtocol != "" {
return p.ProxyProtocol
}
}
return ""
}

func init() {
providerFlags := flag.NewFlagSet("", flag.ContinueOnError)
// Default to Testnet playground provider.
Expand Down
Loading