forked from jenkinsci/azure-container-agents-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAciContainerTemplateFluent.java
More file actions
276 lines (210 loc) · 6.76 KB
/
Copy pathAciContainerTemplateFluent.java
File metadata and controls
276 lines (210 loc) · 6.76 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
package com.microsoft.jenkins.containeragents.builders;
import com.microsoft.jenkins.containeragents.PodEnvVar;
import com.microsoft.jenkins.containeragents.aci.AciPort;
import com.microsoft.jenkins.containeragents.aci.volumes.AzureFileVolume;
import com.microsoft.jenkins.containeragents.strategy.ContainerIdleRetentionStrategy;
import com.microsoft.jenkins.containeragents.strategy.ContainerOnceRetentionStrategy;
import com.microsoft.jenkins.containeragents.util.Constants;
import hudson.slaves.RetentionStrategy;
import org.jenkinsci.plugins.docker.commons.credentials.DockerRegistryEndpoint;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class AciContainerTemplateFluent<T extends AciContainerTemplateFluent<T>> {
private String name;
private String label;
private String image;
private String osType;
private String command;
private String rootFs;
private String ipType;
private int timeout;
private List<AciPort> ports = new ArrayList<>();
private String cpu;
private String memory;
private RetentionStrategy<?> retentionStrategy;
private List<PodEnvVar> envVars = new ArrayList<>();
private List<DockerRegistryEndpoint> privateRegistryCredentials = new ArrayList<>();
private List<AzureFileVolume> volumes = new ArrayList<>();
private String launchMethodType;
private String sshCredentialsId;
private String sshPort;
//CHECKSTYLE:OFF
AciContainerTemplateFluent() {
timeout = 10;
osType = "Linux";
image = "jenkins/inbound-agent";
command = "jenkins-agent -url ${rootUrl} ${secret} ${nodeName}";
rootFs = "/home/jenkins";
retentionStrategy = new ContainerOnceRetentionStrategy();
cpu = "1";
memory = "1.5";
ipType = "Public";
launchMethodType = Constants.LAUNCH_METHOD_JNLP;
}
public T withIpTyoe(Boolean ipType) {
this.ipType = ipType;
return (T) this;
}
public T withName(String name) {
this.name = name;
return (T) this;
}
public T withLabel(String label) {
this.label = label;
return (T) this;
}
public T withImage(String image) {
this.image = image;
return (T) this;
}
public T withOsType(String osType) {
this.osType = osType;
return (T) this;
}
public T withCommand(String command) {
this.command = command;
return (T) this;
}
public T withRootFs(String rootFs) {
this.rootFs = rootFs;
return (T) this;
}
public T withTimeout(int timeout) {
this.timeout = timeout;
return (T) this;
}
public T withPorts(List<AciPort> ports) {
this.ports.clear();
this.ports.addAll(ports);
return (T) this;
}
public T addToPorts(AciPort... ports) {
this.ports.addAll(Arrays.asList(ports));
return (T) this;
}
public T addNewPort(String port) {
this.ports.add(new AciPort(port));
return (T) this;
}
public T withCpu(String cpu) {
this.cpu = cpu;
return (T) this;
}
public T withMemory(String memory) {
this.memory = memory;
return (T) this;
}
public T withOnceRetentionStrategy() {
this.retentionStrategy = new ContainerOnceRetentionStrategy();
return (T) this;
}
public T withIdleRetentionStrategy(int idle) {
this.retentionStrategy = new ContainerIdleRetentionStrategy(idle);
return (T) this;
}
public T withEnvVars(List<PodEnvVar> envVars) {
this.envVars.clear();
this.envVars.addAll(envVars);
return (T) this;
}
public T addToEnvVars(PodEnvVar... envVars) {
this.envVars.addAll(Arrays.asList(envVars));
return (T) this;
}
public T addNewEnvVar(String key, String value) {
this.envVars.add(new PodEnvVar(key, value));
return (T) this;
}
public T withPrivateRegistryCredentials(List<DockerRegistryEndpoint> privateRegistryCredentials) {
this.privateRegistryCredentials.clear();
this.privateRegistryCredentials.addAll(privateRegistryCredentials);
return (T) this;
}
public T addToPrivateRegistryCredentials(DockerRegistryEndpoint... privateRegistryCredentials) {
this.privateRegistryCredentials.addAll(Arrays.asList(privateRegistryCredentials));
return (T) this;
}
public T addNewPrivateRegistryCredential(String registryUrl, String credentialsId) {
this.privateRegistryCredentials.add(new DockerRegistryEndpoint(registryUrl, credentialsId));
return (T) this;
}
public T withVolume(List<AzureFileVolume> volumes) {
this.volumes.clear();
this.volumes.addAll(volumes);
return (T) this;
}
public T addToVolumes(AzureFileVolume... volumes) {
this.volumes.addAll(Arrays.asList(volumes));
return (T) this;
}
public T addNewAzureFileVolume(String mountPath, String shareName, String credentialsId) {
this.volumes.add(new AzureFileVolume(mountPath, shareName, credentialsId));
return (T) this;
}
public T withJNLPLaunchMethod() {
this.launchMethodType = Constants.LAUNCH_METHOD_JNLP;
return (T) this;
}
public T withSSHLaunchMethod(String sshCredentialsId, String sshPort) {
this.launchMethodType = Constants.LAUNCH_METHOD_SSH;
this.sshCredentialsId = sshCredentialsId;
this.sshPort = sshPort;
return (T) this;
}
//CHECKSTYLE:ON
public String getName() {
return name;
}
public String getLabel() {
return label;
}
public String getIpType() {
return ipType;
}
public String getImage() {
return image;
}
public String getOsType() {
return osType;
}
public String getCommand() {
return command;
}
public String getRootFs() {
return rootFs;
}
public int getTimeout() {
return timeout;
}
public List<AciPort> getPorts() {
return ports;
}
public String getCpu() {
return cpu;
}
public String getMemory() {
return memory;
}
public RetentionStrategy<?> getRetentionStrategy() {
return retentionStrategy;
}
public List<PodEnvVar> getEnvVars() {
return envVars;
}
public List<DockerRegistryEndpoint> getPrivateRegistryCredentials() {
return privateRegistryCredentials;
}
public List<AzureFileVolume> getVolumes() {
return volumes;
}
public String getLaunchMethodType() {
return launchMethodType;
}
public String getSshCredentialsId() {
return sshCredentialsId;
}
public String getSshPort() {
return sshPort;
}
}