Skip to content

Instantly share code, notes, and snippets.

@cvicens
Created July 1, 2019 12:52
Show Gist options
  • Save cvicens/bd3771b0907be50bb0adb558b21ceaec to your computer and use it in GitHub Desktop.
Save cvicens/bd3771b0907be50bb0adb558b21ceaec to your computer and use it in GitHub Desktop.
Gradle with a task like fabric8:deploy... sort of...
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
plugins {
id "java"
id "io.spring.dependency-management" version "1.0.1.RELEASE"
id 'org.springframework.boot' version '1.5.2.RELEASE'
id "eclipse"
id "name.remal.maven-publish-nexus-staging" version "1.0.93"
id "org.sonarqube" version "2.6.2"
}
sonarqube {
properties {
property 'sonar.projectName', 'Inventory Service Gradle SonarQube Scanner'
}
}
group = 'com.redhat.cloudnative'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven {
url "http://nexus.lab-infra.svc.cluster.local:8081/repository/maven-all-public"
}
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Camden.SR2"
}
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-data-jpa')
implementation('org.springframework.boot:spring-boot-starter-web')
runtimeOnly('com.h2database:h2')
runtimeOnly('org.postgresql:postgresql')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
task getVersion {
doLast {
println rootProject.name + '-' + version
}
}
task project(type:Exec) {
group 'openshift'
description 'Gets current project'
try {
executable "sh"
args "-c", "oc project"
} catch(Exception e) {
println e.getMessage()
}
doLast {
println 'Execution was ' + (execResult.getExitValue() == 0 ? 'successfull!' : 'a failure!')
}
}
task newProject(type:Exec) {
group 'openshift'
description 'Creates a project'
ignoreExitValue true
try {
executable "sh"
args "-c", "oc new-project cva-tests"
} catch(Exception e) {
println e.getMessage()
}
doLast {
println 'Execution was ' + (execResult.getExitValue() == 0 ? 'successfull!' : 'a failure!')
}
}
task newBuild(type:Exec) {
group 'openshift'
description 'Creates a new binary Java build'
ignoreExitValue true
try {
executable "sh"
args "-c", "oc new-build --name=${rootProject.name} ${s2iImage} --binary=true"
} catch(Exception e) {
println e.getMessage()
}
doLast {
println 'Execution was ' + (execResult.getExitValue() == 0 ? 'successfull!' : 'a failure!')
}
}
task startBuild(type:Exec) {
group 'openshift'
description 'Starts a new binary Java build'
ignoreExitValue true
try {
executable "sh"
args "-c", "oc start-build ${rootProject.name} --from-file=./build/libs/${rootProject.name}-${version}.jar --follow"
} catch(Exception e) {
println e.getMessage()
}
doLast {
println 'Execution was ' + (execResult.getExitValue() == 0 ? 'successfull!' : 'a failure!')
}
}
task newApp(type:Exec) {
group 'openshift'
description 'Creates a app from an image stream'
ignoreExitValue true
try {
executable "sh"
args "-c", "oc new-app ${rootProject.name}:latest"
} catch(Exception e) {
println e.getMessage()
}
doLast {
println 'Execution was ' + (execResult.getExitValue() == 0 ? 'successfull!' : 'a failure!')
}
}
task exposeApp(type:Exec) {
group 'openshift'
description 'Exposes a app from an image stream'
ignoreExitValue true
try {
executable "sh"
args "-c", "oc expose svc ${rootProject.name}"
} catch(Exception e) {
println e.getMessage()
}
doLast {
println 'Execution was ' + (execResult.getExitValue() == 0 ? 'successfull!' : 'a failure!')
}
}
task deploy {
group 'openshift'
description 'Deploys the app to Openshift current project'
dependsOn 'clean'
dependsOn 'build'
dependsOn 'newBuild'
dependsOn 'startBuild'
dependsOn 'newApp'
dependsOn 'exposeApp'
tasks.findByName('build').mustRunAfter 'clean'
tasks.findByName('newBuild').mustRunAfter 'build'
tasks.findByName('startBuild').mustRunAfter 'newBuild'
tasks.findByName('newApp').mustRunAfter 'startBuild'
tasks.findByName('exposeApp').mustRunAfter 'newApp'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment