Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/app/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/builder"
"github.com/tensorchord/envd/pkg/docker"
"github.com/tensorchord/envd/pkg/flag"
"github.com/tensorchord/envd/pkg/home"
sshconfig "github.com/tensorchord/envd/pkg/ssh/config"
Expand Down Expand Up @@ -101,6 +102,10 @@ func build(clicontext *cli.Context) error {
logrus.Debug("tag not specified, using default")
tag = fmt.Sprintf("%s:%s", fileutil.Base(buildContext), "dev")
}
tag, err = docker.NormalizeNamed(tag)
if err != nil {
return err
}

logger := logrus.WithFields(logrus.Fields{
"build-context": buildContext,
Expand Down
5 changes: 5 additions & 0 deletions pkg/app/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ func up(clicontext *cli.Context) error {
logrus.Debug("tag not specified, using default")
tag = fmt.Sprintf("%s:%s", fileutil.Base(buildContext), "dev")
}
// The current container engine is only Docker. It should be expaned to support other container engines.
tag, err = docker.NormalizeNamed(tag)
if err != nil {
return err
}
ctr := fileutil.Base(buildContext)

detach := clicontext.Bool("detach")
Expand Down
29 changes: 28 additions & 1 deletion pkg/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
Expand All @@ -46,7 +47,8 @@ const (
)

var (
interval = 1 * time.Second
interval = 1 * time.Second
anchoredIdentifierRegexp = regexp.MustCompile(`^([a-f0-9]{64})$`)
)

type Client interface {
Expand Down Expand Up @@ -100,6 +102,31 @@ please visit https://docs.docker.com/engine/install/linux-postinstall/ for more
return generalClient{cli}, nil
}

// Normalize the name accord the spec of docker, It may support normalize imagea and container in the future.
func NormalizeNamed(s string) (string, error) {
if ok := anchoredIdentifierRegexp.MatchString(s); ok {
return "", fmt.Errorf("invalid repository name (%s), cannot specify 64-byte hexadecimal strings, please rename it", s)
}
var remoteName string
var tagSep int
if tagSep = strings.IndexRune(s, ':'); tagSep > -1 {
remoteName = s[:tagSep]
} else {
remoteName = s
}
if strings.ToLower(remoteName) != remoteName {
remoteName = strings.ToLower(remoteName)
if tagSep > -1 {
s = remoteName + s[tagSep:]
} else {
s = remoteName
}
logrus.Warnf("The working direcotry's name is not lowercased: %s, the image built will be lowercased to %s", remoteName, s)
}
return s, nil

}

func (c generalClient) GPUEnabled(ctx context.Context) (bool, error) {
info, err := c.GetInfo(ctx)
if err != nil {
Expand Down
27 changes: 27 additions & 0 deletions pkg/docker/docker_suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2022 The envd 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 docker

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestManager(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Docker Suite")
}
42 changes: 42 additions & 0 deletions pkg/docker/docker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 The envd 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 docker

import (
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("docker", func() {
When("given the a lowcase tag", func() {
It("should return the tag identically", func() {
tag := "test:test"
newTag, err := NormalizeNamed(tag)
Expect(err).NotTo(HaveOccurred())
Expect(newTag).To(Equal(tag))
})
})
When("given the a uppercase tag", func() {
It("should return the tag lowcased", func() {
tag := "Test:test"
newTag, err := NormalizeNamed(tag)
Expect(err).NotTo(HaveOccurred())
Expect(newTag).NotTo(Equal(tag))
Expect(newTag).To(Equal(strings.ToLower(tag)))
})
})
})