Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generating Docker with Gradle, the easy and ugly way....
buildscript {
repositories {
mavenLocal()
mavenCentral()
repositories { jcenter() }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
ext {
keycloakVersion = '3.2.1.Final'
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
configurations { providedRuntime }
jar { baseName = 'byoskill-backend' }
dependencies {
compile project(":byos-backend:byos-backend-cqrs")
compile project(":byos-backend:byos-backend-domain-commons")
compile project(":byos-backend:byos-backend-jobs")
compile project(":byos-backend:byos-backend-users")
compile project(":byos-backend:byos-backend-utils")
compile "commons-io:commons-io:$APACHE_COMMONIO"
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
task dockerLogin(type:Exec) {
workingDir '.'
//on windows:
commandLine 'docker', '-privileged', 'login', "-u", dockerUser, "-p" , dockerPassword
}
// docker login
// ./gradlew buildDocker -Ppush
task buildDocker(type: Exec, dependsOn: [build, dockerLogin]) {
workingDir '.'
//on windows:
commandLine 'docker', 'build', "--build-arg", "BUILD_VERSION=$version", "-t", "$dockerRepository:$version", "."
}
task gcloudTag( dependsOn: [buildDocker]) {
doLast {
exec {
workingDir '.'
commandLine 'docker', 'tag', "$dockerRepository:$version", "$cloudDockerRepository:$version"
}
exec {
workingDir '.'
commandLine 'docker', 'tag', "$dockerRepository:$version", "$cloudDockerRepository:latest"
}
}
}
task dockerTag( dependsOn: [buildDocker]) {
doLast {
exec {
workingDir '.'
commandLine 'docker', 'tag', "$dockerRepository:$version", "$dockerRepository:latest"
}
}
}
task dockerPush( dependsOn: [dockerTag]) {
doLast {
exec {
workingDir '.'
commandLine 'docker', 'push', "$dockerRepository:$version"
}
exec {
workingDir '.'
commandLine 'docker', 'push', "$dockerRepository:latest"
}
}
}
task gcloudPush( dependsOn: [gcloudTag]) {
doLast {
exec {
workingDir '.'
commandLine 'gcloud','docker','--', 'push', "$cloudDockerRepository:$version"
}
exec {
workingDir '.'
commandLine 'gcloud','docker','--', 'push', "$cloudDockerRepository:latest"
}
}
}
dependencyManagement {
imports {
mavenBom "org.keycloak.bom:keycloak-adapter-bom:${keycloakVersion}"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.