Skip to content

Commit 9fd48f9

Browse files
authored
fix: build failed when registry address with port (#47)
Signed-off-by: chlins <[email protected]>
1 parent 84b897f commit 9fd48f9

File tree

7 files changed

+20
-11
lines changed

7 files changed

+20
-11
lines changed

pkg/backend/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ func (b *backend) Build(ctx context.Context, modelfilePath, workDir, target stri
5757
// build the image config.
5858
configDesc, err := build.BuildConfig(ctx, b.store, repo)
5959
if err != nil {
60-
return fmt.Errorf("faile to build image config: %w", err)
60+
return fmt.Errorf("failed to build image config: %w", err)
6161
}
6262

6363
fmt.Printf("%-15s => %s (%s)\n", "Built config", configDesc.Digest, humanize.IBytes(uint64(configDesc.Size)))
6464

6565
// build the image manifest.
6666
manifestDesc, err := build.BuildManifest(ctx, b.store, repo, tag, layers, configDesc, manifestAnnotation(modelfile))
6767
if err != nil {
68-
return fmt.Errorf("faile to build image manifest: %w", err)
68+
return fmt.Errorf("failed to build image manifest: %w", err)
6969
}
7070

7171
fmt.Printf("%-15s => %s (%s)\n", "Built manifest", manifestDesc.Digest, humanize.IBytes(uint64(manifestDesc.Size)))

pkg/backend/extract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (b *backend) Extract(ctx context.Context, target string, output string) err
5252
return exportModelArtifact(ctx, b.store, manifest, repo, output)
5353
}
5454

55-
// exportModelArtifact exports the target model artifact to the output directory, which will open the artifact and extract to restore the orginal repo structure.
55+
// exportModelArtifact exports the target model artifact to the output directory, which will open the artifact and extract to restore the original repo structure.
5656
func exportModelArtifact(ctx context.Context, store storage.Storage, manifest ocispec.Manifest, repo, output string) error {
5757
for _, layer := range manifest.Layers {
5858
// pull the blob from the storage.

pkg/backend/processor/license.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"os"
2222

2323
"github.com/CloudNativeAI/modctl/pkg/backend/build"
24-
modelspec "github.com/CloudNativeAI/model-spec/specs-go/v1"
2524
"github.com/CloudNativeAI/modctl/pkg/storage"
25+
modelspec "github.com/CloudNativeAI/model-spec/specs-go/v1"
2626

2727
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2828
)
@@ -46,7 +46,7 @@ func (p *licenseProcessor) Identify(_ context.Context, path string, info os.File
4646
func (p *licenseProcessor) Process(ctx context.Context, store storage.Storage, repo, path, workDir string) (ocispec.Descriptor, error) {
4747
desc, err := build.BuildLayer(ctx, store, repo, path, workDir)
4848
if err != nil {
49-
return ocispec.Descriptor{}, nil
49+
return ocispec.Descriptor{}, err
5050
}
5151

5252
// add license annotations.

pkg/backend/processor/model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"regexp"
2323

2424
"github.com/CloudNativeAI/modctl/pkg/backend/build"
25-
modelspec "github.com/CloudNativeAI/model-spec/specs-go/v1"
2625
"github.com/CloudNativeAI/modctl/pkg/storage"
26+
modelspec "github.com/CloudNativeAI/model-spec/specs-go/v1"
2727

2828
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2929
)
@@ -58,7 +58,7 @@ func (p *modelProcessor) Identify(_ context.Context, path string, info os.FileIn
5858
func (p *modelProcessor) Process(ctx context.Context, store storage.Storage, repo, path, workDir string) (ocispec.Descriptor, error) {
5959
desc, err := build.BuildLayer(ctx, store, repo, path, workDir)
6060
if err != nil {
61-
return ocispec.Descriptor{}, nil
61+
return ocispec.Descriptor{}, err
6262
}
6363

6464
// add model annotations.

pkg/backend/processor/model_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"regexp"
2323

2424
"github.com/CloudNativeAI/modctl/pkg/backend/build"
25-
modelspec "github.com/CloudNativeAI/model-spec/specs-go/v1"
2625
"github.com/CloudNativeAI/modctl/pkg/storage"
26+
modelspec "github.com/CloudNativeAI/model-spec/specs-go/v1"
2727

2828
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2929
)
@@ -58,7 +58,7 @@ func (p *modelConfigProcessor) Identify(_ context.Context, path string, info os.
5858
func (p *modelConfigProcessor) Process(ctx context.Context, store storage.Storage, repo, path, workDir string) (ocispec.Descriptor, error) {
5959
desc, err := build.BuildLayer(ctx, store, repo, path, workDir)
6060
if err != nil {
61-
return ocispec.Descriptor{}, nil
61+
return ocispec.Descriptor{}, err
6262
}
6363

6464
// add config annotations.

pkg/backend/processor/readme.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
"os"
2222

2323
"github.com/CloudNativeAI/modctl/pkg/backend/build"
24-
modelspec "github.com/CloudNativeAI/model-spec/specs-go/v1"
2524
"github.com/CloudNativeAI/modctl/pkg/storage"
25+
modelspec "github.com/CloudNativeAI/model-spec/specs-go/v1"
2626

2727
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2828
)
@@ -46,7 +46,7 @@ func (p *readmeProcessor) Identify(_ context.Context, path string, info os.FileI
4646
func (p *readmeProcessor) Process(ctx context.Context, store storage.Storage, repo, path, workDir string) (ocispec.Descriptor, error) {
4747
desc, err := build.BuildLayer(ctx, store, repo, path, workDir)
4848
if err != nil {
49-
return ocispec.Descriptor{}, nil
49+
return ocispec.Descriptor{}, err
5050
}
5151

5252
// add readme annotations.

pkg/storage/distribution/distribution.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"crypto/sha256"
2222
"fmt"
2323
"io"
24+
"regexp"
2425

2526
distribution "github.com/distribution/distribution/v3"
2627
registry "github.com/distribution/distribution/v3/registry/storage"
@@ -31,6 +32,14 @@ import (
3132
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3233
)
3334

35+
func init() {
36+
// The PathRegexp in the distribution package is used to validate the repository name,
37+
// which not cover the case of the repository name includes the :port, so mutate the regexp to support it.
38+
// original regexp: ^(/[A-Za-z0-9._-]+)+$
39+
// new regexp: ^(/[A-Za-z0-9._:-]+)+$
40+
driver.PathRegexp = regexp.MustCompile(`^(/[A-Za-z0-9._:-]+)+$`)
41+
}
42+
3443
const (
3544
// StorageTypeDistribution is the storage type of distribution.
3645
StorageTypeDistribution = "distribution"

0 commit comments

Comments
 (0)