@@ -142,10 +142,43 @@ func marshalDockerfile(ctx context.Context, dt []byte, opts ...llb.ConstraintsOp
142142}
143143
144144func getSigningConfigFromContext (ctx context.Context , client gwclient.Client , cfgPath string , configCtxName string , sOpt dalec.SourceOpts , opts ... llb.ConstraintsOpt ) (* dalec.PackageSigner , error ) {
145+ dt , err := readConfigFromContext (ctx , client , cfgPath , configCtxName , sOpt , opts ... )
146+ if err != nil {
147+ return nil , err
148+ }
149+
150+ var pc dalec.PackageConfig
151+ if err := yaml .Unmarshal (dt , & pc ); err != nil {
152+ return nil , err
153+ }
154+
155+ return pc .Signer , nil
156+ }
157+
158+ func getSourceFilterConfigFromContext (ctx context.Context , client gwclient.Client , cfgPath string , configCtxName string , getContext func (string , ... llb.LocalOption ) (* llb.State , error ), opts ... llb.ConstraintsOpt ) (dalec.SourceFilterConfig , error ) {
159+ dt , err := readConfigFromContext (ctx , client , cfgPath , configCtxName , dalec.SourceOpts {
160+ GetContext : getContext ,
161+ }, opts ... )
162+ if err != nil {
163+ return dalec.SourceFilterConfig {}, err
164+ }
165+
166+ return decodeSourceFilterConfig (ctx , dt )
167+ }
168+
169+ func decodeSourceFilterConfig (ctx context.Context , dt []byte ) (dalec.SourceFilterConfig , error ) {
170+ var cfg dalec.SourceFilterConfig
171+ if err := yaml .UnmarshalContext (ctx , dt , & cfg , yaml .Strict ()); err != nil {
172+ return dalec.SourceFilterConfig {}, err
173+ }
174+ return cfg , nil
175+ }
176+
177+ func readConfigFromContext (ctx context.Context , client gwclient.Client , cfgPath string , configCtxName string , sOpt dalec.SourceOpts , opts ... llb.ConstraintsOpt ) ([]byte , error ) {
145178 src := dalec.Source {Path : cfgPath , Context : & dalec.SourceContext {Name : configCtxName }}
146- signConfigState := src .ToState ("" , sOpt , opts ... )
179+ configState := src .ToState ("" , dalec. SourceOpts { GetContext : sOpt . GetContext } , opts ... )
147180
148- scDef , err := signConfigState .Marshal (ctx )
181+ scDef , err := configState .Marshal (ctx )
149182 if err != nil {
150183 return nil , err
151184 }
@@ -162,19 +195,9 @@ func getSigningConfigFromContext(ctx context.Context, client gwclient.Client, cf
162195 return nil , err
163196 }
164197
165- dt , err := ref .ReadFile (ctx , gwclient.ReadRequest {
198+ return ref .ReadFile (ctx , gwclient.ReadRequest {
166199 Filename : cfgPath ,
167200 })
168- if err != nil {
169- return nil , err
170- }
171-
172- var pc dalec.PackageConfig
173- if err := yaml .Unmarshal (dt , & pc ); err != nil {
174- return nil , err
175- }
176-
177- return pc .Signer , nil
178201}
179202
180203func MaybeSign (ctx context.Context , client gwclient.Client , st llb.State , spec * dalec.Spec , targetKey string , sOpt dalec.SourceOpts , opts ... llb.ConstraintsOpt ) llb.State {
@@ -242,6 +265,27 @@ func getSignConfigCtxName(client gwclient.Client) string {
242265 return client .BuildOpts ().Opts ["build-arg:" + buildArgDalecSigningConfigContextName ]
243266}
244267
268+ func getSourceFilterConfigPath (client gwclient.Client ) string {
269+ return client .BuildOpts ().Opts ["build-arg:" + dalec .BuildArgDalecSourceFilterConfigPath ]
270+ }
271+
272+ func getSourceFilterContextNameWithDefault (client gwclient.Client ) string {
273+ configCtxName := dalec .DefaultSourceOptionsContextName
274+ if cn := client .BuildOpts ().Opts ["build-arg:" + dalec .BuildArgDalecSourceFilterContextName ]; cn != "" {
275+ configCtxName = cn
276+ }
277+ return configCtxName
278+ }
279+
280+ func loadSourceFilterConfig (ctx context.Context , client gwclient.Client , getContext func (string , ... llb.LocalOption ) (* llb.State , error )) (dalec.SourceFilterConfig , error ) {
281+ cfgPath := getSourceFilterConfigPath (client )
282+ if cfgPath == "" {
283+ return dalec.SourceFilterConfig {}, nil
284+ }
285+
286+ return getSourceFilterConfigFromContext (ctx , client , cfgPath , getSourceFilterContextNameWithDefault (client ), getContext )
287+ }
288+
245289func forwardToSigner (ctx context.Context , client gwclient.Client , cfg * dalec.PackageSigner , s llb.State , opts ... llb.ConstraintsOpt ) (llb.State , error ) {
246290 const (
247291 // See https://github.com/moby/buildkit/blob/d8d946b85c52095d34a52ce210960832f4e06775/frontend/dockerui/context.go#L29
0 commit comments