Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit d11d1f3

Browse files
committed
builder: fix pull synchronization regression
Config resolution was synchronized based on a wrong key as ref variable is initialized only after in the same function. Using the right key isn't fully correct either as the synchronized method changes properties of the puller instance and can't be just skipped. Added better error handling for the same case as well. Signed-off-by: Tonis Tiigi <[email protected]> Upstream-commit: b53ea19c4989e5d2a5b90033de6fd55b423302a0 Component: engine
1 parent fe28d64 commit d11d1f3

File tree

1 file changed

+11
-5
lines changed
  • components/engine/builder/builder-next/adapters/containerimage

1 file changed

+11
-5
lines changed

components/engine/builder/builder-next/adapters/containerimage/pull.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func (is *Source) Resolve(ctx context.Context, id source.Identifier, sm *session
183183
type puller struct {
184184
is *Source
185185
resolveLocalOnce sync.Once
186+
g flightcontrol.Group
186187
src *source.ImageIdentifier
187188
desc ocispec.Descriptor
188189
ref string
@@ -253,9 +254,7 @@ func (p *puller) resolveLocal() {
253254
}
254255

255256
func (p *puller) resolve(ctx context.Context, g session.Group) error {
256-
// key is used to synchronize resolutions that can happen in parallel when doing multi-stage.
257-
key := "resolve::" + p.ref + "::" + platforms.Format(p.platform)
258-
_, err := p.is.g.Do(ctx, key, func(ctx context.Context) (_ interface{}, err error) {
257+
_, err := p.g.Do(ctx, "", func(ctx context.Context) (_ interface{}, err error) {
259258
resolveProgressDone := oneOffProgress(ctx, "resolve "+p.src.Reference.String())
260259
defer func() {
261260
resolveProgressDone(err)
@@ -329,6 +328,10 @@ func (p *puller) CacheKey(ctx context.Context, g session.Group, index int) (stri
329328
return dgst.String(), nil, false, nil
330329
}
331330

331+
if len(p.config) == 0 {
332+
return "", nil, false, errors.Errorf("invalid empty config file resolved for %s", p.src.Reference.String())
333+
}
334+
332335
k := cacheKeyFromConfig(p.config).String()
333336
if k == "" {
334337
dgst, err := p.mainManifestKey(p.platform)
@@ -360,8 +363,10 @@ func (p *puller) getRef(ctx context.Context, diffIDs []layer.DiffID, opts ...cac
360363

361364
func (p *puller) Snapshot(ctx context.Context, g session.Group) (cache.ImmutableRef, error) {
362365
p.resolveLocal()
363-
if err := p.resolve(ctx, g); err != nil {
364-
return nil, err
366+
if len(p.config) == 0 {
367+
if err := p.resolve(ctx, g); err != nil {
368+
return nil, err
369+
}
365370
}
366371

367372
if p.config != nil {
@@ -801,6 +806,7 @@ func cacheKeyFromConfig(dt []byte) digest.Digest {
801806
var img ocispec.Image
802807
err := json.Unmarshal(dt, &img)
803808
if err != nil {
809+
logrus.WithError(err).Errorf("failed to unmarshal image config for cache key %v", err)
804810
return digest.FromBytes(dt)
805811
}
806812
if img.RootFS.Type != "layers" || len(img.RootFS.DiffIDs) == 0 {

0 commit comments

Comments
 (0)