-
Notifications
You must be signed in to change notification settings - Fork 15
/
docker_image.js
49 lines (48 loc) · 1.58 KB
/
docker_image.js
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
function DockerImage (source_image) {
var full_image = source_image.trim();
var full_name = '';
if (!full_image.includes('/')) {
full_name = "library/" + full_image;
}
if (!full_image.includes('/')) {
full_image = "library/" + full_image;
}
if (!full_image.includes(":")) {
full_image = full_image + ":latest";
}
var proto = 'https://';
if (/^https/.test(full_image)) {
proto = 'https://';
full_image = full_image.replace(/https:\/\//, '');
}
else if (/^http/.test(full_image)) {
full_image = full_image.replace(/http:\/\//, '');
}
// trim / from front and back
full_image = full_image.replace(/^\//, '').replace(/\/$/, '');
var registry
// figure out registry
if (/^library\//.test(full_image) || full_image.split('/').length < 3) {
// its docker io
registry = 'index.docker.io';
}
else {
registry = full_image.replace(/\/.*/, '');
}
// figure out image name
full_image = full_image.replace(/#{registry}(\/(v|V)(1|2)|)/i, '').replace(/^\//, '').replace(/\/$/, '');
var image_parts = full_image.split(':');
var image_name = image_parts[0];
var image_tag = image_parts[1];
// recombine for registry
var registry_url = proto + registry;
var fqin = registry_url + "/" + full_image;
this.fqin = fqin;
this.registry = registry;
this.registry_url = registry_url;
this.name = image_name;
this.tag = image_tag;
}
DockerImage.prototype.address = function() {
return this.registry + this.name + ":" + this.tag
};