Skip to content

Commit 098dc9b

Browse files
authored
Merge pull request #3 from nunokisc/main
add new service elements, change opts to output inside buildHostConfig
2 parents d360a26 + b774ad4 commit 098dc9b

File tree

1 file changed

+142
-26
lines changed

1 file changed

+142
-26
lines changed

lib/services.js

Lines changed: 142 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,47 @@ module.exports = async function (docker, projectName, recipe, output) {
104104
if (service.mac_address !== undefined) {
105105
opts.MacAddress = service.mac_address;
106106
}
107+
if (service.stdin_open !== undefined) {
108+
opts.OpenStdin = service.stdin_open;
109+
}
110+
if (service.stop_grace_period !== undefined) {
111+
let period = parseInt(service.stop_grace_period)
112+
if (service.stop_grace_period == period) {
113+
opts.StopTimeout = service.stop_grace_period;
114+
} else if (service.stop_grace_period.includes('m') && service.stop_grace_period.includes('s')) {
115+
let minutes = parseInt(service.stop_grace_period.substring(0, service.stop_grace_period.indexOf('m')))
116+
let seconds = parseInt(service.stop_grace_period.substring(service.stop_grace_period.indexOf('m') + 1, service.stop_grace_period.indexOf('s')))
117+
opts.StopTimeout = (minutes * 60) + seconds
118+
} else {
119+
opts.StopTimeout = service.stop_grace_period.substring(0, service.stop_grace_period.length - 2)
120+
}
121+
}
122+
if (service.stop_signal !== undefined) {
123+
opts.StopSignal = service.stop_signal;
124+
}
125+
if (service.tty !== undefined) {
126+
opts.Tty = service.tty;
127+
}
128+
if (service.user !== undefined) {
129+
opts.User = service.user;
130+
}
131+
if (service.working_dir !== undefined) {
132+
opts.WorkingDir = service.working_dir;
133+
}
134+
if (service.labels !== undefined) {
135+
if (service.labels.length > 0) {
136+
var labels = {};
137+
for (var labelsb of service.labels) {
138+
var p = labelsb.split('=');
139+
if (p[1] === undefined)
140+
p[1] = ''
141+
labels[p[0]] = p[1]
142+
}
143+
opts.Labels = labels
144+
} else {
145+
opts.Labels = service.labels
146+
}
147+
}
107148
try {
108149
var container = await docker.createContainer(opts);
109150

@@ -156,81 +197,156 @@ var buildHostConfig = function (service, recipe) {
156197
}
157198

158199
if (service.cpu_count !== undefined) {
159-
opts.CpuCount = service.cpu_count;
200+
output.CpuCount = service.cpu_count;
160201
}
161202
if (service.cpu_percent !== undefined) {
162-
opts.CpuPercent = service.cpu_percent;
203+
output.CpuPercent = service.cpu_percent;
163204
}
164205
if (service.cpu_shares !== undefined) {
165-
opts.CpuShares = service.cpu_shares;
206+
output.CpuShares = service.cpu_shares;
166207
}
167208
if (service.cpu_period !== undefined) {
168-
opts.CpuPeriod = service.cpu_period;
209+
output.CpuPeriod = service.cpu_period;
169210
}
170211
if (service.cpu_quota !== undefined) {
171-
opts.CpuQuota = service.cpu_quota;
212+
output.CpuQuota = service.cpu_quota;
172213
}
173214
if (service.cpu_rt_runtime !== undefined) {
174-
opts.CpuRealtimeRuntime = service.cpu_rt_runtime;
215+
output.CpuRealtimeRuntime = service.cpu_rt_runtime;
175216
}
176217
if (service.cpu_rt_period !== undefined) {
177-
opts.CpuRealtimePeriod = service.cpu_rt_period;
218+
output.CpuRealtimePeriod = service.cpu_rt_period;
178219
}
179220
if (service.cpuset !== undefined) {
180-
opts.CpusetCpus = service.cpuset;
221+
output.CpusetCpus = service.cpuset;
181222
}
182223
if (service.cap_add !== undefined) {
183-
opts.CapAdd = service.cap_add;
224+
output.CapAdd = service.cap_add;
184225
}
185226
if (service.cap_drop !== undefined) {
186-
opts.CapDrop = service.cap_drop;
227+
output.CapDrop = service.cap_drop;
187228
}
188229
if (service.cgroup_parent !== undefined) {
189-
opts.CgroupParent = service.cgroup_parent;
230+
output.CgroupParent = service.cgroup_parent;
190231
}
191232
if (service.device_cgroup_rules !== undefined) {
192-
opts.DeviceCgroupRules = service.device_cgroup_rules;
233+
output.DeviceCgroupRules = service.device_cgroup_rules;
193234
}
194235
if (service.dns !== undefined) {
195-
opts.Dns = service.dns;
236+
output.Dns = service.dns;
196237
}
197238
if (service.dns_opt !== undefined) {
198-
opts.DnsOptions = service.dns_opt;
239+
output.DnsOptions = service.dns_opt;
199240
}
200241
if (service.dns_search !== undefined) {
201-
opts.DnsSearch = service.dns_search;
242+
output.DnsSearch = service.dns_search;
202243
}
203244
if (service.extra_hosts !== undefined) {
204-
opts.ExtraHosts = service.extra_hosts;
245+
output.ExtraHosts = service.extra_hosts;
205246
}
206247
if (service.group_add !== undefined) {
207-
opts.GroupAdd = service.group_add;
248+
output.GroupAdd = service.group_add;
208249
}
209250
if (service.init !== undefined) {
210-
opts.Init = service.init;
251+
output.Init = service.init;
211252
}
212253
if (service.ipc !== undefined) {
213-
opts.IpcMode = service.ipc;
254+
output.IpcMode = service.ipc;
214255
}
215256
if (service.isolation !== undefined) {
216-
opts.Isolation = service.isolation;
257+
output.Isolation = service.isolation;
217258
}
218259
if (service.mem_swappiness !== undefined) {
219-
opts.MemorySwappiness = service.mem_swappiness;
260+
output.MemorySwappiness = service.mem_swappiness;
220261
}
221262
if (service.oom_kill_disable !== undefined) {
222-
opts.OomKillDisable = service.oom_kill_disable;
263+
output.OomKillDisable = service.oom_kill_disable;
223264
}
224265
if (service.oom_score_adj !== undefined) {
225-
opts.OomScoreAdj = service.oom_score_adj;
266+
output.OomScoreAdj = service.oom_score_adj;
226267
}
227268
if (service.pid !== undefined) {
228-
opts.PidMode = service.pid;
269+
output.PidMode = service.pid;
229270
}
230271
if (service.pids_limit !== undefined) {
231-
opts.PidsLimit = service.pids_limit;
272+
output.PidsLimit = service.pids_limit;
273+
}
274+
if (service.privileged !== undefined) {
275+
output.Privileged = service.privileged;
276+
}
277+
if (service.read_only !== undefined) {
278+
output.ReadonlyRootfs = service.read_only;
279+
}
280+
if (service.runtime !== undefined) {
281+
output.Runtime = service.runtime;
282+
}
283+
if (service.security_opt !== undefined) {
284+
output.SecurityOpt = service.security_opt;
285+
}
286+
if (service.shm_size !== undefined) {
287+
output.ShmSize = service.shm_size;
288+
}
289+
if (service.storage_opt !== undefined) {
290+
output.StorageOpt = service.storage_opt;
291+
}
292+
if (service.sysctls !== undefined) {
293+
if (service.sysctls.length > 0) {
294+
var sysctls = {};
295+
for (var sysctlsb of service.sysctls) {
296+
var p = sysctlsb.split('=');
297+
sysctls[p[0]] = p[1]
298+
}
299+
output.Sysctls = sysctls
300+
} else {
301+
let sysctlKeys = Object.keys(service.sysctls)
302+
let newSysctls = {}
303+
for (var key of sysctlKeys) {
304+
newSysctls[key] = service.sysctls[key].toString();
305+
}
306+
output.Sysctls = newSysctls
307+
}
308+
}
309+
if (service.userns_mode !== undefined) {
310+
output.UsernsMode = service.userns_mode;
311+
}
312+
if (service.tmpfs !== undefined) {
313+
if (Array.isArray(service.tmpfs)) {
314+
var tmpfs = {};
315+
for (var tmpfsb of service.tmpfs) {
316+
var p = tmpfsb.split(':');
317+
if (p[1] === undefined)
318+
p[1] = '';
319+
tmpfs[p[0]] = p[1];
320+
}
321+
output.Tmpfs = tmpfs;
322+
} else {
323+
var tmpfs = {};
324+
var p = service.tmpfs.split(':');
325+
if (p[1] === undefined)
326+
p[1] = '';
327+
tmpfs[p[0]] = p[1];
328+
output.Tmpfs = tmpfs;
329+
}
330+
}
331+
if (service.ulimits !== undefined) {
332+
let ulimitsKeys = Object.keys(service.ulimits);
333+
let ulimitsArray = []
334+
for (var key of ulimitsKeys) {
335+
let ulimitsObject = {}
336+
if (typeof service.ulimits[key] === 'object') {
337+
ulimitsObject.Name = key;
338+
ulimitsObject.Soft = service.ulimits[key].soft;
339+
ulimitsObject.Hard = service.ulimits[key].hard;
340+
ulimitsArray.push(ulimitsObject);
341+
} else {
342+
ulimitsObject.Name = key;
343+
ulimitsObject.Soft = service.ulimits[key];
344+
ulimitsObject.Hard = service.ulimits[key];
345+
ulimitsArray.push(ulimitsObject);
346+
}
347+
}
348+
output.Ulimits = ulimitsArray;
232349
}
233-
234350
return output;
235351
}
236352

0 commit comments

Comments
 (0)