dockly 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/dockly/bash_builder.rb +3 -4
- data/lib/dockly/version.rb +1 -1
- data/snippets/file_diff_docker_import.erb +18 -2
- data/snippets/file_docker_import.erb +15 -1
- data/snippets/get_and_install_deb.erb +13 -2
- data/snippets/registry_import.erb +13 -1
- data/snippets/s3_diff_docker_import.erb +33 -9
- data/snippets/s3_docker_import.erb +18 -2
- data/spec/dockly/bash_builder_spec.rb +25 -67
- metadata +2 -3
- data/snippets/docker_import.erb +0 -1
data/lib/dockly/bash_builder.rb
CHANGED
@@ -16,15 +16,14 @@ module Dockly
|
|
16
16
|
end
|
17
17
|
|
18
18
|
generate_snippet_for :normalize_for_dockly, []
|
19
|
-
generate_snippet_for :get_from_s3, [:s3_url, :output_path], { :output_path => "-" }
|
20
|
-
generate_snippet_for :install_package, [:path]
|
21
19
|
generate_snippet_for :get_and_install_deb, [:s3_url, :deb_path]
|
22
|
-
|
23
|
-
generate_snippet_for :docker_tag_latest, [:repo, :tag]
|
20
|
+
|
24
21
|
generate_snippet_for :file_docker_import, [:path, :repo, :tag]
|
25
22
|
generate_snippet_for :file_diff_docker_import, [:base_image, :diff_image, :repo, :tag]
|
26
23
|
generate_snippet_for :s3_docker_import, [:s3_url, :repo, :tag]
|
27
24
|
generate_snippet_for :s3_diff_docker_import, [:base_image, :diff_image, :repo, :tag]
|
28
25
|
generate_snippet_for :registry_import, [:repo, :tag], { :tag => "latest" }
|
26
|
+
|
27
|
+
generate_snippet_for :docker_tag_latest, [:repo, :tag]
|
29
28
|
end
|
30
29
|
end
|
data/lib/dockly/version.rb
CHANGED
@@ -1,4 +1,20 @@
|
|
1
1
|
file_diff_docker_import_fn() {
|
2
|
-
<%=
|
2
|
+
s3_path="<%= data[:base_image] %>"
|
3
|
+
log "fetch: starting to fetch $s3_path"
|
4
|
+
s3cmd -f get $s3_path - 2> >(log)
|
5
|
+
log "fetch: successfully fetched $s3_path"
|
3
6
|
}
|
4
|
-
|
7
|
+
|
8
|
+
docker_import() {
|
9
|
+
repo=<%= data[:repo] %>
|
10
|
+
tag=<%= data[:tag] %>
|
11
|
+
(cat "<%= data[:diff_image] %>"; file_diff_docker_import_fn) | gunzip -c | docker import - $repo:$tag
|
12
|
+
}
|
13
|
+
|
14
|
+
worked=1
|
15
|
+
for attempt in {1..200}; do
|
16
|
+
[[ $worked != 0]] || break
|
17
|
+
docker_import && worked=0 || (log "fetch: attempt $attempt failed, sleeping 30"; sleep 30)
|
18
|
+
done
|
19
|
+
[[ $worked != 0 ]] && fatal "fetch: failed to import diff image"
|
20
|
+
log "fetch: successfully imported image"
|
@@ -1 +1,15 @@
|
|
1
|
-
|
1
|
+
docker_import() {
|
2
|
+
path=<%= data[:path] %>
|
3
|
+
repo=<%= data[:repo] %>
|
4
|
+
tag=<%= data[:tag] %>
|
5
|
+
cat $path | gunzip -c | docker import - $repo:$tag
|
6
|
+
}
|
7
|
+
|
8
|
+
# Hopefully this isn't ever needed
|
9
|
+
worked=1
|
10
|
+
for attempt in {1..200}; do
|
11
|
+
[[ $worked != 0 ]] || break
|
12
|
+
docker_import && worked=0 || (log "fetch: attempt $attempt failed, sleeping 30"; sleep 30)
|
13
|
+
done
|
14
|
+
[[ $worked != 0 ]] && fatal "fetch: failed to import image"
|
15
|
+
log "fetch: successfully imported image"
|
@@ -1,2 +1,13 @@
|
|
1
|
-
|
2
|
-
<%=
|
1
|
+
worked=1
|
2
|
+
s3_path="<%= data[:s3_url] %>"
|
3
|
+
output_path="<%= data[:deb_path] %>"
|
4
|
+
log "fetch: starting to fetch $s3_path"
|
5
|
+
for attempt in {1..200}; do
|
6
|
+
[[ $worked != 0 ]] || break
|
7
|
+
log "fetch: attempt ${attempt} to get $s3_path ..."
|
8
|
+
s3cmd -f get $s3_path $output_path 2> >(log) && worked=0 || (log "fetch: attempt failed, sleeping 30"; sleep 30)
|
9
|
+
done
|
10
|
+
[[ $worked != 0 ]] && fatal "fetch: failed to pull deb from S3"
|
11
|
+
log "fetch: successfully fetched $s3_path"
|
12
|
+
|
13
|
+
dpkg -i "<%= data[:deb_path] %>"
|
@@ -1 +1,13 @@
|
|
1
|
-
|
1
|
+
docker_pull() {
|
2
|
+
repo=<%= data[:repo] %>
|
3
|
+
tag=<%= data[:tag] %>
|
4
|
+
docker pull $repo:$tag
|
5
|
+
}
|
6
|
+
|
7
|
+
worked=1
|
8
|
+
for attempt in {1..200}; do
|
9
|
+
[[ $worked != 0 ]] || break
|
10
|
+
docker_pull && worked=0 || (log "fetch: attempt $attempt failed, sleeping 30"; sleep 30)
|
11
|
+
done
|
12
|
+
[[ $worked != 0 ]] && fatal "failed to import image"
|
13
|
+
log "fetch: successfully imported image"
|
@@ -3,24 +3,48 @@ base_image = "/opt/dockly/base_image.tar"
|
|
3
3
|
%>
|
4
4
|
|
5
5
|
s3_diff_docker_import_base_fn() {
|
6
|
-
<%=
|
6
|
+
s3_path="<%= data[:base_image] %>"
|
7
|
+
log "fetch: starting to fetch $s3_path"
|
8
|
+
s3cmd -f get $s3_path - 2> >(log)
|
9
|
+
log "fetch: successfully fetched $s3_path"
|
7
10
|
}
|
8
11
|
|
9
12
|
s3_diff_docker_import_diff_fn() {
|
10
|
-
<%=
|
13
|
+
s3_path="<%= data[:diff_image] %>"
|
14
|
+
log "fetch: starting to fetch $s3_path"
|
15
|
+
s3cmd -f get $s3_path - 2> >(log)
|
16
|
+
log "fetch: successfully fetched $s3_path"
|
17
|
+
}
|
18
|
+
|
19
|
+
base_image() {
|
20
|
+
s3_diff_docker_import_base_fn | gunzip -vc > "<%= base_image %>" 2> >(log)
|
11
21
|
}
|
12
22
|
|
13
23
|
stream_image() {
|
14
|
-
size=$(stat --format "%s" "<%= base_image %>")
|
15
|
-
head_size=$(($size - 1024))
|
16
|
-
head -c $head_size "<%= base_image %>"
|
17
|
-
s3_diff_docker_import_diff_fn | (gunzip -vc 2> >(log) || fatal "tardiff failed to gunzip")
|
24
|
+
size=$(stat --format "%s" "<%= base_image %>")
|
25
|
+
head_size=$(($size - 1024))
|
26
|
+
head -c $head_size "<%= base_image %>"
|
27
|
+
s3_diff_docker_import_diff_fn | (gunzip -vc 2> >(log) || fatal "tardiff failed to gunzip")
|
18
28
|
}
|
19
29
|
|
20
30
|
docker_import() {
|
21
|
-
|
31
|
+
repo=<%= data[:repo] %>
|
32
|
+
tag=<%= data[:tag] %>
|
33
|
+
docker import - $repo:$tag > >(log) 2>&1 || fatal "docker failed to import"
|
22
34
|
}
|
23
35
|
|
24
|
-
|
36
|
+
worked=1
|
37
|
+
for attempt in {1..200}; do
|
38
|
+
[[ $worked != 0 ]] || break
|
39
|
+
base_image && worked=0 || (log "fetch: attempt $attempt failed, sleeping 30"; sleep 30)
|
40
|
+
done
|
41
|
+
[[ $worked != 0 ]] && fatal "fetch: failed to pull base image"
|
42
|
+
log "fetch: successfully pulled base image"
|
25
43
|
|
26
|
-
|
44
|
+
worked=1
|
45
|
+
for attempt in {1..200}; do
|
46
|
+
[[ $worked != 0 ]] || break
|
47
|
+
stream_image | docker_import && worked=0 || (log "fetch: attempt $attempt failed, sleeping 30"; sleep 30)
|
48
|
+
done
|
49
|
+
[[ $worked != 0 ]] && fatal "fetch: failed to import diff image"
|
50
|
+
log "fetch: successfully imported diff image"
|
@@ -1,4 +1,20 @@
|
|
1
1
|
s3_docker_import_fn() {
|
2
|
-
<%=
|
2
|
+
s3_path="<%= data[:s3_url] %>"
|
3
|
+
log "fetch: starting to fetch $s3_path"
|
4
|
+
s3cmd -f get $s3_path - 2> >(log)
|
5
|
+
log "fetch: successfully fetched $s3_path"
|
3
6
|
}
|
4
|
-
|
7
|
+
|
8
|
+
docker_import() {
|
9
|
+
repo=<%= data[:repo] %>
|
10
|
+
tag=<%= data[:tag] %>
|
11
|
+
s3_docker_import_fn | gunzip -c | docker import - $repo:$tag
|
12
|
+
}
|
13
|
+
|
14
|
+
worked=1
|
15
|
+
for attempt in {1..200}; do
|
16
|
+
[[ $worked != 0 ]] || break
|
17
|
+
docker_import && worked=0 || (log "fetch: attempt $attempt failed, sleeping 30"; sleep 30)
|
18
|
+
done
|
19
|
+
[[ $worked != 0 ]] && fatal "failed to import image"
|
20
|
+
log "fetch: successfully imported image"
|
@@ -10,67 +10,15 @@ describe Dockly::BashBuilder do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe "#get_from_s3" do
|
14
|
-
let(:s3_url) { "s3://url-for-s3/file.tar.gz" }
|
15
|
-
context "uses the default output" do
|
16
|
-
it "polls from s3 and sets the s3_path" do
|
17
|
-
output = subject.get_from_s3(s3_url)
|
18
|
-
expect(output).to include("s3cmd -f get $s3_path $output_path")
|
19
|
-
expect(output).to include("s3_path=\"#{s3_url}\"")
|
20
|
-
expect(output).to include("output_path=\"-\"")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
context "uses a specific output directory" do
|
24
|
-
let(:output_dir) { "test" }
|
25
|
-
it "polls from s3 and sets the s3_path and output_path" do
|
26
|
-
output = subject.get_from_s3(s3_url, output_dir)
|
27
|
-
expect(output).to include("s3cmd -f get $s3_path $output_path")
|
28
|
-
expect(output).to include("s3_path=\"#{s3_url}\"")
|
29
|
-
expect(output).to include("output_path=\"#{output_dir}\"")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#install_package" do
|
35
|
-
let(:path) { "/opt/dockly/deb.deb" }
|
36
|
-
it "installs from the given path" do
|
37
|
-
output = subject.install_package(path)
|
38
|
-
expect(output.strip).to eq("dpkg -i \"#{path}\"")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
13
|
describe "#get_and_install_deb" do
|
43
14
|
let(:s3_url) { "s3://bucket/path-to-deb.deb" }
|
44
15
|
let(:deb_path) { "/opt/dockly/deb_path.deb" }
|
45
16
|
it "gets from s3 and installs the package" do
|
46
|
-
|
47
|
-
expect(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
describe "#docker_import" do
|
53
|
-
context "when not given a repo" do
|
54
|
-
it "imports with no tagging" do
|
55
|
-
output = subject.docker_import
|
56
|
-
expect(output).to include("docker import -")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when given a repo" do
|
61
|
-
let(:repo) { "aRepo" }
|
62
|
-
it "imports with repo and latest" do
|
63
|
-
output = subject.docker_import(repo)
|
64
|
-
expect(output).to include("docker import - #{repo}:latest")
|
65
|
-
end
|
66
|
-
|
67
|
-
context "and a non-default tag" do
|
68
|
-
let(:tag) { "aTag" }
|
69
|
-
it "imports with repo and the tag" do
|
70
|
-
output = subject.docker_import(repo, tag)
|
71
|
-
expect(output).to include("docker import - #{repo}:#{tag}")
|
72
|
-
end
|
73
|
-
end
|
17
|
+
output = subject.get_and_install_deb(s3_url, deb_path)
|
18
|
+
expect(output).to include(s3_url)
|
19
|
+
expect(output).to include(deb_path)
|
20
|
+
expect(output).to include("s3cmd -f get")
|
21
|
+
expect(output).to include("dpkg -i")
|
74
22
|
end
|
75
23
|
end
|
76
24
|
|
@@ -93,10 +41,10 @@ describe Dockly::BashBuilder do
|
|
93
41
|
describe "#file_docker_import" do
|
94
42
|
let(:path) { "/opt/dockly/file.tar.gz" }
|
95
43
|
it "cats, gunzips and passes to docker import" do
|
96
|
-
expect(subject).to receive(:docker_import)
|
97
44
|
output = subject.file_docker_import(path)
|
98
45
|
expect(output).to include("cat")
|
99
46
|
expect(output).to include("gunzip -c")
|
47
|
+
expect(output).to include("docker import -")
|
100
48
|
end
|
101
49
|
end
|
102
50
|
|
@@ -104,19 +52,23 @@ describe Dockly::BashBuilder do
|
|
104
52
|
let(:base_image) { "s3://bucket/base_image.tar.gz" }
|
105
53
|
let(:diff_image) { "/opt/dockly/diff_image.tar.gz" }
|
106
54
|
it "gets the base file from S3 and cats that with the diff image and imports to docker" do
|
107
|
-
|
108
|
-
expect(
|
109
|
-
expect(
|
55
|
+
output = subject.file_diff_docker_import(base_image, diff_image)
|
56
|
+
expect(output).to include(base_image)
|
57
|
+
expect(output).to include(diff_image)
|
58
|
+
expect(output).to include("cat \"#{diff_image}\"")
|
59
|
+
expect(output).to include("s3cmd -f get")
|
60
|
+
expect(output).to include("docker import -")
|
110
61
|
end
|
111
62
|
end
|
112
63
|
|
113
64
|
describe "#s3_docker_import" do
|
114
65
|
let(:s3_url) { "s3://bucket/image.tar.gz" }
|
115
66
|
it "pulls, gunzips and passes to docker import" do
|
116
|
-
expect(subject).to receive(:get_from_s3)
|
117
|
-
expect(subject).to receive(:docker_import)
|
118
67
|
output = subject.s3_docker_import(s3_url)
|
68
|
+
expect(output).to include(s3_url)
|
119
69
|
expect(output).to include("gunzip -c")
|
70
|
+
expect(output).to include("s3cmd -f get")
|
71
|
+
expect(output).to include("docker import -")
|
120
72
|
end
|
121
73
|
end
|
122
74
|
|
@@ -124,13 +76,15 @@ describe Dockly::BashBuilder do
|
|
124
76
|
let(:base_image) { "s3://bucket/base_image.tar.gz" }
|
125
77
|
let(:diff_image) { "s3://bucket/diff_image.tar.gz" }
|
126
78
|
it "makes two functions for getting from s3, finds the size, and imports both to docker" do
|
127
|
-
expect(subject).to receive(:get_from_s3).twice
|
128
|
-
expect(subject).to receive(:docker_import)
|
129
79
|
output = subject.s3_diff_docker_import(base_image, diff_image)
|
80
|
+
expect(output).to include(base_image)
|
81
|
+
expect(output).to include(diff_image)
|
130
82
|
expect(output).to include("stat --format \"%s\"") # get file size
|
131
83
|
expect(output).to include("$(($size - 1024))") # compute file size
|
132
84
|
expect(output).to include("head -c $head_size")
|
133
85
|
expect(output).to include("gunzip")
|
86
|
+
expect(output).to include("s3cmd -f get")
|
87
|
+
expect(output).to include("docker import -")
|
134
88
|
end
|
135
89
|
end
|
136
90
|
|
@@ -139,7 +93,9 @@ describe Dockly::BashBuilder do
|
|
139
93
|
context "not given a tag" do
|
140
94
|
it "pulls the latest" do
|
141
95
|
output = subject.registry_import(repo)
|
142
|
-
expect(output).to include("docker pull
|
96
|
+
expect(output).to include("docker pull $repo:$tag")
|
97
|
+
expect(output).to include("repo=#{repo}")
|
98
|
+
expect(output).to include("tag=latest")
|
143
99
|
end
|
144
100
|
end
|
145
101
|
|
@@ -147,7 +103,9 @@ describe Dockly::BashBuilder do
|
|
147
103
|
let(:tag) { "aTag" }
|
148
104
|
it "pulls to specified tag" do
|
149
105
|
output = subject.registry_import(repo, tag)
|
150
|
-
expect(output).to include("docker pull
|
106
|
+
expect(output).to include("docker pull $repo:$tag")
|
107
|
+
expect(output).to include("repo=#{repo}")
|
108
|
+
expect(output).to include("tag=#{tag}")
|
151
109
|
end
|
152
110
|
end
|
153
111
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dockly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: clamp
|
@@ -278,7 +278,6 @@ files:
|
|
278
278
|
- lib/dockly/version.rb
|
279
279
|
- lib/foreman/cli_fix.rb
|
280
280
|
- lib/foreman/export/base_fix.rb
|
281
|
-
- snippets/docker_import.erb
|
282
281
|
- snippets/docker_tag_latest.erb
|
283
282
|
- snippets/file_diff_docker_import.erb
|
284
283
|
- snippets/file_docker_import.erb
|
data/snippets/docker_import.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
docker import - <% if data[:repo] %><%= data[:repo] %>:<%= data[:tag] %><% end %>
|