dg 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dg/docker.rb +43 -5
- data/lib/dg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1046c9e937f5b5bd562829da8815c495de75681a
|
4
|
+
data.tar.gz: 6f0c35bc9ac501948bb1ac0a174f80ecc17b6427
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec8a8ccd0430e36f83690f9925b40b04b5e583a26273a7504b55bebb382ff310e36a8757d0924941af45f84fd62331733960df9f027311da5665f187e3234585
|
7
|
+
data.tar.gz: 8e69e2a120db6cf26697f0356196b5129bd07e0cc609e6ce8900c749c922e5b541c389c2f680e94cc767a1b61d78e86627ea8caa5f48b19cb20d325990c0d2a7
|
data/lib/dg/docker.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'pty'
|
2
2
|
require 'uri'
|
3
3
|
require 'net/http'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'time'
|
4
6
|
require 'dg/version'
|
5
7
|
|
6
8
|
module DG
|
@@ -10,10 +12,17 @@ module DG
|
|
10
12
|
|
11
13
|
FIG_YML_PATH = "#{BASEPATH}/fig.yml"
|
12
14
|
FIG_GEN_PATH = "#{BASEPATH}/fig_gen.yml"
|
15
|
+
CACHE_FILES = %w(
|
16
|
+
bower.json
|
17
|
+
Gemfile
|
18
|
+
Gemfile.lock
|
19
|
+
package.json
|
20
|
+
)
|
13
21
|
|
14
22
|
class << self
|
15
23
|
|
16
24
|
def build
|
25
|
+
reset_mtimes
|
17
26
|
build_docker_image_with_tag
|
18
27
|
end
|
19
28
|
|
@@ -81,16 +90,16 @@ module DG
|
|
81
90
|
exit 1
|
82
91
|
end
|
83
92
|
|
84
|
-
def run_with_output(command, capture = false)
|
93
|
+
def run_with_output(command, capture = false, return_hash = false)
|
85
94
|
sudo_command = SUDO ? "sudo -E bash -c '#{command}'" : command
|
86
|
-
puts "Running `#{sudo_command}` in #{Dir.pwd}"
|
95
|
+
puts "Running `#{sudo_command}` #{return_hash ? '(quietly)' : ''} in #{Dir.pwd}"
|
87
96
|
|
88
97
|
begin
|
89
98
|
buffer = ''
|
90
99
|
PTY.spawn(sudo_command) do |stdin, stdout, pid|
|
91
100
|
callback = capture ?
|
92
101
|
->(line) {
|
93
|
-
print line
|
102
|
+
print line unless return_hash
|
94
103
|
buffer << line
|
95
104
|
} :
|
96
105
|
->(line) { print line }
|
@@ -99,8 +108,12 @@ module DG
|
|
99
108
|
end
|
100
109
|
status_code = $?.exitstatus
|
101
110
|
|
102
|
-
error!(
|
111
|
+
error!(
|
112
|
+
RuntimeError.new("exit code was #{status_code}"),
|
113
|
+
"executing #{command}"
|
114
|
+
) if !return_hash && status_code != 0
|
103
115
|
|
116
|
+
return { stdout: buffer, status_code: status_code } if return_hash
|
104
117
|
return capture ? buffer : status_code
|
105
118
|
rescue PTY::ChildExited
|
106
119
|
puts "The child process exited!"
|
@@ -138,6 +151,31 @@ module DG
|
|
138
151
|
error!(e, "generating new fig.yml")
|
139
152
|
end
|
140
153
|
|
154
|
+
def reset_mtimes
|
155
|
+
CACHE_FILES.each do |file|
|
156
|
+
next unless File.exist?(file)
|
157
|
+
revision = run_with_output(
|
158
|
+
%(git rev-list -n 1 HEAD '#{file}'),
|
159
|
+
capture = true,
|
160
|
+
return_hash = true
|
161
|
+
)
|
162
|
+
if revision[:status_code] == 0
|
163
|
+
# File exists, find out its last modified time from git
|
164
|
+
# FileUtils.touch('example.txt', mtime: Time.now)
|
165
|
+
time = Time.parse(
|
166
|
+
run_with_output(
|
167
|
+
%(git show --pretty=format:%ai --abbrev-commit #{
|
168
|
+
revision[:stdout].strip} | head -n 1),
|
169
|
+
capture = true,
|
170
|
+
return_hash = true
|
171
|
+
)[:stdout].strip
|
172
|
+
)
|
173
|
+
FileUtils.touch(file, mtime: time)
|
174
|
+
puts "Setting mtime for #{file} to #{time}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
141
179
|
def build_docker_image_with_tag
|
142
180
|
run_with_output("docker build -t #{git_image_name} #{BASEPATH}")
|
143
181
|
rescue => e
|
@@ -191,7 +229,7 @@ module DG
|
|
191
229
|
|
192
230
|
Commands:
|
193
231
|
build Build an image based on your fig.yml (tags with the project's Git commit hash)
|
194
|
-
debug Debug a previously built image (!) THIS MUST BE RUN IN A SUBSHELL: `$(
|
232
|
+
debug Debug a previously built image (!) THIS MUST BE RUN IN A SUBSHELL: `$(dg debug)`
|
195
233
|
deploy Trigger the GoCD pipeline for this project
|
196
234
|
help Display this help text
|
197
235
|
purge Remove ALL docker containers and images (not just for this project!)
|
data/lib/dg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Malet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
DockerGo (DG)
|