summaryrefslogtreecommitdiff
path: root/crashboxd/src/test/scala/io/crashbox/ci/DockerUtil.scala
blob: 969245f1de05ca5548352ccdada33c014b7a844d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package io.crashbox.ci

import IOUtil._

object DockerUtil {
  import com.spotify.docker.client.DockerClient
  import java.io.File
  import java.nio.file.Files

  val defaultImage = "crashbox"

  def ensureImage(client: DockerClient): Unit = {
    println("Pulling base docker image for running docker tests")
    val baseImage = "debian:jessie-backports"
    client.pull(baseImage)

    withTempDir { dir =>
      println("Adapting base image for tests")
      val modifications = s"""|FROM $baseImage
                              |RUN adduser crashbox
                              |USER crashbox
                              |""".stripMargin
      Files.write((new File(dir, "Dockerfile")).toPath, modifications.getBytes)
      client.build(dir.toPath, defaultImage)
    }
  }

}