Skip to content

Commit 94ebabe

Browse files
committed
Use ENCORE_APP_META_PATH for 'encore test'
1 parent e5579ec commit 94ebabe

File tree

13 files changed

+88
-33
lines changed

13 files changed

+88
-33
lines changed

cli/daemon/run/exec_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (mgr *Manager) ExecCommand(ctx context.Context, p ExecCommandParams) (err e
165165
Gateways: gateways,
166166
DefinedSecrets: secrets,
167167
SvcConfigs: cfg.Configs,
168-
IncludeMetaEnv: bld.NeedsMeta(),
168+
IncludeMeta: bld.NeedsMeta(),
169169
}
170170
procConf, err := configGen.AllInOneProc()
171171
if err != nil {

cli/daemon/run/exec_script.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func (mgr *Manager) ExecScript(ctx context.Context, p ExecScriptParams) (err err
197197
Gateways: gateways,
198198
DefinedSecrets: secrets,
199199
SvcConfigs: cfg.Configs,
200-
IncludeMetaEnv: bld.NeedsMeta(),
200+
IncludeMeta: bld.NeedsMeta(),
201201
}
202202
procConf, err := configGen.AllInOneProc()
203203
if err != nil {

cli/daemon/run/run.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func (r *Run) StartProcGroup(params *StartProcGroupParams) (p *ProcGroup, err er
551551
DefinedSecrets: params.Secrets,
552552
SvcConfigs: params.ServiceConfigs,
553553
DeployID: option.Some(fmt.Sprintf("run_%s", xid.New().String())),
554-
IncludeMetaEnv: r.Builder.NeedsMeta(),
554+
IncludeMeta: r.Builder.NeedsMeta(),
555555
},
556556
Experiments: params.Experiments,
557557
Meta: params.Meta,

cli/daemon/run/runtime_config2.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
serviceCfgEnvPrefix = "ENCORE_CFG_"
4040
listenEnvVar = "ENCORE_LISTEN_ADDR"
4141
metaEnvVar = "ENCORE_APP_META"
42+
metaPathEnvVar = "ENCORE_APP_META_PATH"
4243
)
4344

4445
type RuntimeConfigGenerator struct {
@@ -76,8 +77,11 @@ type RuntimeConfigGenerator struct {
7677
Gateways map[string]GatewayConfig
7778
AuthKey config.EncoreAuthKey
7879

79-
// Whether to include the metadata as an environment variable.
80-
IncludeMetaEnv bool
80+
// Whether to include the metadata.
81+
IncludeMeta bool
82+
// If set, write the metadata to the given path
83+
// instead of including it as an environment variable.
84+
MetaPath option.Option[string]
8185

8286
// The values of defined secrets.
8387
DefinedSecrets map[string]string
@@ -96,7 +100,6 @@ type GatewayConfig struct {
96100
func (g *RuntimeConfigGenerator) initialize() error {
97101
return g.initOnce.Do(func() error {
98102
g.conf = rtconfgen.NewBuilder()
99-
100103
newRid := func() string { return "res_" + xid.New().String() }
101104

102105
if deployID, ok := g.DeployID.Get(); ok {
@@ -719,7 +722,7 @@ func (g *RuntimeConfigGenerator) ForTests(newRuntimeConf bool) (envs []string, e
719722
svcNames := fns.Map(g.md.Svcs, func(svc *meta.Service) string { return svc.Name })
720723
envs = append(envs, g.encodeConfigs(svcNames...)...)
721724

722-
if g.IncludeMetaEnv {
725+
if g.IncludeMeta {
723726
metaBytes, err := proto.Marshal(g.md)
724727
if err != nil {
725728
return nil, errors.Wrap(err, "failed to marshal metadata")
@@ -779,14 +782,21 @@ func (g *RuntimeConfigGenerator) ProcEnvs(proc *ProcConfig, useRuntimeConfigV2 b
779782
env = append(env, fmt.Sprintf("%s=%s", runtimeCfgEnvVar, runtimeCfgStr))
780783
}
781784

782-
if g.IncludeMetaEnv {
785+
if g.IncludeMeta {
783786
metaBytes, err := proto.Marshal(g.md)
784787
if err != nil {
785788
return nil, errors.Wrap(err, "failed to marshal metadata")
786789
}
787-
gzipped := gzipBytes(metaBytes)
788-
metaEnvStr := "gzip:" + base64.StdEncoding.EncodeToString(gzipped)
789-
env = append(env, fmt.Sprintf("%s=%s", metaEnvVar, metaEnvStr))
790+
if metaPath, ok := g.MetaPath.Get(); ok {
791+
if err := os.WriteFile(metaPath, metaBytes, 0644); err != nil {
792+
return nil, errors.Wrap(err, "failed to write metadata")
793+
}
794+
env = append(env, fmt.Sprintf("%s=%s", metaPathEnvVar, metaPath))
795+
} else {
796+
gzipped := gzipBytes(metaBytes)
797+
metaEnvStr := "gzip:" + base64.StdEncoding.EncodeToString(gzipped)
798+
env = append(env, fmt.Sprintf("%s=%s", metaEnvVar, metaEnvStr))
799+
}
790800
}
791801

792802
if runtimeLibPath := encoreEnv.EncoreRuntimeLib(); runtimeLibPath != "" {

cli/daemon/run/tests.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"path/filepath"
78
"runtime"
89
"strings"
910

@@ -191,6 +192,15 @@ func (mgr *Manager) testSpec(ctx context.Context, bld builder.Impl, expSet *expe
191192
return nil, err
192193
}
193194

195+
var metaPath option.Option[string]
196+
if bld.NeedsMeta() {
197+
tempDir, err := bld.TempDir()
198+
if err != nil {
199+
return nil, err
200+
}
201+
metaPath = option.Some(filepath.Join(tempDir, "meta.pb"))
202+
}
203+
194204
authKey := genAuthKey()
195205
configGen := &RuntimeConfigGenerator{
196206
app: params.App,
@@ -206,7 +216,8 @@ func (mgr *Manager) testSpec(ctx context.Context, bld builder.Impl, expSet *expe
206216
EnvName: option.Some("test"),
207217
EnvType: option.Some(runtimev1.Environment_TYPE_TEST),
208218
DeployID: option.Some(fmt.Sprintf("clitest_%s", xid.New().String())),
209-
IncludeMetaEnv: bld.NeedsMeta(),
219+
IncludeMeta: bld.NeedsMeta(),
220+
MetaPath: metaPath,
210221
}
211222

212223
env, err := configGen.ForTests(bld.UseNewRuntimeConfig())

e2e-tests/app_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func RunApp(c testing.TB, appRoot string, logger RunLogger, env []string) *RunAp
8282
App: app,
8383
ResourceManager: rm,
8484
Mgr: mgr,
85-
Builder: v2builder.BuilderImpl{},
85+
Builder: v2builder.New(),
8686
}
8787

8888
parse, build, configs := testBuild(c, appRoot, env)

e2e-tests/echo_app_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ func TestProcClosedOnCtxCancel(t *testing.T) {
581581
ResourceManager: rm,
582582
ListenAddr: "127.0.0.1:34212",
583583
SvcProxy: svcProxy,
584-
Builder: v2builder.BuilderImpl{},
584+
Builder: v2builder.New(),
585585
}
586586

587587
parse, build, _ := testBuild(c, appRoot, append(os.Environ(), "ENCORE_EXPERIMENT=v2"))

pkg/builder/builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,5 +283,6 @@ type Impl interface {
283283
GenUserFacing(context.Context, GenUserFacingParams) error
284284
UseNewRuntimeConfig() bool
285285
NeedsMeta() bool
286+
TempDir() (string, error)
286287
Close() error
287288
}

pkg/builder/builderimpl/builders.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ func Resolve(lang appfile.Lang, expSet *experiments.Set) builder.Impl {
1212
if lang == appfile.LangTS || experiments.TypeScript.Enabled(expSet) {
1313
return tsbuilder.New()
1414
}
15-
return v2builder.BuilderImpl{}
15+
return v2builder.New()
1616
}

pkg/clientgen/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestClientCodeGenerationFromGoApp(t *testing.T) {
3333
c.Assert(err, qt.IsNil)
3434

3535
ctx := context.Background()
36-
bld := v2builder.BuilderImpl{}
36+
bld := v2builder.New()
3737

3838
for _, path := range tests {
3939
path := path

0 commit comments

Comments
 (0)