Skip to content
Permalink
Browse files
fix(dockerfile): support RUN with --mount from another stage
When the following instruction used:

    RUN --mount=type=bind,from=build,source=/usr/local/test_project/dist,target=/usr/test_project/dist \
    cp -v /usr/test_project/dist/prog.py /usr/local/bin/prog

— change image digest when `from=build` stage digest has changed.

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Jun 1, 2022
1 parent a655a35 commit ebd544a302b66d7210eea69179ac829a7b2abd02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
@@ -18,11 +18,23 @@ func ResolveDockerStagesFromValue(stages []instructions.Stage) {
}

for _, cmd := range s.Commands {
copyCmd, ok := cmd.(*instructions.CopyCommand)
if ok && copyCmd.From != "" {
from := strings.ToLower(copyCmd.From)
if val, ok := nameToIndex[from]; ok {
copyCmd.From = val
switch typedCmd := cmd.(type) {
case *instructions.CopyCommand:
if typedCmd.From != "" {
from := strings.ToLower(typedCmd.From)
if val, ok := nameToIndex[from]; ok {
typedCmd.From = val
}
}

case *instructions.RunCommand:
for _, mount := range instructions.GetMounts(typedCmd) {
if mount.From != "" {
from := strings.ToLower(mount.From)
if val, ok := nameToIndex[from]; ok {
mount.From = val
}
}
}
}
}
@@ -474,12 +474,20 @@ func (s *DockerfileStage) GetDependencies(ctx context.Context, c Conveyor, _ con
}

for _, cmd := range stage.Commands {
copyCmd, ok := cmd.(*instructions.CopyCommand)
if ok && copyCmd.From != "" {
relatedStageIndex, err := strconv.Atoi(copyCmd.From)
switch typedCmd := cmd.(type) {
case *instructions.CopyCommand:
relatedStageIndex, err := strconv.Atoi(typedCmd.From)
if err == nil && relatedStageIndex < len(stagesDependencies) {
stagesDependencies[ind] = append(stagesDependencies[ind], stagesDependencies[relatedStageIndex]...)
}

case *instructions.RunCommand:
for _, mount := range instructions.GetMounts(typedCmd) {
relatedStageIndex, err := strconv.Atoi(mount.From)
if err == nil && relatedStageIndex < len(stagesDependencies) {
stagesDependencies[ind] = append(stagesDependencies[ind], stagesDependencies[relatedStageIndex]...)
}
}
}
}
}

0 comments on commit ebd544a

Please sign in to comment.