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
8 changes: 8 additions & 0 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,14 @@ func (s *Runtime) Init(ctx context.Context, req *runtimev0.InitRequest) (*runtim
if err := s.EnvironmentVariables.AddEndpoints(ctx, s.NetworkMappings, resources.NetworkAccessFromRuntimeContext(s.Base.Runtime.RuntimeContext)); err != nil {
return s.Base.Runtime.InitError(err)
}
// Workspace configuration is a separate InitRequest field, not part of
// service/dependency configuration. Install it before creating the runner
// so initialization and the eventual application receive the same bindings.
// Workspace inputs have no RuntimeContext: the composition has already
// selected its environment. Filtering them as dependency outputs drops them.
if err := s.EnvironmentVariables.AddConfigurations(ctx, req.WorkspaceConfigurations...); err != nil {
return s.Base.Runtime.InitError(err)
}

env, cacheLocation, err := s.runnerEnv(ctx)
if err != nil {
Expand Down
38 changes: 38 additions & 0 deletions workspace_configuration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"context"
"testing"

basev0 "github.com/codefly-dev/core/generated/go/codefly/base/v0"
runtimev0 "github.com/codefly-dev/core/generated/go/codefly/services/runtime/v0"
"github.com/codefly-dev/core/resources"
"github.com/stretchr/testify/require"
)

func TestWorkspaceConfigurationReachesServiceProcess(t *testing.T) {
runtime, env, req := initStartTestRuntime(t)
req.WorkspaceConfigurations = []*basev0.Configuration{{
Origin: resources.ConfigurationWorkspace,
Infos: []*basev0.ConfigurationInformation{{
Name: "gateway",
ConfigurationValues: []*basev0.ConfigurationValue{
{Key: "profile", Value: "local/fake-text"},
{Key: "token", Value: "synthetic-test-token", Secret: true},
},
}},
}}
initialized, err := runtime.Init(context.Background(), req)
require.NoError(t, err)
require.Equal(t, runtimev0.InitStatus_READY, initialized.GetStatus().GetState())
started, err := runtime.Start(context.Background(), &runtimev0.StartRequest{})
require.NoError(t, err)
require.Equal(t, runtimev0.StartStatus_STARTED, started.GetStatus().GetState())
t.Cleanup(func() { _, _ = runtime.Stop(context.Background(), &runtimev0.StopRequest{}) })
values := map[string]string{}
for _, variable := range uvicornProc(t, env).envs {
values[variable.Key] = variable.ValueAsString()
}
require.Equal(t, "local/fake-text", values["CODEFLY__WORKSPACE_CONFIGURATION__GATEWAY__PROFILE"])
require.Equal(t, "synthetic-test-token", values["CODEFLY__WORKSPACE_SECRET_CONFIGURATION__GATEWAY__TOKEN"])
}
Loading