Skip to content

Commit

Permalink
Fix docker image building (#9)
Browse files Browse the repository at this point in the history
* Fix docker image building

* Enable validation
  • Loading branch information
aryabokon authored Oct 19, 2023
1 parent 70998a1 commit 4af1c5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,21 @@ springBoot {
buildInfo()
}

val dockerRegistry = System.getenv().getOrDefault("DOCKER_REGISTRY", project.properties["docker.registry"]) as? String
val octopusGithubDockerRegistry = System.getenv().getOrDefault("OCTOPUS_GITHUB_DOCKER_REGISTRY", project.properties["octopus.github.docker.registry"]) as? String

docker {
springBootApplication {
baseImage.set("${rootProject.properties["docker.registry"]}/openjdk:11")
ports.set(listOf(8765, 8765))
images.set(setOf("${rootProject.properties["publishing.docker.registry"]}/${project.name}:${project.version}"))
baseImage.set("$dockerRegistry/openjdk:11")
ports.set(listOf(8888, 8888))
images.set(setOf("$octopusGithubDockerRegistry/octopusden/${project.name}:${project.version}"))
}
}

tasks.getByName("dockerBuildImage").doFirst {
validateDockerRegistryParams()
}

dependencies {
implementation(platform("org.springframework.cloud:spring-cloud-dependencies:${project.property("spring-cloud.version")}"))
implementation(platform("org.springframework.boot:spring-boot-dependencies:${project.property("spring-boot.version")}"))
Expand All @@ -93,3 +100,16 @@ dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.micrometer:micrometer-registry-prometheus:1.10.4")
}

fun validateDockerRegistryParams() {
if (dockerRegistry.isNullOrBlank() || octopusGithubDockerRegistry.isNullOrBlank()) {
throw IllegalArgumentException(
"Start gradle build with" +
(if (dockerRegistry.isNullOrBlank()) " -Pdocker.registry=..." else "") +
(if (octopusGithubDockerRegistry.isNullOrBlank()) " -Poctopus.github.docker.registry=..." else "") +
" or set env variable(s):" +
(if (dockerRegistry.isNullOrBlank()) " DOCKER_REGISTRY" else "") +
(if (octopusGithubDockerRegistry.isNullOrBlank()) " OCTOPUS_GITHUB_DOCKER_REGISTRY" else "")
)
}
}
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ kotlin.version=1.6.21
spring-cloud.version=2021.0.0
spring-boot.version=2.6.1
docker.registry=
octopus.github.docker.registry=

0 comments on commit 4af1c5f

Please sign in to comment.