@@ -578,7 +578,12 @@ object DockerPlugin extends AutoPlugin {
578
578
* @return Dockerfile
579
579
*/
580
580
private [this ] final def generateDockerConfig (commands : Seq [CmdLike ], target : File ): File = {
581
- val dockerContent = makeDockerContent(commands)
581
+ val (labelCommands, remaining) = commands.partition {
582
+ case cmd : Cmd => cmd.cmd.trim.toUpperCase == " LABEL"
583
+ case _ => false
584
+ }
585
+
586
+ val dockerContent = makeDockerContent(remaining ++ labelCommands)
582
587
583
588
val f = target / " Dockerfile"
584
589
IO .write(f, dockerContent)
@@ -658,6 +663,7 @@ object DockerPlugin extends AutoPlugin {
658
663
.map(_ => publishLocalBuildkitLogger(log))
659
664
.getOrElse(publishLocalLogger(log))
660
665
val ret = sys.process.Process (buildCommand, context) ! logger
666
+ val execPruneImg : String => Seq [String ] = label => execCommand ++ s " image prune -f --filter label= $label" .split(" " )
661
667
662
668
if (removeIntermediateImages) {
663
669
val labelKey = " snp-multi-stage-id"
@@ -670,11 +676,13 @@ object DockerPlugin extends AutoPlugin {
670
676
// No matter if the build process succeeded or failed, we try to remove the intermediate images
671
677
case Some (id) =>
672
678
val label = s " ${labelKey}= ${id}"
673
- log.info(s """ Removing intermediate image(s) (labeled " ${label}") """ )
674
- val retImageClean =
675
- sys.process.Process (execCommand ++ s " image prune -f --filter label= ${label}" .split(" " )) ! logger
679
+ val label2 = s " snp-multi-stage=intermediate "
680
+ log.info(s """ Removing intermediate image(s) (labeled " $label" and " $label2") """ )
681
+ val multiStageIdCleanResponse = sys.process.Process (execPruneImg(label)) ! logger
682
+ val multiStageCleanResponse = sys.process.Process (execPruneImg(label2)) ! logger
683
+
676
684
// FYI: "docker image prune" returns 0 (success) no matter if images were removed or not
677
- if (retImageClean != 0 )
685
+ if (multiStageIdCleanResponse != 0 || multiStageCleanResponse != 0 )
678
686
log.error(
679
687
" Something went wrong while removing multi-stage intermediate image(s)"
680
688
) // no exception, just let the user know
0 commit comments