Skip to content

Commit

Permalink
Strip multi-stage names from tags (#2)
Browse files Browse the repository at this point in the history
* Strip multi-stage names from tags

https://docs.docker.com/build/building/multi-stage/

* Drop explicit dependency
  • Loading branch information
timtebeek authored Jul 15, 2024
1 parent 052ea3c commit b69bd42
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/openrewrite/docker/trait/Dockerfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public List<DockerImageVersion> getFroms() {
String[] imageVersionStr = line.substring("FROM".length()).trim().split(":");
froms.add(new DockerImageVersion(
imageVersionStr[0],
imageVersionStr.length > 1 ? imageVersionStr[1] : null
imageVersionStr.length > 1 ? imageVersionStr[1].split(" ")[0] : null
));
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/openrewrite/docker/FindDockerImagesUsedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.docker.search.FindDockerImageUses;
import org.openrewrite.docker.table.DockerBaseImages;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.test.SourceSpecs.text;

class FindDockerImagesUsedTest implements RewriteTest {
Expand Down Expand Up @@ -52,4 +54,28 @@ void dockerfile() {
)
);
}

@Test
void multistageDockerfile() {
rewriteRun(
spec -> spec.dataTable(DockerBaseImages.Row.class, rows -> assertThat(rows)
.containsOnly(new DockerBaseImages.Row("nvidia/cuda", "11.8.0-cudnn8-devel-ubuntu20.04"))),
text(
//language=Dockerfile
"""
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04 AS base
LABEL maintainer="Hugging Face"
ARG DEBIAN_FRONTEND=noninteractive
SHELL ["sh", "-lc"]
""",
"""
~~(nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04)~~>FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu20.04 AS base
LABEL maintainer="Hugging Face"
ARG DEBIAN_FRONTEND=noninteractive
SHELL ["sh", "-lc"]
""",
spec -> spec.path("Dockerfile")
)
);
}
}

0 comments on commit b69bd42

Please sign in to comment.