@@ -13,6 +13,7 @@ import (
1313 dockerclient "github.com/docker/docker/client"
1414 "github.com/outblocks/outblocks-cli/internal/util"
1515 "github.com/outblocks/outblocks-cli/pkg/config"
16+ "github.com/outblocks/outblocks-plugin-go/types"
1617 plugin_util "github.com/outblocks/outblocks-plugin-go/util"
1718 "github.com/outblocks/outblocks-plugin-go/util/errgroup"
1819 "github.com/pterm/pterm"
@@ -112,9 +113,16 @@ func (d *Deploy) runAppBuildCommand(ctx context.Context, cmd *util.CmdInfo, app
112113 return nil
113114}
114115
115- func (d * Deploy ) buildStaticApp (ctx context.Context , app * config.StaticApp ) error {
116+ func (d * Deploy ) buildStaticApp (ctx context.Context , app * config.StaticApp , eval * util.VarEvaluator ) error {
117+ var err error
118+
116119 env := plugin_util .MergeStringMaps (app .Env (), app .Build .Env )
117120
121+ env , err = eval .ExpandStringMap (env )
122+ if err != nil {
123+ return err
124+ }
125+
118126 cmd , err := util .NewCmdInfo (app .Build .Command , app .Dir (), util .FlattenEnvMap (env ))
119127 if err != nil {
120128 return fmt .Errorf ("error preparing build command for %s app: %s: %w" , app .Type (), app .Name (), err )
@@ -123,7 +131,7 @@ func (d *Deploy) buildStaticApp(ctx context.Context, app *config.StaticApp) erro
123131 return d .runAppBuildCommand (ctx , cmd , & app .BasicApp )
124132}
125133
126- func (d * Deploy ) buildServiceApp (ctx context.Context , app * config.ServiceApp ) error {
134+ func (d * Deploy ) buildServiceApp (ctx context.Context , app * config.ServiceApp , eval * util. VarEvaluator ) error {
127135 dockercontext := filepath .Join (app .Dir (), app .Build .DockerContext )
128136 dockercontext , ok := plugin_util .CheckDir (dockercontext )
129137
@@ -142,7 +150,12 @@ func (d *Deploy) buildServiceApp(ctx context.Context, app *config.ServiceApp) er
142150 return err
143151 }
144152
145- buildArgs := util .FlattenEnvMap (app .Build .DockerBuildArgs )
153+ buildArgsMap , err := eval .ExpandStringMap (app .Build .DockerBuildArgs )
154+ if err != nil {
155+ return err
156+ }
157+
158+ buildArgs := util .FlattenEnvMap (buildArgsMap )
146159 for i , arg := range buildArgs {
147160 buildArgs [i ] = strings .ReplaceAll (arg , "\" " , "\\ \" " )
148161 }
@@ -183,6 +196,20 @@ type appBuilder struct {
183196}
184197
185198func (d * Deploy ) buildApps (ctx context.Context ) error {
199+ appTypeMap := make (map [string ]* types.App )
200+
201+ if len (d .opts .TargetApps ) != 0 || len (d .opts .SkipApps ) != 0 {
202+ // Get state apps as well.
203+ state , _ , err := getState (ctx , d .cfg , false , 0 )
204+ if err != nil {
205+ return err
206+ }
207+
208+ for _ , app := range state .Apps {
209+ appTypeMap [app .ID ] = & app .App
210+ }
211+ }
212+
186213 var builders []* appBuilder
187214
188215 g , _ := errgroup .WithConcurrency (ctx , defaultConcurrency )
@@ -194,6 +221,8 @@ func (d *Deploy) buildApps(ctx context.Context) error {
194221 var appsTemp []config.App
195222
196223 for _ , app := range apps {
224+ appTypeMap [app .ID ()] = app .PluginType ()
225+
197226 if len (targetAppIDsMap ) > 0 && ! targetAppIDsMap [app .ID ()] {
198227 continue
199228 }
@@ -207,7 +236,17 @@ func (d *Deploy) buildApps(ctx context.Context) error {
207236
208237 apps = appsTemp
209238
239+ // Flatten appTypeMap.
240+ appTypes := make ([]* types.App , 0 , len (appTypeMap ))
241+ for _ , app := range appTypeMap {
242+ appTypes = append (appTypes , app )
243+ }
244+
245+ appVars := types .AppVarsFromApps (appTypes )
246+
210247 for _ , app := range apps {
248+ eval := util .NewVarEvaluator (types .VarsForApp (appVars , app .PluginType (), nil ))
249+
211250 // TODO: add build app function
212251 switch app .Type () {
213252 case config .AppTypeStatic :
@@ -219,15 +258,15 @@ func (d *Deploy) buildApps(ctx context.Context) error {
219258
220259 builders = append (builders , & appBuilder {
221260 app : a ,
222- build : func () error { return d .buildStaticApp (ctx , a ) },
261+ build : func () error { return d .buildStaticApp (ctx , a , eval ) },
223262 })
224263
225264 case config .AppTypeService :
226265 a := app .(* config.ServiceApp )
227266
228267 builders = append (builders , & appBuilder {
229268 app : a ,
230- build : func () error { return d .buildServiceApp (ctx , a ) },
269+ build : func () error { return d .buildServiceApp (ctx , a , eval ) },
231270 })
232271 }
233272 }
0 commit comments