Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the ability to set a target build stage to a Dockerfile (#4810)
Co-authored-by: Eddú Meléndez <eddu.melendez@gmail.com>
- Loading branch information
1 parent
13e4293
commit 66bcd39
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
core/src/test/java/org/testcontainers/containers/MultiStageBuildTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.testcontainers.containers; | ||
|
||
import org.junit.Test; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Paths; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class MultiStageBuildTest { | ||
|
||
@Test | ||
public void testDockerMultistageBuild() throws IOException, InterruptedException { | ||
try ( | ||
GenericContainer<?> container = new GenericContainer<>( | ||
new ImageFromDockerfile() | ||
.withDockerfile(Paths.get("src/test/resources/Dockerfile-multistage")) | ||
.withTarget("builder") | ||
) | ||
.withCommand("/bin/sh", "-c", "sleep 10") | ||
) { | ||
container.start(); | ||
assertThat(container.execInContainer("pwd").getStdout()).contains("/my-files"); | ||
assertThat(container.execInContainer("ls").getStdout()).contains("hello.txt"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM alpine:3.14 AS builder | ||
|
||
WORKDIR /my-files | ||
|
||
RUN echo 'Hello World' > hello.txt | ||
|
||
FROM alpine:3.14 | ||
|
||
COPY --from=builder /my-files/hello.txt hello.txt |