Skip to content

Commit

Permalink
Use aws/codebuild/standard:2.0 from codebuild (#22)
Browse files Browse the repository at this point in the history
See docu for details: https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html
It already has both chrome and firefox, java & .net and all of it

Cons: now we have to add runtime-versions section for the standard2.0 image =\
  • Loading branch information
derwasp authored Jun 3, 2019
1 parent 7e8abcc commit c3bab06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ annotation class SynnefoOptions(
/**
* @return the name of the docker image to run the job on (/aws/codebuild or docker hub or ECR)
*/
val image: String = "albelli/aws-codebuild-docker-images:java-openjdk-8-chromedriver",
val image: String = "aws/codebuild/standard:2.0",

/**
* @return the type of the CodeBuild instance to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,29 @@ internal class AmazonCodeBuildScheduler(private val classLoader: ClassLoader) {
" - 'result-artifacts/**/*'\n" +
" discard-paths: yes"

private val buildSpecTemplateStandard2_0 = "version: 0.2\n" +
"\n" +
"phases:\n" +
" pre_build:\n" +
" commands:\n" +
" - echo Build started on `date`\n" +
" install:\n" +
" runtime-versions:\n" +
" java: openjdk8\n" +
" build:\n" +
" commands:\n" +
" - mkdir result-artifacts\n" +
" - cd result-artifacts\n" +
" - %s\n" +
" - ls\n" +
" post_build:\n" +
" commands:\n" +
" - echo Build completed on `date`\n" +
"artifacts:\n" +
" files:\n" +
" - 'result-artifacts/**/*'\n" +
" discard-paths: yes"

internal data class Job(
val runnerInfos: List<SynnefoRunnerInfo>,
val notifier: RunNotifier
Expand Down Expand Up @@ -296,7 +319,9 @@ internal class AmazonCodeBuildScheduler(private val classLoader: ClassLoader) {
}

private suspend fun startBuild(job: Job, settings: SynnefoProperties, sourceLocation: String, info: SynnefoRunnerInfo): ScheduledJob {
val buildSpec = generateBuildspecForFeature(Paths.get(settings.classPath).fileName.toString(), info.cucumberFeatureLocation, info.runtimeOptions)
val useStandardImage = settings.image.startsWith("aws/codebuild/standard:2.0")

val buildSpec = generateBuildspecForFeature(Paths.get(settings.classPath).fileName.toString(), info.cucumberFeatureLocation, info.runtimeOptions, useStandardImage)

val buildStartRequest = StartBuildRequest.builder()
.projectName(settings.projectName)
Expand Down Expand Up @@ -388,7 +413,7 @@ internal class AmazonCodeBuildScheduler(private val classLoader: ClassLoader) {
s3clientExt.completeMultipartUpload(completeMultipartUploadRequest).await()
}

private fun generateBuildspecForFeature(jar: String, feature: String, runtimeOptions: List<String>): String {
private fun generateBuildspecForFeature(jar: String, feature: String, runtimeOptions: List<String>, useStandardImage: Boolean): String {
val sb = StringBuilder()
sb.appendWithEscaping("java")
sb.appendWithEscaping("-cp")
Expand All @@ -403,7 +428,8 @@ internal class AmazonCodeBuildScheduler(private val classLoader: ClassLoader) {
}
runtimeOptions.forEach { sb.appendWithEscaping(it) }

return String.format(this.buildSpecTemplate, sb.toString())
val image = if (useStandardImage) { this.buildSpecTemplateStandard2_0 } else {this.buildSpecTemplate }
return String.format(image, sb.toString())
}

private fun getSystemProperties(): List<String> {
Expand Down

0 comments on commit c3bab06

Please sign in to comment.