Skip to content

Commit

Permalink
✨ adds USER declaritive to Dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Ford <[email protected]>
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
scottford-io authored and afiune committed May 7, 2024
1 parent 8e61400 commit 0dbbb99
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions providers/os/resources/docker_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (p *mqlDockerFile) stage2resource(stage instructions.Stage) (*mqlDockerFile
var unsupported []string
var entrypointRaw *instructions.EntrypointCommand
var cmdRaw *instructions.CmdCommand
var userRaw *instructions.UserCommand
for i := range stage.Commands {
switch v := stage.Commands[i].(type) {
case *instructions.EnvCommand:
Expand All @@ -188,6 +189,9 @@ func (p *mqlDockerFile) stage2resource(stage instructions.Stage) (*mqlDockerFile
for _, kv := range v.Labels {
labels[kv.Key] = kv.Value
}
case *instructions.UserCommand:
userRaw = v

case *instructions.RunCommand:
script := strings.Join(v.ShellDependantCmdLine.CmdLine, "\n")
runResource, err := CreateResource(p.MqlRuntime, "docker.file.run", map[string]*llx.RawData{
Expand Down Expand Up @@ -312,6 +316,30 @@ func (p *mqlDockerFile) stage2resource(stage instructions.Stage) (*mqlDockerFile
args["cmd"] = llx.NilData
}

if userRaw != nil {
arr := strings.Split(userRaw.User, ":")
var user string
var group string
if len(arr) != 0 && arr[0] != "" {
user = arr[0]
}

if len(arr) > 1 && arr[1] != "" {
group = arr[1]
}
userResource, err := CreateResource(p.MqlRuntime, "docker.file.user", map[string]*llx.RawData{
"__id": llx.StringData(p.locationID(userRaw.Location())),
"user": llx.StringData(user),
"group": llx.StringData(group),
})
if err != nil {
return nil, err
}
args["user"] = llx.ResourceData(userResource, "docker.file.user")
} else {
args["user"] = llx.NilData
}

rawStage, err := CreateResource(p.MqlRuntime, "docker.file.stage", args)
if err != nil {
return nil, err
Expand Down

0 comments on commit 0dbbb99

Please sign in to comment.