Skip to content

Commit 3ca10d2

Browse files
Merge pull request #43 from PhlipPhlops/fix/workspace-configurations-to-runtime
fix: pass workspace configurations into runtime environment
2 parents 0328b95 + 6d3a464 commit 3ca10d2

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎runtime.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,14 @@ func (s *Runtime) Init(ctx context.Context, req *runtimev0.InitRequest) (*runtim
403403
if err := s.EnvironmentVariables.AddEndpoints(ctx, s.NetworkMappings, resources.NetworkAccessFromRuntimeContext(s.Base.Runtime.RuntimeContext)); err != nil {
404404
return s.Base.Runtime.InitError(err)
405405
}
406+
// Workspace configuration is a separate InitRequest field, not part of
407+
// service/dependency configuration. Install it before creating the runner
408+
// so initialization and the eventual application receive the same bindings.
409+
// Workspace inputs have no RuntimeContext: the composition has already
410+
// selected its environment. Filtering them as dependency outputs drops them.
411+
if err := s.EnvironmentVariables.AddConfigurations(ctx, req.WorkspaceConfigurations...); err != nil {
412+
return s.Base.Runtime.InitError(err)
413+
}
406414

407415
env, cacheLocation, err := s.runnerEnv(ctx)
408416
if err != nil {

‎workspace_configuration_test.go‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"testing"
6+
7+
basev0 "github.com/codefly-dev/core/generated/go/codefly/base/v0"
8+
runtimev0 "github.com/codefly-dev/core/generated/go/codefly/services/runtime/v0"
9+
"github.com/codefly-dev/core/resources"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestWorkspaceConfigurationReachesServiceProcess(t *testing.T) {
14+
runtime, env, req := initStartTestRuntime(t)
15+
req.WorkspaceConfigurations = []*basev0.Configuration{{
16+
Origin: resources.ConfigurationWorkspace,
17+
Infos: []*basev0.ConfigurationInformation{{
18+
Name: "gateway",
19+
ConfigurationValues: []*basev0.ConfigurationValue{
20+
{Key: "profile", Value: "local/fake-text"},
21+
{Key: "token", Value: "synthetic-test-token", Secret: true},
22+
},
23+
}},
24+
}}
25+
initialized, err := runtime.Init(context.Background(), req)
26+
require.NoError(t, err)
27+
require.Equal(t, runtimev0.InitStatus_READY, initialized.GetStatus().GetState())
28+
started, err := runtime.Start(context.Background(), &runtimev0.StartRequest{})
29+
require.NoError(t, err)
30+
require.Equal(t, runtimev0.StartStatus_STARTED, started.GetStatus().GetState())
31+
t.Cleanup(func() { _, _ = runtime.Stop(context.Background(), &runtimev0.StopRequest{}) })
32+
values := map[string]string{}
33+
for _, variable := range uvicornProc(t, env).envs {
34+
values[variable.Key] = variable.ValueAsString()
35+
}
36+
require.Equal(t, "local/fake-text", values["CODEFLY__WORKSPACE_CONFIGURATION__GATEWAY__PROFILE"])
37+
require.Equal(t, "synthetic-test-token", values["CODEFLY__WORKSPACE_SECRET_CONFIGURATION__GATEWAY__TOKEN"])
38+
}

0 commit comments

Comments
 (0)