forked from jelastic-jps/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanifest.jps
130 lines (116 loc) · 4.96 KB
/
manifest.jps
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
type: install
id: jenkins
baseUrl: https://raw.githubusercontent.com/SiryjVyiko/jenkins/master
logo: /images/jenkins.png
name: Jenkins DevOps Pack
categories:
- apps/dev-tools
- apps/popular
- apps/dev-and-admin-tools
homepage: https://jenkins.io/
description: /text/description.md
globals:
user: jelastic${fn.random(1000)}
password: ${fn.password}
tomcat: 9.0.12-jdk-10.0.2
javaengine: jdk-10.0.2
jenkins: latest
nodes:
- cloudlets: 8
nodeType: tomcat
displayName: Master
tag: ${globals.tomcat}
- cloudlets: 8
nodeType: javaengine
nodeGroup: slaves
displayName: Workers
tag: ${globals.javaengine}
count: ${settings.nodes}
scalingMode: stateless
diskLimit: 20G
settings:
fields:
- type: spinner
name: nodes
caption: Workers
min: 1
max: 10
default: 2
skipNodeEmails: true
onBeforeInit: return {result:0, ssl:!!jelastic.billing.account.GetQuotas('environment.jelasticssl.enabled').array[0].value}
onInstall:
- prepareMaster
- deploy:
name: jenkins-${globals.jenkins}.war
context: ROOT
archive: http://mirrors.jenkins-ci.org/war-stable/${globals.jenkins}/jenkins.war
- setupMaster
- readPublicKeyFromMaster
- forEach(nodes.slaves):
initSlave:
publicKey: ${response.body}
slaveNodeId: ${@i.id}
slaveNodeIp: ${@i.intIP}
onAfterScaleOut[slaves]:
- readPublicKeyFromMaster
- forEach(event.response.nodes):
initSlave:
publicKey: ${response.body}
slaveNodeId: ${@i.id}
slaveNodeIp: ${@i.intIP}
onBeforeScaleIn[slaves]:
forEach(event.response.nodes):
removeSlave:
slaveNodeId: ${@i.id}
actions:
prepareMaster:
cmd[cp]: |-
yum -y install xmlstarlet;
xmlstarlet ed --inplace -s Context -t elem -n 'Resources cachingAllowed="true" cacheMaxSize="40960"' /opt/tomcat/conf/context.xml;
service tomcat restart;
user: root
setupMaster:
cmd[cp]: |-
while [[ $(curl -s -w "%{http_code}" http://localhost:8080/ -o /dev/null) != "403" ]]; do echo "."; sleep 2; done
pswd=$(cat ~/.jenkins/secrets/initialAdminPassword)
jar=${STACK_PATH}/webapps/ROOT/WEB-INF/jenkins-cli.jar
cmd="java -jar $jar -auth admin:$pswd -s http://localhost:8080/"
until $(echo 'jenkins.model.Jenkins.instance.securityRealm.createAccount("${globals.user}", "${globals.password}")' | $cmd groovy =); do echo "repeat..."; sleep 2; done
printf "<?xml version='1.1' encoding='UTF-8'?>\n<jenkins.model.JenkinsLocationConfiguration>\n\t<adminAddress>${user.email}</adminAddress>\n\t<jenkinsUrl>${env.protocol}://${env.domain}/</jenkinsUrl>\n</jenkins.model.JenkinsLocationConfiguration>" > ~/.jenkins/jenkins.model.JenkinsLocationConfiguration.xml
wget ${baseUrl}/conf/plugins.txt -O plugins.txt
while read p; do names="${p%% *} $names"; done < plugins.txt;
$cmd install-plugin $names;
sed -i 's|>NEW<|>RUNNING<|g' ~/.jenkins/config.xml
sudo service tomcat restart
while [[ $(curl -s -w "%{http_code}" http://localhost:8080/ -o /dev/null) != "403" ]]; do echo "."; sleep 2; done
echo -e "\n"|ssh-keygen -t rsa -N ""
wget ${baseUrl}/conf/credentials.xml -O credentials.xml
xmlstarlet ed --inplace -u "com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey/privateKeySource/privateKey" -v "$(cat .ssh/id_rsa)" credentials.xml 2>/dev/null;
cat credentials.xml | java -jar $jar -s http://localhost -auth admin:$pswd create-credentials-by-xml "SystemCredentialsProvider::SystemContextResolver::jenkins" "(global)"
rm -f credentials.xml
readPublicKeyFromMaster:
api: env.file.Read
path: /opt/tomcat/temp/.ssh/id_rsa.pub
nodeid: ${nodes.cp.master.id}
initSlave:
- cmd[${this.slaveNodeId}]: |-
iptables -I INPUT -p tcp -s ${nodes.cp.master.intIP} --dport 22 -j ACCEPT;
user: root
- cmd[${this.slaveNodeId}]: |-
echo "${this.publicKey}" >> /home/jelastic/.ssh/authorized_keys;
- cmd[${nodes.cp.master.id}]: |-
ssh-keyscan -H ${this.slaveNodeIp} >> ~/.ssh/known_hosts
pswd=$(cat ~/.jenkins/secrets/initialAdminPassword)
jar=${STACK_PATH}/webapps/ROOT/WEB-INF/jenkins-cli.jar
wget ${baseUrl}/conf/worker.xml -O worker.xml
xmlstarlet ed --inplace -u "slave/name" -v "node${this.slaveNodeId}" worker.xml 2>/dev/null;
xmlstarlet ed --inplace -u "slave/launcher/host" -v "${this.slaveNodeIp}" worker.xml 2>/dev/null;
xmlstarlet ed --inplace -u "slave/label" -v "node${this.slaveNodeId}" worker.xml 2>/dev/null;
cat worker.xml | java -jar $jar -s http://localhost -auth admin:$pswd create-node node${this.slaveNodeId}
rm -f worker.xml
removeSlave:
cmd[${nodes.cp.master.id}]: |-
pswd=$(cat ~/.jenkins/secrets/initialAdminPassword)
jar=${STACK_PATH}/webapps/ROOT/WEB-INF/jenkins-cli.jar
java -jar $jar -s http://localhost -auth admin:$pswd delete-node node${this.slaveNodeId}
success: /text/success.md