This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
159 lines (133 loc) · 4.63 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import com.bmuschko.gradle.docker.tasks.image.*
plugins {
id 'base'
id 'com.bmuschko.docker-remote-api' version '4.8.0'
id 'com.openexchange.autosemver.gradle-base' version '0.2.0'
id 'com.openexchange.autosemver.gradle-git' version '0.1.1'
id 'com.openexchange.autosemver.gradle-jira' version '0.1.2'
}
repositories {
maven {
url = uri("https://artifactory.open-xchange.com/artifactory/libs-release")
}
}
//-------------------------------------------------------------------------------------------------
//semver
autoSemVer {
//Read current version from git tags
versionProvider = git.tagVersionProvider
//Determine current git branch from the git module's provide
branchNameProvider = git.branchNameProvider
preReleaseProvider = git.branchNamePreReleaseProvider
//Calculate next version based on the "reelase type" field specified in
//Jira for all found Jira issues in the git history
if(findProperty("jiraLogin")?.trim() &&
findProperty("jiraPassword")?.trim()){
incrementProvider = jira.issueCustomFieldIncrementProvider
jira {
issueKeyProvider = git.commitJiraIssueKeyProvider
url = findProperty("jiraURL")?.toString()
username = findProperty("jiraLogin")?.toString()
password = findProperty("jiraPassword")?.toString()
versionIncrementFieldId = "customfield_12505"
}
}
else {
println("Ignoring JIRA provider: Not able to setup JiraProvider due missing JIRA credentials")
}
//Branches on which the gradle "release" task will operate only
releaseBranches.add("master")
//Tag versions in git when publishing/releasing
versionPublisher.add(git.tagVersionPublisher)
}
//-------------------------------------------------------------------------------------------------
//Docker
//Configuration of the docker plugin
docker {
url = oxDockerUrl
registryCredentials {
url = oxDockerRegistryUrl
username = oxDockerRegistryUsername
password = oxDockerRegistryPassword
}
}
//Gets the docker repository; Which is the configured repostitory or the project name if not configured
def getDockerRepository() {
String repo = oxDockerRegistryUrl
if (repo == null || repo.isEmpty()) {
return "pushservice"
}
return repo.toLowerCase()
}
def getDockerImageID() {
return getDockerRepository() + ":" + this.project.version;
}
def getLatestDockerImageID() {
return getDockerRepository() + ":latest"
}
//Writes the current project version to a version.txt file
//usefull for further processing
def writeVersionFile() {
new File("${buildDir}/version.txt").text = this.project.version;
}
//-------------------------------------------------------------------------------------------------
//TASKS
task version {
group = "help"
description = "Shows the current version of the project"
doLast {
println("Project:\t\t" + this.project.name)
println("Current version:\t" + this.project.version)
}
}
task writeVersion {
group = "build"
description = "writes the project.version to a file for further processing"
doLast {
mkdir 'build'
writeVersionFile()
}
}
assemble.finalizedBy(writeVersion)
//task copyDockerFile(type: Copy) {
// from file("Dockerfile")
// into file("$buildDir")
//}
task buildImage (type: DockerBuildImage) {
description = "Assembles a docker image containing the jar file ready to run."
group = "docker"
dependsOn 'COIPushService:assemble'
dependsOn 'Documentation:docu'
dependsOn writeVersion
inputDir = file('.')
}
project.afterEvaluate {
buildImage{
tags.add(getDockerImageID())
tags.add(getLatestDockerImageID())
}
}
task pushImage (type: DockerPushImage) {
group = "docker"
description = "pushes the docker image to a given docker registry"
dependsOn buildImage
}
project.afterEvaluate {
pushImage{
imageName = getDockerRepository()
if(!imageName){
throw new GradleException('Could not determine docker project name or repository name: imageName is null')
}
if (!project.hasProperty('version') || project.version == "unspecified"){
throw new GradleException('Could not determine docker image tag. Property \"project.version\" is undefined.')
}
tag = this.project.version
}
}
task pushImageAsLatest (type: DockerPushImage) {
group = "docker"
description = "pushes the docker image to a given docker registry while using the 'latest' tag"
dependsOn buildImage
imageName = getDockerRepository()
tag = 'latest'
}