Skip to content

Commit 6ec8aba

Browse files
ETCHKILIneko-kai
andauthored
distage-framework-docker: Add platform to pull command, will fix #2345 (#2346)
* distage-framework-docker: Add platform to pull command * test: Add test * Remove whitebox test (doesn't actually test anything) * Add integration test that verifies image pull with correct platform actually happens * formatting * deduplicate --------- Co-authored-by: Kai <450507+neko-kai@users.noreply.github.com>
1 parent e742811 commit 6ec8aba

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

distage/distage-framework-docker/src/main/scala/izumi/distage/docker/impl/ContainerResource.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ open class ContainerResource[F[_], Tag](
423423
val pullCmd = Value(rawClient.pullImageCmd(imageName))
424424
.mut(registry)(_.withRegistry(_))
425425
.mut(registryAuth)(_.withAuthConfig(_))
426+
.mut(config.platform)(_.withPlatform(_))
426427
.get
427428
pullCmd.start().awaitCompletion(config.pullTimeout.toMillis, TimeUnit.MILLISECONDS)
428429
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package izumi.distage.testkit.docker
2+
3+
import com.github.dockerjava.api.exception.NotFoundException
4+
import distage.{DefaultModule2, ModuleDef, TagKK}
5+
import izumi.distage.docker.ContainerDef
6+
import izumi.distage.docker.healthcheck.ContainerHealthCheck
7+
import izumi.distage.docker.impl.{ContainerResource, DockerClientWrapper}
8+
import izumi.distage.docker.model.Docker.DockerReusePolicy
9+
import izumi.distage.testkit.docker.DockerPullWithPlatformTest.{HelloWorldRiscV64Docker, imageName}
10+
import izumi.distage.testkit.model.TestConfig
11+
import izumi.distage.testkit.scalatest.Spec2
12+
import izumi.functional.bio.{F, IO2}
13+
import org.scalatest.Assertion
14+
15+
final class DockerPullWithPlatformTestZIO extends DockerPullWithPlatformTest[zio.IO]
16+
17+
object DockerPullWithPlatformTest {
18+
val imageName = "library/hello-world:latest"
19+
20+
object HelloWorldRiscV64Docker extends ContainerDef {
21+
override def config: Config = {
22+
Config(
23+
image = imageName,
24+
ports = Seq.empty,
25+
autoRemove = false,
26+
reuse = DockerReusePolicy.ReuseDisabled,
27+
// succeed: we only care about the image pull, not the container's runtime behavior;
28+
// the riscv64 binary won't execute on a non-riscv64 host anyway
29+
healthCheck = ContainerHealthCheck.succeed,
30+
platform = Some("linux/riscv64"),
31+
)
32+
}
33+
}
34+
}
35+
36+
abstract class DockerPullWithPlatformTest[F[+_, +_]: DefaultModule2: TagKK: IO2] extends Spec2[F] {
37+
38+
override protected def config: TestConfig = super.config.copy(
39+
moduleOverrides = new ModuleDef {
40+
make[ContainerResource[F[Throwable, _], HelloWorldRiscV64Docker.Tag]]
41+
.from(HelloWorldRiscV64Docker.make[F[Throwable, _]])
42+
}
43+
)
44+
45+
"Platform-specific image pull" should {
46+
47+
"pull hello-world for linux/riscv64 and verify image architecture" in {
48+
(client: DockerClientWrapper[F[Throwable, _]], containerResource: ContainerResource[F[Throwable, _], HelloWorldRiscV64Docker.Tag]) =>
49+
def removeImage(): F[Nothing, Unit] = {
50+
F.syncThrowable(client.rawClient.removeImageCmd(imageName).withForce(true).exec()).void.catchAll(_ => F.unit)
51+
}
52+
53+
def verifyImageNotPulled: F[Throwable, NotFoundException] = {
54+
F.syncThrowable {
55+
intercept[NotFoundException](client.rawClient.inspectImageCmd(imageName).exec())
56+
}
57+
}
58+
59+
def verifyImagePulled: F[Throwable, Assertion] = {
60+
F.syncThrowable {
61+
val inspection = client.rawClient.inspectImageCmd(imageName).exec()
62+
assert(inspection.getArch == "riscv64")
63+
assert(inspection.getOs == "linux")
64+
}
65+
}
66+
67+
(for {
68+
_ <- removeImage()
69+
_ <- verifyImageNotPulled
70+
_ <- containerResource.use(_ => verifyImagePulled)
71+
} yield ()).guarantee(removeImage())
72+
}
73+
74+
}
75+
76+
}

0 commit comments

Comments
 (0)