Skip to content

Commit

Permalink
feat: support build owner (#1202)
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <kemingyang@tensorchord.ai>

Signed-off-by: Keming <kemingyang@tensorchord.ai>
  • Loading branch information
kemingy authored Nov 15, 2022
1 parent a91bab6 commit 3fa3070
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,8 @@ jobs:
username: ${{ secrets.DOCKERIO_USERNAME }}
password: ${{ secrets.DOCKERIO_TOKEN }}
- name: Build and push
run: |
sudo -u runneradmin id
sudo usermod -aG docker runneradmin
sudo -u runneradmin bash ./base-images/remote-cache/build-and-push-remote-cache.sh
run: ./base-images/remote-cache/build-and-push-remote-cache.sh
env:
BUILD_FUNC: ${{ matrix.build_func }}
TAG_SUFFIX: ${{ matrix.TAG_SUFFIX }}
ENVD_BUILD_OWNER: 1000
8 changes: 8 additions & 0 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ func New() EnvdApp {
Value: "tensorchord",
Hidden: true,
},
&cli.StringFlag{
Name: flag.FlagBuildOwner,
Usage: "owner (uid:gid) in the built image",
Value: "",
EnvVars: []string{"ENVD_BUILD_OWNER"},
Hidden: true,
},
}

internalApp.Commands = []*cli.Command{
Expand Down Expand Up @@ -139,6 +146,7 @@ func New() EnvdApp {

// TODO(gaocegege): Add a config struct to keep them.
viper.Set(flag.FlagBuildkitdImage, context.String(flag.FlagBuildkitdImage))
viper.Set(flag.FlagBuildOwner, context.String(flag.FlagBuildOwner))
viper.Set(flag.FlagDebug, debugEnabled)
viper.Set(flag.FlagAnalytics, analytics)
viper.Set(flag.FlagDockerOrganization,
Expand Down
1 change: 1 addition & 0 deletions pkg/flag/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package flag
const (
FlagCacheDir = "cache-dir"
FlagBuildkitdImage = "buildkitd-image"
FlagBuildOwner = "owner"
FlagDebug = "debug"
FlagAnalytics = "analytics-enabled"
FlagBuildContext = "build-context"
Expand Down
26 changes: 26 additions & 0 deletions pkg/lang/ir/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ import (
"os/user"
"regexp"
"strconv"
"strings"

"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"

"github.com/tensorchord/envd/pkg/flag"
"github.com/tensorchord/envd/pkg/util/fileutil"
)

Expand Down Expand Up @@ -62,6 +66,28 @@ func parseLanguage(l string) (string, *string, error) {
}

func getUIDGID() (int, int, error) {
owner := viper.GetString(flag.FlagBuildOwner)
if len(owner) > 0 {
logrus.WithField("flag", owner).Info("use owner")
ids := strings.Split(owner, ":")
if len(ids) > 2 {
return 0, 0, errors.Newf("wrong format for owner (uid:gid): %s", owner)
}
uid, err := strconv.Atoi(ids[0])
if err != nil {
logrus.Info(err)
return 0, 0, errors.Wrap(err, "failed to get uid")
}
// if omit gid, will use the uid as gid
if len(ids) == 1 {
return uid, uid, nil
}
gid, err := strconv.Atoi(ids[1])
if err != nil {
return 0, 0, errors.Wrap(err, "failed to get gid")
}
return uid, gid, nil
}
user, err := user.Current()
if err != nil {
return 0, 0, errors.Wrap(err, "failed to get uid/gid")
Expand Down

0 comments on commit 3fa3070

Please sign in to comment.