Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate that a docker image referenced in WDL validates.
Validate that if WDL contains a docker reference and it is properly formatted, that the docker image exists. Dealt with both 'official' and 'personal' docker hub images and optional tags. Added integration tests.
- Loading branch information
Showing
10 changed files
with
458 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/scala/org/broadinstitute/dsde/agora/server/webservice/util/DockerHubClient.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.broadinstitute.dsde.agora.server.webservice.util | ||
|
||
import akka.actor.ActorSystem | ||
import spray.client.pipelining._ | ||
import spray.http.HttpResponse | ||
import spray.http.StatusCodes._ | ||
import org.broadinstitute.dsde.agora.server.webservice.util.DockerHubJsonSupport._ | ||
|
||
import scala.concurrent.duration._ | ||
import scala.concurrent.{Await, Future} | ||
|
||
case class DockerImageReference(user: Option[String], repo: String, tag: String) | ||
|
||
case class DockerTagInfo(pk: Int, id: String) | ||
|
||
object DockerHubClient { | ||
case class DockerConnectionException(text: String = "There was a problem connecting to Docker Hub APIs.") extends Exception(text) | ||
|
||
case class DockerImageNotFoundException(dockerImage: DockerImageReference) extends Exception { | ||
override def getMessage: String = { | ||
s"Docker Image for User ${dockerImage.user.getOrElse("'Official'")}/" + s"${dockerImage.repo}" + s":${dockerImage.tag} not found." | ||
} | ||
} | ||
|
||
implicit val actorSystem = ActorSystem("agora") | ||
|
||
import actorSystem.dispatcher | ||
|
||
val timeout = 5.seconds | ||
|
||
def pipeline = sendReceive | ||
|
||
def dcGET(url: String): Future[HttpResponse] = pipeline(Get(url)) | ||
|
||
def doesDockerImageExist(dockerImage: DockerImageReference): Boolean = { | ||
val dockerImageInfo = dcGET(dockerImageTagUrl(dockerImage)) | ||
|
||
val dockerTagExists = dockerImageInfo map { response: HttpResponse => | ||
response.status match { | ||
case OK => unmarshal[List[DockerTagInfo]].apply(response).nonEmpty | ||
case NotFound => throw new DockerImageNotFoundException(dockerImage) | ||
case _ => throw new DockerImageNotFoundException(dockerImage) | ||
} | ||
} | ||
|
||
dockerImageInfo.onFailure { case _ => throw DockerImageNotFoundException(dockerImage) } | ||
val isDockerImageInfoFound = Await.result(dockerTagExists, timeout) | ||
isDockerImageInfoFound | ||
} | ||
|
||
val dockerImageRepositoryBaseUrl = "https://index.docker.io/v1/repositories/" | ||
def dockerImageTagUrl(dockerImage: DockerImageReference) = { | ||
var url = dockerImageRepositoryBaseUrl | ||
if (dockerImage.user.isDefined) { | ||
url += dockerImage.user.get + "/" | ||
} | ||
url += dockerImage.repo + "/tags/" + dockerImage.tag | ||
url | ||
} | ||
|
||
} | ||
|
8 changes: 8 additions & 0 deletions
8
...ain/scala/org/broadinstitute/dsde/agora/server/webservice/util/DockerHubJsonSupport.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.broadinstitute.dsde.agora.server.webservice.util | ||
|
||
import spray.httpx.SprayJsonSupport | ||
import spray.json.DefaultJsonProtocol | ||
|
||
object DockerHubJsonSupport extends DefaultJsonProtocol with SprayJsonSupport { | ||
implicit val DockerTagInfoFormat = jsonFormat2(DockerTagInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 8 additions & 4 deletions
12
src/test/scala/org/broadinstitute/dsde/agora/server/AgoraIntegrationTestSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.