Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
245 lines (189 sloc) 6.18 KB
buildscript {
ext.cubaVersion = '6.9.5'
repositories {
maven {
url 'https://repo.cuba-platform.com/content/groups/work'
credentials {
username(rootProject.hasProperty('repoUser') ? rootProject['repoUser'] : 'cuba')
password(rootProject.hasProperty('repoPass') ? rootProject['repoPass'] : 'cuba123')
}
}
}
dependencies {
classpath "com.haulmont.gradle:cuba-plugin:$cubaVersion"
classpath 'com.bmuschko:gradle-docker-plugin:3.2.5'
}
}
import com.bmuschko.gradle.docker.tasks.image.Dockerfile
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage
import com.bmuschko.gradle.docker.tasks.image.DockerPushImage
import com.bmuschko.gradle.docker.DockerRegistryCredentials
def modulePrefix = 'cubarnetes'
def globalModule = project(":${modulePrefix}-global")
def coreModule = project(":${modulePrefix}-core")
def webModule = project(":${modulePrefix}-web")
def servletApi = 'javax.servlet:javax.servlet-api:3.1.0'
apply(plugin: 'idea')
apply(plugin: 'cuba')
apply plugin: 'com.bmuschko.docker-remote-api'
cuba {
artifact {
group = 'com.roadtocubaandbeyond.cubarnetes'
version = "0.1.0"
isSnapshot = true
}
tomcat {
dir = "$project.rootDir/deploy/tomcat"
}
ide {
vcs = 'Git'
}
}
dependencies {
appComponent("com.haulmont.cuba:cuba-global:$cubaVersion")
}
def postgres = 'org.postgresql:postgresql:9.4.1212'
configure([globalModule, coreModule, webModule]) {
apply(plugin: 'java')
apply(plugin: 'maven')
apply(plugin: 'idea')
apply(plugin: 'cuba')
dependencies {
testCompile('junit:junit:4.12')
}
task sourceJar(type: Jar) {
from file('src')
classifier = 'sources'
}
artifacts {
archives sourceJar
}
}
configure([globalModule, coreModule, webModule]) {
apply(plugin: 'groovy')
sourceSets {
main { groovy { srcDirs = ["src"] } }
test { groovy { srcDirs = ["test"] } }
}
}
configure(globalModule) {
task enhance(type: CubaEnhancing)
}
configure(coreModule) {
configurations {
jdbc
dbscripts
}
dependencies {
compile(globalModule)
provided(servletApi)
jdbc(postgres)
testRuntime(postgres)
}
task cleanConf(description: 'Cleans up conf directory') {
doLast {
def dir = new File(cuba.tomcat.dir, "/conf/${modulePrefix}-core")
if (dir.isDirectory()) {
ant.delete(includeemptydirs: true) {
fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
}
}
}
}
task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
appName = "${modulePrefix}-core"
appJars(modulePrefix + '-global', modulePrefix + '-core')
}
task createDb(dependsOn: assembleDbScripts, description: 'Creates local database', type: CubaDbCreation) {
dbms = 'postgres'
host = 'localhost'
dbName = 'cubarnetes'
dbUser = 'postgres'
dbPassword = 'postgres'
}
task updateDb(dependsOn: assembleDbScripts, description: 'Updates local database', type: CubaDbUpdate) {
dbms = 'postgres'
host = 'localhost'
dbName = 'cubarnetes'
dbUser = 'postgres'
dbPassword = 'postgres'
}
}
configure(webModule) {
configurations {
webcontent
}
dependencies {
provided(servletApi)
compile(globalModule)
}
task webArchive(type: Zip) {
from file("$buildDir/web")
from file('web')
classifier = 'web'
}
artifacts {
archives webArchive
}
task deployConf(type: Copy) {
from file('src')
include "com/roadtocubaandbeyond/cubarnetes/**"
into "$cuba.tomcat.dir/conf/${modulePrefix}"
}
task clearMessagesCache(type: CubaClearMessagesCache) {
appName = "${modulePrefix}"
}
deployConf.dependsOn clearMessagesCache
task cleanConf(description: 'Cleans up conf directory') {
doLast {
def dir = new File(cuba.tomcat.dir, "/conf/${modulePrefix}")
if (dir.isDirectory()) {
ant.delete(includeemptydirs: true) {
fileset(dir: dir, includes: '**/*', excludes: 'local.app.properties')
}
}
}
}
task deploy(dependsOn: [assemble, cleanConf], type: CubaDeployment) {
appName = "${modulePrefix}"
appJars(modulePrefix + '-global', modulePrefix + '-web')
}
}
task undeploy(type: Delete, dependsOn: ":${modulePrefix}-web:cleanConf") {
delete("$cuba.tomcat.dir/shared")
delete("$cuba.tomcat.dir/webapps/${modulePrefix}-core")
delete("$cuba.tomcat.dir/webapps/${modulePrefix}")
}
task restart(dependsOn: ['stop', ":${modulePrefix}-core:deploy", ":${modulePrefix}-web:deploy"], description: 'Redeploys applications and restarts local Tomcat') {
doLast {
ant.waitfor(maxwait: 6, maxwaitunit: 'second', checkevery: 2, checkeveryunit: 'second') {
not {
socket(server: 'localhost', port: '8787')
}
}
start.execute()
}
}
task wrapper(type: Wrapper) {
gradleVersion = '4.3.1'
}
task buildUberJar(type: CubaUberJarBuilding) {
singleJar = true
logbackConfigurationFile = 'etc/uber-jar-logback.xml'
coreJettyEnvPath = 'modules/core/web/META-INF/jetty-env.xml'
appProperties = ['cuba.automaticDatabaseUpdate' : true]
}
task createDockerfile(type: Dockerfile, dependsOn: buildUberJar) {
destFile = project.file('build/distributions/uberJar/Dockerfile')
from 'openjdk:8-alpine'
addFile("cubarnetes.jar", "/usr/src/cuba/app.jar")
defaultCommand("java", "-Dapp.home=/usr/src/cuba/home", "-jar", "/usr/src/cuba/app.jar")
}
task buildImage(type: DockerBuildImage, dependsOn: createDockerfile) {
inputDir = createDockerfile.destFile.parentFile
tags = ['cubarnetes', 'gcr.io/cuba-on-kubernetes/cubarnetes']
}
task pushImage(type: DockerPushImage, dependsOn: buildImage) {
tag = 'latest'
imageName = 'gcr.io/cuba-on-kubernetes/cubarnetes'
}