Skip to content

Commit

Permalink
feat: Avoid gid in base image cache (#749)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <cegao@tensorchord.ai>
  • Loading branch information
gaocegege committed Aug 10, 2022
1 parent 2e39182 commit 7625cd2
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 12 deletions.
3 changes: 2 additions & 1 deletion base-images/remote-cache/build-and-push-remote-cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ ROOT_DIR=`dirname $0`

GIT_TAG_VERSION=$(git describe --tags --abbrev=0 | sed -r 's/[v]+//g') # remove v from version
ENVD_VERSION="${ENVD_VERSION:-$GIT_TAG_VERSION}"
DOCKER_HUB_ORG="${DOCKER_HUB_ORG:-tensorchord}"

cd ${ROOT_DIR}

envd build --export-cache type=registry,ref=docker.io/tensorchord/python-cache:envd-v${ENVD_VERSION} --force
envd build --export-cache type=registry,ref=docker.io/${DOCKER_HUB_ORG}/python-cache:envd-v${ENVD_VERSION} --force

cd - > /dev/null
8 changes: 8 additions & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func New() EnvdApp {
Value: "docker.io/moby/buildkit:v0.10.3",
Hidden: true,
},
&cli.StringFlag{
Name: flag.FlagDockerOrganization,
Usage: "docker organization to use",
Value: "tensorchord",
Hidden: true,
},
}

internalApp.Commands = []*cli.Command{
Expand Down Expand Up @@ -111,6 +117,8 @@ func New() EnvdApp {
// TODO(gaocegege): Add a config struct to keep them.
viper.Set(flag.FlagBuildkitdImage, context.String(flag.FlagBuildkitdImage))
viper.Set(flag.FlagDebug, debugEnabled)
viper.Set(flag.FlagDockerOrganization,
context.String(flag.FlagDockerOrganization))
return nil
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/flag/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
package flag

const (
FlagCacheDir = "cache-dir"
FlagBuildkitdImage = "buildkitd-image"
FlagDebug = "debug"
FlagBuildContext = "build-context"
FlagCacheDir = "cache-dir"
FlagBuildkitdImage = "buildkitd-image"
FlagDebug = "debug"
FlagBuildContext = "build-context"
FlagDockerOrganization = "docker-organization"
)
5 changes: 4 additions & 1 deletion pkg/lang/ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import (
"github.com/cockroachdb/errors"
"github.com/moby/buildkit/client/llb"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"

"github.com/tensorchord/envd/pkg/config"
"github.com/tensorchord/envd/pkg/flag"
"github.com/tensorchord/envd/pkg/progress/compileui"
"github.com/tensorchord/envd/pkg/types"
"github.com/tensorchord/envd/pkg/version"
Expand Down Expand Up @@ -144,7 +146,8 @@ func (g Graph) ExposedPorts() (map[string]struct{}, error) {
func (g Graph) DefaultCacheImporter() (*string, error) {
// The base remote cache should work for all languages.
res := fmt.Sprintf(
"type=registry,ref=docker.io/tensorchord/python-cache:envd-%s",
"type=registry,ref=docker.io/%s/python-cache:envd-%s",
viper.GetString(flag.FlagDockerOrganization),
version.GetGitTagFromVersion())
return &res, nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/lang/ir/conda.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ func (g Graph) compileCondaEnvironment(root llb.State) (llb.State, error) {

func (g Graph) installConda(root llb.State) (llb.State, error) {
run := root.AddEnv("CONDA_VERSION", condaVersionDefault).
File(llb.Mkdir("/opt/conda", 0755, llb.WithParents(true),
llb.WithUIDGID(g.uid, g.gid)),
File(llb.Mkdir("/opt/conda", 0755, llb.WithParents(true)),
llb.WithCustomName("[internal] create conda directory")).
Run(llb.Shlex(fmt.Sprintf("bash -c '%s'", installCondaBash)),
llb.WithCustomName("[internal] install conda"))
Expand Down
13 changes: 9 additions & 4 deletions pkg/lang/ir/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cockroachdb/errors"
"github.com/moby/buildkit/client/llb"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"

"github.com/tensorchord/envd/pkg/config"
"github.com/tensorchord/envd/pkg/flag"
Expand Down Expand Up @@ -78,7 +79,8 @@ func (g Graph) compileCopy(root llb.State) llb.State {

func (g *Graph) compileCUDAPackages() llb.State {
root := llb.Image(fmt.Sprintf(
"docker.io/tensorchord/python:3.9-%s-cuda%s-cudnn%s-envd-%s",
"docker.io/%s/python:3.9-%s-cuda%s-cudnn%s-envd-%s",
viper.GetString(flag.FlagDockerOrganization),
g.OS, *g.CUDA, *g.CUDNN, version.GetGitTagFromVersion()))
return root
}
Expand Down Expand Up @@ -127,7 +129,8 @@ func (g *Graph) compileBase() (llb.State, error) {
} else if g.CUDA == nil && g.CUDNN == nil {
switch g.Language.Name {
case "r":
base = llb.Image(fmt.Sprintf("docker.io/tensorchord/r-base:4.2-envd-%s",
base = llb.Image(fmt.Sprintf("docker.io/%s/r-base:4.2-envd-%s",
viper.GetString(flag.FlagDockerOrganization),
version.GetGitTagFromVersion()))
// r-base image already has GID 1000.
// It is a trick, we actually use GID 1000
Expand All @@ -139,11 +142,13 @@ func (g *Graph) compileBase() (llb.State, error) {
}
case "python":
base = llb.Image(fmt.Sprintf(
"docker.io/tensorchord/python:3.9-ubuntu20.04-envd-%s",
"docker.io/%s/python:3.9-ubuntu20.04-envd-%s",
viper.GetString(flag.FlagDockerOrganization),
version.GetGitTagFromVersion()))
case "julia":
base = llb.Image(fmt.Sprintf(
"docker.io/tensorchord/julia:1.8rc1-ubuntu20.04-envd-%s",
"docker.io/%s/julia:1.8rc1-ubuntu20.04-envd-%s",
viper.GetString(flag.FlagDockerOrganization),
version.GetGitTagFromVersion()))
}
} else {
Expand Down

0 comments on commit 7625cd2

Please sign in to comment.