@@ -2,9 +2,11 @@ package export
22
33import (
44 "context"
5+ "encoding/base64"
56 "encoding/json"
67 "fmt"
78 "path/filepath"
9+ "strings"
810 "time"
911
1012 "github.com/cockroachdb/errors"
@@ -76,21 +78,6 @@ func Docker(ctx context.Context, app *apps.Instance, req *daemonpb.ExportRequest
7678 return false , errors .Wrap (err , "cache metadata" )
7779 }
7880
79- // Validate the service configs.
80- _ , err = bld .ServiceConfigs (ctx , builder.ServiceConfigsParams {
81- Parse : parse ,
82- CueMeta : & cueutil.Meta {
83- // Dummy data to satisfy config validation.
84- APIBaseURL : "http://localhost:0" ,
85- EnvName : "encore-eject" ,
86- EnvType : cueutil .EnvType_Development ,
87- CloudType : cueutil .CloudType_Local ,
88- },
89- })
90- if err != nil {
91- return false , err
92- }
93-
9481 log .Info ().Msgf ("compiling Encore application for %s/%s" , req .Goos , req .Goarch )
9582 result , err := bld .Compile (ctx , builder.CompileParams {
9683 Build : buildInfo ,
@@ -192,6 +179,28 @@ func Docker(ctx context.Context, app *apps.Instance, req *daemonpb.ExportRequest
192179 }
193180 spec .WriteFiles [defaultInfraConfigPath ] = data
194181 spec .Env = append (spec .Env , fmt .Sprintf ("ENCORE_INFRA_CONFIG_PATH=%s" , defaultInfraConfigPath ))
182+
183+ // Validate the service configs.
184+ cfgs , err := bld .ServiceConfigs (ctx , builder.ServiceConfigsParams {
185+ Parse : parse ,
186+ CueMeta : & cueutil.Meta {
187+ APIBaseURL : cfg .Metadata .BaseURL ,
188+ EnvName : cfg .Metadata .EnvName ,
189+ EnvType : orDefault (cueutil .EnvType (cfg .Metadata .EnvType ), "development" ),
190+ CloudType : orDefault (cueutil .CloudType (cfg .Metadata .Cloud ), "local" ),
191+ },
192+ })
193+ if err != nil {
194+ return false , err
195+ }
196+ for svcName , cfgStr := range cfgs .Configs {
197+ spec .Env = append (spec .Env , fmt .Sprintf (
198+ "%s%s=%s" ,
199+ "ENCORE_CFG_" ,
200+ strings .ToUpper (svcName ),
201+ base64 .RawURLEncoding .EncodeToString ([]byte (cfgStr )),
202+ ))
203+ }
195204 }
196205 var baseImgOverride option.Option [v1.Image ]
197206 if params .BaseImageTag != "" {
@@ -253,6 +262,14 @@ func Docker(ctx context.Context, app *apps.Instance, req *daemonpb.ExportRequest
253262 return true , nil
254263}
255264
265+ func orDefault [T comparable ](value T , defaultValue T ) T {
266+ var zero T
267+ if value == zero {
268+ return defaultValue
269+ }
270+ return value
271+ }
272+
256273func resolveBaseImage (ctx context.Context , log zerolog.Logger , p * daemonpb.DockerExportParams , spec * dockerbuild.ImageSpec ) (v1.Image , error ) {
257274 baseImgTag := p .BaseImageTag
258275 if baseImgTag == "" || baseImgTag == "scratch" {
0 commit comments