Advertisement
Guest User

Untitled

a guest
Jul 13th, 2020
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 2.91 KB | None | 0 0
  1. jib {
  2.     from {
  3.         // picks up the previously created layer.
  4.         // using tar lets us avoid communicating with docker
  5.         image = "tar://$buildDir/image.tar"
  6.     }
  7.     to {
  8.         image = "finalimage"
  9.     }
  10. }
  11.  
  12. // todo: file bug to make aditional image building easier
  13. val javaBase = tasks.register("javaBase") {
  14.  
  15.     // todo: figure out a better way to handle this instead of having to list out all subdirs
  16.     // had to because it would just copy basetest-linux-x64 the folder instead of its subdirs
  17.     val all = listOf(
  18.        ///Paths.get("$buildDir", "jre/basetest-linux-x64/bin"),
  19.         Paths.get("$buildDir", "jre/basetest-linux-x64/conf"),
  20.         Paths.get("$buildDir", "jre/basetest-linux-x64/legal"),
  21.         Paths.get("$buildDir", "jre/basetest-linux-x64/lib"),
  22.         Paths.get("$buildDir", "jre/basetest-linux-x64/release")
  23.     )
  24.  
  25.     val root = listOf(
  26.         Paths.get("$buildDir", "jre/basetest-linux-x64/")
  27.     )
  28.  
  29.     val bin = listOf(
  30.         Paths.get("$buildDir", "jre/basetest-linux-x64/bin")
  31.     )
  32.  
  33.     doLast {
  34.         val binaries = listOf(AbsoluteUnixPath.get("/usr/lib/jdk-14.0.1/bin/java"), AbsoluteUnixPath.get("/usr/lib/jdk-14.0.1/bin/keytool"))
  35.  
  36.         Jib.from("gcr.io/distroless/java-debian10:base-debug")
  37.             .setCreationTime(Instant.EPOCH) // make layer reproducible
  38.             .addFileEntriesLayer(
  39.                 FileEntriesLayer.builder()
  40.                     // todo: replace this with a recursive addition, checking java permissions on host platform first
  41.                     .apply {
  42.                         val context = AbsoluteUnixPath.get("/usr/lib/jdk-14.0.1")
  43.                         all.forEach {
  44.                             addEntryRecursive(it, context.resolve(it.fileName))
  45.                         }
  46.                     }
  47.                     // dumb, doesn't inherit permissions from files in directory, have to manually specify executable bit
  48.                     .addEntryRecursive(bin.first(), AbsoluteUnixPath.get("/usr/lib/jdk-14.0.1/bin/")) { _, u ->
  49.                         if (u in binaries) {
  50.                             FilePermissions.fromOctalString("755")
  51.                         } else {
  52.                             FilePermissions.fromOctalString("644")
  53.                         }
  54.                     }
  55.                     .build()
  56.             )
  57.             // todo: replace this with a symlink when possible
  58.             // dumb, can't append to pre-existing env variable
  59.             .addEnvironmentVariable("PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/busybox:/usr/lib/jdk-14.0.1/bin")
  60.             .containerize(
  61.                 Containerizer.to(
  62.                     TarImage.at(File(buildDir, "image.tar").toPath()).named("myimage")
  63.                     //DockerDaemonImage.named("myimage")
  64.                 )
  65.             )
  66.     }
  67.     //dependsOn
  68.     //dependsOn(tasks.jre, createSymlink)
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement