miriamtech-gocd 0.2.8 → 0.3.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 +4 -4
- data/lib/miriamtech/gocd/artifacts.rb +7 -1
- data/lib/miriamtech/gocd/docker.rb +15 -8
- data/lib/miriamtech/gocd/images.rb +6 -7
- data/lib/miriamtech/gocd/tasks.rb +23 -6
- data/lib/miriamtech/gocd/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f793b1d04ccfb06de74c6ce2cb193465fceab73cea6eec430fdba9fdc70914b
|
4
|
+
data.tar.gz: d2cbd3b72c3eeef2dd71fa92cf5972cc585e9e68d86d9fd0475678324b500e84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6c30bad571ed57e23fe61a300c8994d19fa40edd697f33dc449a5669b97a2213f0d14db3cd9896b8bd36cc89728ae02bdfd0f27ab8c4e5d6d45b78bb4427597
|
7
|
+
data.tar.gz: ab5fa74f84b309d6f5daabfaf5a157f54f0245c7e62284157a98c40d285bb8b88acab36c796b0d76e66d910307ef781771a834c27657225395cd93186bf6da85
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
module MiriamTech
|
2
4
|
module GoCD
|
3
5
|
module DSL
|
@@ -10,7 +12,7 @@ module MiriamTech
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def with_artifacts_volume(prefix = project_name)
|
13
|
-
artifacts_volume = sanitized_volume_name("#{prefix}#{
|
15
|
+
artifacts_volume = sanitized_volume_name("#{prefix}_#{random_hex}")
|
14
16
|
docker "volume create #{artifacts_volume}"
|
15
17
|
yield artifacts_volume
|
16
18
|
ensure
|
@@ -34,6 +36,10 @@ module MiriamTech
|
|
34
36
|
def sanitized_volume_name(name)
|
35
37
|
name.gsub(/[^-_.A-Za-z0-9]/, '_')
|
36
38
|
end
|
39
|
+
|
40
|
+
def random_hex
|
41
|
+
SecureRandom.hex
|
42
|
+
end
|
37
43
|
end
|
38
44
|
end
|
39
45
|
end
|
@@ -10,14 +10,21 @@ module MiriamTech
|
|
10
10
|
@build_tag ||= generate_build_tag(env)
|
11
11
|
end
|
12
12
|
|
13
|
+
def build_counter(env = ENV)
|
14
|
+
@build_counter ||= generate_build_counter(env)
|
15
|
+
end
|
16
|
+
|
13
17
|
def docker(string)
|
14
18
|
sh "docker #{string}"
|
15
19
|
end
|
16
20
|
|
17
|
-
def docker_build_arguments(env = ENV)
|
21
|
+
def docker_build_arguments(env = ENV, build_args: {})
|
18
22
|
args = ['--force-rm']
|
19
23
|
no_cache_arg = env['DOCKER_BUILD_NO_CACHE']
|
20
24
|
args << '--no-cache' if no_cache_arg && !FALSY_ENV_VALUES.include?(no_cache_arg)
|
25
|
+
build_args.each do |key, value|
|
26
|
+
args << "--build-arg #{key}=#{value}"
|
27
|
+
end
|
21
28
|
args
|
22
29
|
end
|
23
30
|
|
@@ -30,13 +37,13 @@ module MiriamTech
|
|
30
37
|
private
|
31
38
|
|
32
39
|
def generate_build_tag(env)
|
33
|
-
revision = env['
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
+
revision = env['GO_REVISION_SOURCE']
|
41
|
+
revision ? ":#{revision}" : ''
|
42
|
+
end
|
43
|
+
|
44
|
+
def generate_build_counter(env)
|
45
|
+
counter = env['GO_PIPELINE_COUNTER']
|
46
|
+
counter ? ":#{counter}" : ''
|
40
47
|
end
|
41
48
|
end
|
42
49
|
end
|
@@ -17,13 +17,12 @@ module MiriamTech
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def cleanup_old_images(image_name, number_to_keep)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
next unless
|
25
|
-
|
26
|
-
docker "image rm #{image}"
|
20
|
+
images = `docker images --format '"{{.CreatedAt}}" id:{{.ID}}' #{image_name} | sort -r`.split("\n")
|
21
|
+
images.each_with_index do |image, index|
|
22
|
+
next if index >= number_to_keep
|
23
|
+
match = image.match(/id:(.*)\z/)
|
24
|
+
next unless match
|
25
|
+
docker "image rm --force #{match[1]}"
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
@@ -8,11 +8,12 @@ module MiriamTech
|
|
8
8
|
|
9
9
|
def define_gocd_tasks(
|
10
10
|
image_name,
|
11
|
-
revisions_to_keep: 10
|
11
|
+
revisions_to_keep: 10,
|
12
|
+
build_args: {}
|
12
13
|
)
|
13
14
|
|
14
15
|
task :default => [:test]
|
15
|
-
task :full => [:
|
16
|
+
task :full => [:destroy_containers, :build]
|
16
17
|
|
17
18
|
task :environment do
|
18
19
|
ENV['BUILD_TAG'] = build_tag
|
@@ -20,14 +21,17 @@ module MiriamTech
|
|
20
21
|
|
21
22
|
CLEAN.add("#{root_path}/test/reports")
|
22
23
|
task :clean => [:environment]
|
23
|
-
task :
|
24
|
+
task :destroy_containers => [:environment, :clean, :cleanup_old_images]
|
25
|
+
|
26
|
+
# This is here for compatibility
|
27
|
+
task :clobber => :destroy_containers
|
24
28
|
|
25
29
|
if compose_file.exist?
|
26
30
|
task :clean do
|
27
31
|
docker_compose 'stop'
|
28
32
|
end
|
29
33
|
|
30
|
-
task :
|
34
|
+
task :destroy_containers do
|
31
35
|
docker_compose 'rm -fv'
|
32
36
|
end
|
33
37
|
end
|
@@ -37,10 +41,23 @@ module MiriamTech
|
|
37
41
|
end
|
38
42
|
|
39
43
|
task :build => :environment do
|
40
|
-
docker "build #{docker_build_arguments.join(' ')} -t #{image_name}#{build_tag} #{root_path}"
|
44
|
+
docker "build #{docker_build_arguments(build_args: build_args).join(' ')} -t #{image_name}#{build_tag} -t #{image_name}#{build_counter} #{root_path}"
|
45
|
+
end
|
46
|
+
|
47
|
+
task :test => [:environment, :destroy_containers] do
|
48
|
+
at_exit { Rake::Task[:destroy_containers].execute }
|
41
49
|
end
|
42
50
|
|
43
|
-
task :
|
51
|
+
task :save, [:path] => :environment do | t, args |
|
52
|
+
args.with_defaults(path: File.join(root_path, '.docker', 'image.tar'))
|
53
|
+
FileUtils.mkdir_p File.dirname(args[:path])
|
54
|
+
docker "save #{image_name}#{build_tag} -o #{args[:path]}"
|
55
|
+
end
|
56
|
+
|
57
|
+
task :load, :path do | t, args |
|
58
|
+
args.with_defaults(path: File.join(root_path, '.docker', 'image.tar'))
|
59
|
+
docker "load -i #{args[:path]}"
|
60
|
+
end
|
44
61
|
|
45
62
|
task :push do
|
46
63
|
push(image_name)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miriamtech-gocd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Treis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -159,8 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
159
159
|
- !ruby/object:Gem::Version
|
160
160
|
version: '0'
|
161
161
|
requirements: []
|
162
|
-
|
163
|
-
rubygems_version: 2.7.6.2
|
162
|
+
rubygems_version: 3.2.5
|
164
163
|
signing_key:
|
165
164
|
specification_version: 4
|
166
165
|
summary: Utilities for building apps in Docker containers with GoCD
|