-
Notifications
You must be signed in to change notification settings - Fork 3
/
JenkinsAndHarborDeployment.groovy
135 lines (90 loc) · 4 KB
/
JenkinsAndHarborDeployment.groovy
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
package com.eficode.devstack.deployment.impl
import com.eficode.devstack.container.Container
import com.eficode.devstack.container.impl.HarborManagerContainer
import com.eficode.devstack.container.impl.JenkinsContainer
import com.eficode.devstack.deployment.Deployment
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.util.concurrent.Callable
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import java.util.concurrent.Future
class JenkinsAndHarborDeployment implements Deployment {
Logger log = LoggerFactory.getLogger(this.class)
String friendlyName = "Jenkins and Harbor Deployment"
String deploymentNetworkName = "jenkins_and_harbor"
ArrayList<Deployment> subDeployments = []
JenkinsAndHarborDeployment(String jenkinsBaseUrl, String harborBaseUrl, String dockerHost = "", String dockerCertPath = "") {
subDeployments = [
new JenkinsDeployment(jenkinsBaseUrl, dockerHost, dockerCertPath),
new HarborDeployment(harborBaseUrl, "v2.6.1", "/tmp/", dockerHost, dockerCertPath)
]
}
JenkinsDeployment getJenkinsDeployment() {
return subDeployments.find { it instanceof JenkinsDeployment } as JenkinsDeployment
}
JenkinsContainer getJenkinsContainer() {
return jenkinsDeployment.jenkinsContainer
}
HarborDeployment getHarborDeployment() {
return subDeployments.find { it instanceof HarborDeployment } as HarborDeployment
}
HarborManagerContainer getHarborManagerContainer() {
return harborDeployment.managerContainer
}
ArrayList<Container> getContainers() {
return [jenkinsContainer, harborDeployment.harborContainers]
}
void setContainers(ArrayList<Container> containers) {
this.containers = containers
}
private class SetupDeploymentTask implements Callable<Boolean> {
Deployment deployment
SetupDeploymentTask(Deployment deployment) {
this.deployment = deployment
}
@Override
Boolean call() throws Exception {
this.deployment.setupDeployment()
}
}
boolean setupDeployment() {
log.info("Setting up deployment:" + friendlyName)
subDeployments.each { it.deploymentNetworkName = deploymentNetworkName }
jenkinsContainer.createBridgeNetwork(this.deploymentNetworkName)
ExecutorService threadPool = Executors.newFixedThreadPool(2)
Future jenkinsFuture = threadPool.submit(new SetupDeploymentTask(jenkinsDeployment))
Future harborFuture = threadPool.submit(new SetupDeploymentTask(harborDeployment))
threadPool.shutdown()
while (!(jenkinsFuture.done && harborFuture.done)) {
log.info("Waiting for deployments to finish")
log.info("\tJenkins Finished:" + jenkinsFuture.done)
log.info("\tHarbor Finished:" + harborFuture.done)
if (harborFuture.done) {
log.info("\tHarbor deployment finished successfully:" + harborFuture.get())
}
if (jenkinsFuture.done) {
log.info("\tJenkins deployment finished successfully:" + jenkinsFuture.get())
}
sleep(5000)
}
if (harborFuture.done) {
log.info("\tHarbor deployment finished successfully:" + harborFuture.get())
log.info("\t\tHarbor URL:" + harborManagerContainer.harborBaseUrl)
log.info("\t\tHarbor Admin/Pw: admin Harbor12345")
}
if (jenkinsFuture.done) {
log.info("\tJenkins deployment finished successfully:" + jenkinsFuture.get())
log.info("\t\tJenkins URL:" + getJenkinsDeployment().baseUrl)
log.info("\t\tJenkins Admin PW:" + jenkinsContainer.initialAdminPassword)
}
boolean success = (jenkinsFuture.get() && harborFuture.get())
return success
}
@Override
boolean stopAndRemoveDeployment() {
subDeployments.each{
it.stopAndRemoveDeployment()
}
}
}