diff --git a/build.gradle.kts b/build.gradle.kts index fce3a61..077c120 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -85,14 +85,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") + baseImage.set("$dockerRegistry/openjdk:11") ports.set(listOf(8765, 8765)) - images.set(setOf("${rootProject.properties["publishing.docker.registry"]}/${project.name}:${project.version}")) + 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(enforcedPlatform("org.springframework.boot:spring-boot-dependencies:${project.properties["spring-boot.version"]}")) @@ -127,3 +134,16 @@ dependencies { exclude("org.springframework.cloud") } } + +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 "") + ) + } +}