Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use docker image hash to determine if build should rerun #3124

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions contrib/docker/src/mill/contrib/docker/DockerModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ trait DockerModule { outer: JavaModule =>
*/
def executable: T[String] = "docker"

private def baseImageCacheBuster: T[(Boolean, Double)] = T.input {
val pull = pullBaseImage()
if (pull) (pull, Math.random()) else (pull, 0d)
}

def dockerfile: T[String] = T {
val jarName = assembly().path.last
val labelRhs = labels()
Expand Down Expand Up @@ -133,6 +128,18 @@ trait DockerModule { outer: JavaModule =>
|ENTRYPOINT [$quotedEntryPointArgs]""".stripMargin
}

private def pullAndHash = T.input {
def imageHash() =
os.proc(executable(), "images", "--no-trunc", "--quiet", baseImage())
.call(stderr = os.Inherit).out.text().trim

if (pullBaseImage() || imageHash().isEmpty)
os.proc(executable(), "image", "pull", baseImage())
.call(stdout = os.Inherit, stderr = os.Inherit)

(pullBaseImage(), imageHash())
}

final def build = T {
val dest = T.dest

Expand All @@ -145,7 +152,7 @@ trait DockerModule { outer: JavaModule =>

val tagArgs = tags().flatMap(t => List("-t", t))

val (pull, _) = baseImageCacheBuster()
val (pull, _) = pullAndHash()
val pullLatestBase = IterableShellable(if (pull) Some("--pull") else None)

val result = os
Expand Down