Skip to content

Instantly share code, notes, and snippets.

@alirezameskin
Created April 10, 2019 12:16
Show Gist options
  • Save alirezameskin/6d18e38df3a62cbd494047a02d645bb5 to your computer and use it in GitHub Desktop.
Save alirezameskin/6d18e38df3a62cbd494047a02d645bb5 to your computer and use it in GitHub Desktop.
def spotifyInterpreter(client: DockerClient): DockerOperation ~> Try = new (DockerOperation ~> Try) {
override def apply[A](fa: DockerOperation[A]): Try[A] = fa match {
case Pull(image: String) => Try {
client.pull(image)
}
case Run(image: String, command@_*) => Try {
val config = ContainerConfig.builder().cmd(command:_*).image(image).build()
val container:ContainerCreation = client.createContainer(config)
client.startContainer(container.id())
container.id()
}
case Exec(containerId, command@_*) => Try {
val params = Seq(ExecCreateParam.tty(true))
val execCreation = client.execCreate(containerId, command.toArray[String], params:_*)
val output: LogStream = client.execStart(execCreation.id)
output.readFully()
}
case Kill(containerId) => Try {
client.killContainer(containerId)
}
case Remove(containerId) => Try {
client.removeContainer(containerId)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment