/
build.gradle
140 lines (121 loc) · 4.04 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
plugins {
// https://plugins.gradle.org/plugin/org.springframework.boot
id 'org.springframework.boot' version '2.7.3'
// https://plugins.gradle.org/plugin/io.spring.dependency-management
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
id 'java'
}
group = 'org.fabianlee'
version = '' // bootJar will not have version suffixed
//version = project.getProperty('version')=="unspecified" ? '0.0.2-SNAPSHOT':version
// https://docs.gradle.org/current/userguide/compatibility.html
// OpenJDK17 matches with Gradle 7.4
// gradle wrapper --gradle-version=7.4
sourceCompatibility = '17'
targetCompatibility = '17'
// additional variables
ext.dockerOwner = project.hasProperty('dockerOwner') ? project.getProperty('dockerOwner'):'fabianlee'
ext.dockerVersion = project.hasProperty('dockerVersion') ? project.getProperty('dockerVersion'):'1.0.1'
compileJava {
options.encoding = 'UTF-8'
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile){
options.compilerArgs << "-Xlint:deprecation"
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.projectlombok:lombok' // compileOnly does not allow IDE to use annotations
annotationProcessor 'org.projectlombok:lombok'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
}
tasks.named('test') {
useJUnitPlatform()
}
test {
exclude 'org/fabianlee/**'
}
// makes BuildProperties available from Spring context
springBoot {
buildInfo()
}
// for debug purposes
task defaultProperties {
doFirst {
println "Project: $project"
println "Project directory: $projectDir"
println "Build directory: $buildDir"
println "Version: $version"
println "Group: $project.group"
println "dockerOwner: $project.dockerOwner"
println "Description: $project.description"
println "AntBuilder: $ant"
println "dockerVersion: $dockerVersion"
}
}
// takes templatized Dockerfile, places into buildDir
task prepareDockerfileTemplate(type: Copy) {
group "OCI"
dependsOn "bootJar"
from "src/main/resources/docker"
include "Dockerfile"
filter { it.replaceAll('<%=name%>', project.name) }
into "$buildDir"
}
ext.ownerProject = "${dockerOwner}/${project.name}"
task buildah(type: Exec) {
group "OCI"
dependsOn "prepareDockerfileTemplate"
workingDir "${buildDir}"
doFirst {
println "Executing 'buildah' task"
}
commandLine "buildah", "bud", "-f", "Dockerfile", "-t", project.name, "-t", "${ownerProject}:latest","-t","${ownerProject}:${dockerVersion}","-t","docker.io/${ownerProject}:${dockerVersion}","-t","ghcr.io/${ownerProject}:${dockerVersion}"
}
task buildahPush(type: Exec) {
group "OCI"
dependsOn "buildah"
commandLine "buildah", "push", "docker.io/${dockerOwner}/${project.name}:${dockerVersion}"
}
task podmanCleanup(type: Exec) {
ignoreExitValue true
commandLine "podman", "rm", project.name
}
task podmanRun(type: Exec) {
group "OCI"
// buildah does not cache, so do not force complete rebuild
//dependsOn "buildah"
dependsOn podmanCleanup
commandLine "podman", "run",
"-p", "8081:8081",
"--name", project.name,
"-e", "ADFS=${System.env.ADFS}",
project.name
doLast {
println ""
println "To cleanup, run 'podman rm ${project.name}'"
println ""
}
}
task dockerCleanup(type: Exec) {
ignoreExitValue true
commandLine "docker", "rm", project.name
}
task dockerRun(type: Exec) {
group "OCI"
dependsOn dockerCleanup
commandLine "docker", "run",
"--network", "host",
"-p", "8081:8081",
"--name", project.name,
"-e", "ADFS=${System.env.ADFS}",
"${dockerOwner}/${project.name}:${dockerVersion}"
}