@@ -142,10 +142,44 @@ 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+ SourceFilter : dalec .NoSourceFilter ,
162+ }, opts ... )
163+ if err != nil {
164+ return dalec.SourceFilterConfig {}, err
165+ }
166+
167+ return decodeSourceFilterConfig (ctx , dt )
168+ }
169+
170+ func decodeSourceFilterConfig (ctx context.Context , dt []byte ) (dalec.SourceFilterConfig , error ) {
171+ var cfg dalec.SourceFilterConfig
172+ if err := yaml .UnmarshalContext (ctx , dt , & cfg , yaml .Strict ()); err != nil {
173+ return dalec.SourceFilterConfig {}, err
174+ }
175+ return cfg , nil
176+ }
177+
178+ func readConfigFromContext (ctx context.Context , client gwclient.Client , cfgPath string , configCtxName string , sOpt dalec.SourceOpts , opts ... llb.ConstraintsOpt ) ([]byte , error ) {
145179 src := dalec.Source {Path : cfgPath , Context : & dalec.SourceContext {Name : configCtxName }}
146- signConfigState := src .ToState ("" , sOpt , opts ... )
180+ configState := src .ToState ("" , sOpt . WithoutSourceFilter () , opts ... )
147181
148- scDef , err := signConfigState .Marshal (ctx )
182+ scDef , err := configState .Marshal (ctx )
149183 if err != nil {
150184 return nil , err
151185 }
@@ -162,19 +196,9 @@ func getSigningConfigFromContext(ctx context.Context, client gwclient.Client, cf
162196 return nil , err
163197 }
164198
165- dt , err := ref .ReadFile (ctx , gwclient.ReadRequest {
199+ return ref .ReadFile (ctx , gwclient.ReadRequest {
166200 Filename : cfgPath ,
167201 })
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
178202}
179203
180204func 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 +266,27 @@ func getSignConfigCtxName(client gwclient.Client) string {
242266 return client .BuildOpts ().Opts ["build-arg:" + buildArgDalecSigningConfigContextName ]
243267}
244268
269+ func getSourceFilterConfigPath (client gwclient.Client ) string {
270+ return client .BuildOpts ().Opts ["build-arg:" + dalec .BuildArgDalecSourceFilterConfigPath ]
271+ }
272+
273+ func getSourceFilterContextNameWithDefault (client gwclient.Client ) string {
274+ configCtxName := dalec .DefaultSourceOptionsContextName
275+ if cn := client .BuildOpts ().Opts ["build-arg:" + dalec .BuildArgDalecSourceFilterContextName ]; cn != "" {
276+ configCtxName = cn
277+ }
278+ return configCtxName
279+ }
280+
281+ func loadSourceFilterConfig (ctx context.Context , client gwclient.Client , getContext func (string , ... llb.LocalOption ) (* llb.State , error )) (dalec.SourceFilterConfig , error ) {
282+ cfgPath := getSourceFilterConfigPath (client )
283+ if cfgPath == "" {
284+ return dalec.SourceFilterConfig {}, nil
285+ }
286+
287+ return getSourceFilterConfigFromContext (ctx , client , cfgPath , getSourceFilterContextNameWithDefault (client ), getContext )
288+ }
289+
245290func forwardToSigner (ctx context.Context , client gwclient.Client , cfg * dalec.PackageSigner , s llb.State , opts ... llb.ConstraintsOpt ) (llb.State , error ) {
246291 const (
247292 // See https://github.com/moby/buildkit/blob/d8d946b85c52095d34a52ce210960832f4e06775/frontend/dockerui/context.go#L29
0 commit comments