nutkins 0.11.0 → 0.12.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52cf42f9bda34623d363c0949b12a37820f19ee6
4
- data.tar.gz: 81197095413f31fac40a8e43b9e04dff878d824b
3
+ metadata.gz: 30d41118cac65bc2af20312bb21560e8465430f4
4
+ data.tar.gz: 7bb9fb87a3d56797d2ef774c86da9ebdf5d6c6eb
5
5
  SHA512:
6
- metadata.gz: b76082e30b1f978daed27171a39039017754c894f34795f40b15b2d1602bb6676247b42318abda039c4b473868307402264158381e0c38daf23089ed882c4c3d
7
- data.tar.gz: 3958e780eb1148ba2a9e879848bcfca8f87f99c783a2d05495f4d5272df82bdd7fb366576e2eb65422a18da2eaaf9e0b09e820a0309a3a4b7a9932b279814305
6
+ metadata.gz: e1378926ff0871fb1126383ec776d13606edc7620b5635ca21ba765c984d787da0ab7404f7da87e7cddd4ea14d62326cf5b1dc90519bbff484a63fc799b7db49
7
+ data.tar.gz: 9a8d6ab3159a5717d07a0aa43a814dbab8695a7aaf6fc3987141fba0c59e55ba7847c0a769d9a47502ea8e8578fad2eab43c6f6302a20771222772c75b94b311
@@ -36,8 +36,7 @@ module Nutkins::Docker::Builder
36
36
  # docker run is always used and forms the basis of the cache key
37
37
  run_args = nil
38
38
  env_args = nil
39
- add_files = nil
40
- add_files_dest = nil
39
+ copies = []
41
40
 
42
41
  case cmd
43
42
  when "run"
@@ -46,31 +45,48 @@ module Nutkins::Docker::Builder
46
45
  else
47
46
  run_args = cmd_args.join ' && '
48
47
  end
49
- when "add"
50
- *add_files, add_files_dest = cmd_args.split ' '
51
- add_files = add_files.map { |src| Dir.glob src }.flatten
52
- # ensure checksum of each file is embedded into run command
53
- # if any file changes the cache is dirtied
54
- run_args = '#(nop) add ' + add_files.map do |src|
55
- if File.directory? src
56
- md5 = Digest::MD5.new
57
- update_md5_dir = Proc.new do |dir|
58
- Dir.glob("#{dir}/*").each do |dir_entry|
59
- if File.directory? dir_entry
60
- update_md5_dir.call dir_entry
61
- else
62
- md5.update(File.read dir_entry)
48
+ when "copy"
49
+ if cmd_args.kind_of? String
50
+ all_copy_args = [ cmd_args ]
51
+ else
52
+ all_copy_args = cmd_args
53
+ end
54
+
55
+ copies = all_copy_args.map do |copy_args|
56
+ *add_files, add_files_dest = copy_args.split ' '
57
+ add_files = add_files.map { |src| Dir.glob src }.flatten
58
+ # ensure checksum of each file is embedded into run command
59
+ # if any file changes the cache is dirtied
60
+
61
+ if not run_args
62
+ run_args = '#(nop) copy '
63
+ else
64
+ run_args += ';'
65
+ end
66
+
67
+ run_args += add_files.map do |src|
68
+ if File.directory? src
69
+ md5 = Digest::MD5.new
70
+ update_md5_dir = Proc.new do |dir|
71
+ Dir.glob("#{dir}/*").each do |dir_entry|
72
+ if File.directory? dir_entry
73
+ update_md5_dir.call dir_entry
74
+ else
75
+ md5.update(File.read dir_entry)
76
+ end
63
77
  end
64
78
  end
79
+
80
+ update_md5_dir.call src
81
+ hash = md5.hexdigest
82
+ else
83
+ hash = Digest::MD5.file(src).to_s
65
84
  end
85
+ src + ':' + hash
86
+ end.push(add_files_dest).join(' ')
66
87
 
67
- update_md5_dir.call src
68
- hash = md5.hexdigest
69
- else
70
- hash = Digest::MD5.file(src).to_s
71
- end
72
- src + ':' + hash
73
- end.push(add_files_dest).join(' ')
88
+ { srcs: add_files, dest: add_files_dest }
89
+ end
74
90
  when "cmd", "entrypoint", "env", "expose", "label", "onbuild", "user", "volume", "workdir"
75
91
  env_args = cmd + ' ' + (cmd_args.kind_of?(String) ? cmd_args : JSON.dump(cmd_args))
76
92
  run_args = "#(nop) #{env_args}"
@@ -104,10 +120,13 @@ module Nutkins::Docker::Builder
104
120
 
105
121
  cont_id = `docker ps -aq`.lines.first.strip
106
122
  begin
107
- if add_files
108
- add_files.each do |src|
109
- if not Docker.run 'cp', src, "#{cont_id}:#{add_files_dest}"
110
- raise "could not copy #{src} to #{cont_id}:#{add_files_dest}"
123
+ unless copies.empty?
124
+ copies.each do |copy|
125
+ copy[:srcs].each do |src|
126
+ puts "copy #{src} -> #{cont_id}:#{copy[:dest]}"
127
+ if not Docker.run 'cp', src, "#{cont_id}:#{copy[:dest]}"
128
+ raise "could not copy #{src} to #{cont_id}:#{copy[:dest]}"
129
+ end
111
130
  end
112
131
  end
113
132
  end
@@ -1,3 +1,3 @@
1
1
  module Nutkins
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
data/readme.md CHANGED
@@ -66,13 +66,13 @@ build:
66
66
  - apt-get update
67
67
  - apt-get install -y vim zsh less nano rsync git net-tools
68
68
  - groupadd -g 5496 sslcerts
69
- - add: bin/* /bin/
69
+ - copy: bin/* /bin/
70
70
  - entrypoint: ["/bin/smell-baron"]
71
71
  ```
72
72
 
73
73
  The `resources` section downloads files to local directories so that they can be used in the image. In the case of `confd` it also extracts a file from a `tar.gz` compressed archive.
74
74
 
75
- The `commands` section is like a `Dockerfile` and is used to build a container. In this case it runs multiple commands, add some files to the image and sets an `entrypoint`. This image would be tagged `myorg/base:0.0.1`. The image name comes from the subdirectory but can be overriden along with the `version`:
75
+ The `commands` section is like a `Dockerfile` and is used to build a container. In this case it runs multiple commands, copies some files to the image and sets an `entrypoint`. This image would be tagged `myorg/base:0.0.1`. The image name comes from the subdirectory but can be overriden along with the `version`:
76
76
 
77
77
  ```yaml
78
78
  base: ubuntu:16.04
@@ -92,7 +92,7 @@ This will output various information as it builds the image. If the same command
92
92
  ```bash
93
93
  % nutkins build base
94
94
  cached: apt-get update && apt-get install -y vim zsh less nano rsync git net-tools && groupadd -g 5496 sslcerts
95
- cached: #(nop) add bin/confd:33472f6b8f9522ec7bdb01a8feeb03fb bin/etcdctl:8edfaac7c726e8231c6e0e8f75ffb678 bin/smell-baron:909345dcbc4a029d42f39278486a32b9 /bin/
95
+ cached: #(nop) copy bin/confd:33472f6b8f9522ec7bdb01a8feeb03fb bin/etcdctl:8edfaac7c726e8231c6e0e8f75ffb678 bin/smell-baron:909345dcbc4a029d42f39278486a32b9 /bin/
96
96
  cached: #(nop) entrypoint ["/bin/smell-baron"]
97
97
  unchanged image: myorg/base:0.0.1
98
98
  ```
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nutkins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Pike