diff --git a/pkg/backend/build/builder.go b/pkg/backend/build/builder.go index 5fccf14b..3bc6fd0d 100644 --- a/pkg/backend/build/builder.go +++ b/pkg/backend/build/builder.go @@ -25,7 +25,6 @@ import ( "io" "os" "path/filepath" - "sync" "syscall" "time" @@ -39,7 +38,6 @@ import ( "github.com/modelpack/modctl/internal/cache" buildconfig "github.com/modelpack/modctl/pkg/backend/build/config" "github.com/modelpack/modctl/pkg/backend/build/hooks" - "github.com/modelpack/modctl/pkg/backend/build/interceptor" pkgcodec "github.com/modelpack/modctl/pkg/codec" "github.com/modelpack/modctl/pkg/storage" ) @@ -109,12 +107,11 @@ func NewBuilder(outputType OutputType, store storage.Storage, repo, tag string, } return &abstractBuilder{ - store: store, - repo: repo, - tag: tag, - strategy: strategy, - interceptor: cfg.interceptor, - cache: cache, + store: store, + repo: repo, + tag: tag, + strategy: strategy, + cache: cache, }, nil } @@ -125,8 +122,6 @@ type abstractBuilder struct { tag string // strategy is the output strategy used to output the blob. strategy OutputStrategy - // interceptor is the interceptor used to intercept the build process. - interceptor interceptor.Interceptor // cache is the cache used to store the file digest. cache cache.Cache } @@ -171,38 +166,11 @@ func (ab *abstractBuilder) BuildLayer(ctx context.Context, mediaType, workDir, p return ocispec.Descriptor{}, fmt.Errorf("failed to compute digest and size: %w", err) } - var ( - wg sync.WaitGroup - itErr error - applyDesc interceptor.ApplyDescriptorFn - ) - // Intercept the reader if needed. - if ab.interceptor != nil { - var itReader io.Reader - reader, itReader = splitReader(reader) - - wg.Add(1) - go func() { - defer wg.Done() - applyDesc, itErr = ab.interceptor.Intercept(ctx, mediaType, relPath, codec.Type(), itReader) - }() - } - desc, err := ab.strategy.OutputLayer(ctx, mediaType, relPath, destPath, digest, size, reader, hooks) if err != nil { return desc, err } - // Wait for the interceptor to finish. - wg.Wait() - if itErr != nil { - return desc, itErr - } - - if applyDesc != nil { - applyDesc(&desc) - } - // Add file metadata to descriptor. if err := addFileMetadata(&desc, path, relPath); err != nil { return desc, err @@ -409,26 +377,6 @@ func addFileMetadata(desc *ocispec.Descriptor, path, relPath string) error { return nil } -// splitReader splits the original reader into two readers. -func splitReader(original io.Reader) (io.Reader, io.Reader) { - r1, w1 := io.Pipe() - r2, w2 := io.Pipe() - multiWriter := io.MultiWriter(w1, w2) - - go func() { - defer w1.Close() - defer w2.Close() - - _, err := io.Copy(multiWriter, original) - if err != nil { - w1.CloseWithError(err) - w2.CloseWithError(err) - } - }() - - return r1, r2 -} - // getFileMetadata retrieves metadata for a file at the given path. func getFileMetadata(path string) (modelspec.FileMetadata, error) { var metadata modelspec.FileMetadata diff --git a/pkg/backend/build/builder_test.go b/pkg/backend/build/builder_test.go index 3c8f117a..d17cee06 100644 --- a/pkg/backend/build/builder_test.go +++ b/pkg/backend/build/builder_test.go @@ -19,12 +19,10 @@ package build import ( "context" "errors" - "io" "os" "path/filepath" "runtime" "strings" - "sync" "syscall" "testing" "time" @@ -282,21 +280,6 @@ func TestBuilderSuite(t *testing.T) { suite.Run(t, new(BuilderTestSuite)) } -func TestPipeReader(t *testing.T) { - r := strings.NewReader("some io.Reader stream to be read\n") - r1, r2 := splitReader(r) - var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() - _, err := io.Copy(os.Stdout, r2) - assert.NoError(t, err) - }() - _, err := io.Copy(os.Stdout, r1) - assert.NoError(t, err) - wg.Wait() -} - func createTempFile(t *testing.T, dir, pattern, content string) string { t.Helper() f, err := os.CreateTemp(dir, pattern) diff --git a/pkg/backend/build/config.go b/pkg/backend/build/config.go index 2d9bd4a3..10edef0f 100644 --- a/pkg/backend/build/config.go +++ b/pkg/backend/build/config.go @@ -16,17 +16,12 @@ package build -import ( - "github.com/modelpack/modctl/pkg/backend/build/interceptor" -) - type Option func(*config) // config is the configuration for the building. type config struct { - plainHTTP bool - insecure bool - interceptor interceptor.Interceptor + plainHTTP bool + insecure bool } func WithPlainHTTP(plainHTTP bool) Option { @@ -40,9 +35,3 @@ func WithInsecure(insecure bool) Option { c.insecure = insecure } } - -func WithInterceptor(interceptor interceptor.Interceptor) Option { - return func(c *config) { - c.interceptor = interceptor - } -} diff --git a/pkg/backend/build/interceptor/interceptor.go b/pkg/backend/build/interceptor/interceptor.go deleted file mode 100644 index 426ad2d4..00000000 --- a/pkg/backend/build/interceptor/interceptor.go +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2025 The ModelPack Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package interceptor - -import ( - "context" - "io" - - ocispec "github.com/opencontainers/image-spec/specs-go/v1" -) - -// ApplyDescriptorFn is a function that applies changes to the descriptor. -type ApplyDescriptorFn func(desc *ocispec.Descriptor) - -// Interceptor is an interface that defines the interceptor for the building stream. -type Interceptor interface { - // Intercept intercepts the building stream for some customized logic, readerType is the original stream type, such as raw or tar. - Intercept(ctx context.Context, mediaType string, filepath string, readerType string, reader io.Reader) (ApplyDescriptorFn, error) -}