miriamtech-gocd 0.2.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/miriamtech/gocd/artifacts.rb +7 -1
- data/lib/miriamtech/gocd/docker.rb +27 -9
- data/lib/miriamtech/gocd/images.rb +4 -7
- data/lib/miriamtech/gocd/tasks.rb +26 -8
- 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: 7af70e5661f15646ef7e1a0ac50f4c00f34993858532ce46e4262ff3105630a6
|
4
|
+
data.tar.gz: 578521f3e2c1447f495ad1e492c20c77513808edbb12330380e442605e6db561
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5004e2f94cce153b400e3cc925063563d3b5aa0d3ea0946adb38016fa4f836b8018aa5dc354b036d76b14d66afe490d62a3226d095f87d5cbd107c7b79401afe
|
7
|
+
data.tar.gz: 1da4ae9b2a174746079bce2327d9d6d5f1d92e34dc4343ce931e2c9c42253f8b219772e5753e1b2e468c2da99652773f04302a62d17585636722c1c6b850aa73
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
miriamtech-gocd (0.
|
4
|
+
miriamtech-gocd (0.4.0)
|
5
5
|
rake (>= 10.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
parser (3.0.1.0)
|
15
15
|
ast (~> 2.4.1)
|
16
16
|
rainbow (3.0.0)
|
17
|
-
rake (13.0.
|
17
|
+
rake (13.0.6)
|
18
18
|
regexp_parser (2.1.1)
|
19
19
|
rexml (3.2.5)
|
20
20
|
rspec-expectations (3.9.2)
|
@@ -53,4 +53,4 @@ DEPENDENCIES
|
|
53
53
|
rubocop-minitest
|
54
54
|
|
55
55
|
BUNDLED WITH
|
56
|
-
2.
|
56
|
+
2.2.31
|
@@ -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
|
@@ -3,21 +3,39 @@ module MiriamTech
|
|
3
3
|
FALSY_ENV_VALUES = (%w[0 f false n no] + ['']).freeze
|
4
4
|
module DSL
|
5
5
|
def project_name(env = ENV)
|
6
|
-
|
6
|
+
pipeline_name = env['GO_PIPELINE_NAME']
|
7
|
+
stage_name = env['GO_STAGE_NAME']
|
8
|
+
job_name = env['GO_JOB_NAME']
|
9
|
+
name = root_path.basename.to_s
|
10
|
+
|
11
|
+
if pipeline_name
|
12
|
+
name = pipeline_name
|
13
|
+
name += "-#{stage_name}" if stage_name
|
14
|
+
name += "-#{job_name}" if job_name
|
15
|
+
end
|
16
|
+
|
17
|
+
name.downcase
|
7
18
|
end
|
8
19
|
|
9
20
|
def build_tag(env = ENV)
|
10
21
|
@build_tag ||= generate_build_tag(env)
|
11
22
|
end
|
12
23
|
|
24
|
+
def build_counter(env = ENV)
|
25
|
+
@build_counter ||= generate_build_counter(env)
|
26
|
+
end
|
27
|
+
|
13
28
|
def docker(string)
|
14
29
|
sh "docker #{string}"
|
15
30
|
end
|
16
31
|
|
17
|
-
def docker_build_arguments(env = ENV)
|
32
|
+
def docker_build_arguments(env = ENV, build_args: {})
|
18
33
|
args = ['--force-rm']
|
19
34
|
no_cache_arg = env['DOCKER_BUILD_NO_CACHE']
|
20
35
|
args << '--no-cache' if no_cache_arg && !FALSY_ENV_VALUES.include?(no_cache_arg)
|
36
|
+
build_args.each do |key, value|
|
37
|
+
args << "--build-arg #{key}=#{value}"
|
38
|
+
end
|
21
39
|
args
|
22
40
|
end
|
23
41
|
|
@@ -30,13 +48,13 @@ module MiriamTech
|
|
30
48
|
private
|
31
49
|
|
32
50
|
def generate_build_tag(env)
|
33
|
-
revision = env['
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
51
|
+
revision = env['GO_REVISION_SOURCE']
|
52
|
+
revision ? ":#{revision}" : ''
|
53
|
+
end
|
54
|
+
|
55
|
+
def generate_build_counter(env)
|
56
|
+
counter = env['GO_PIPELINE_COUNTER']
|
57
|
+
counter ? ":#{counter}" : ''
|
40
58
|
end
|
41
59
|
end
|
42
60
|
end
|
@@ -17,13 +17,10 @@ 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 image.match(/:(\d+)\z/)
|
25
|
-
next unless Regexp.last_match(1).to_i < revision_number - number_to_keep
|
26
|
-
docker "image rm #{image}"
|
20
|
+
images = `docker images --format '"{{.CreatedAt}}" id:{{.ID}}' #{image_name} | sort -r`.split("\n")
|
21
|
+
images.collect { |each| each.split(':').last }.uniq.each_with_index do |image, index|
|
22
|
+
next if index <= number_to_keep
|
23
|
+
docker "image rm --force #{image}"
|
27
24
|
end
|
28
25
|
end
|
29
26
|
end
|
@@ -8,26 +8,31 @@ 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
|
19
20
|
end
|
20
21
|
|
21
22
|
CLEAN.add("#{root_path}/test/reports")
|
22
|
-
task :
|
23
|
-
task :
|
23
|
+
task :stop_containers => [:environment]
|
24
|
+
task :destroy_containers => [:environment, :clean, :cleanup_old_images]
|
25
|
+
|
26
|
+
# These are here for compatibility
|
27
|
+
task :clean => :stop_containers
|
28
|
+
task :clobber => :destroy_containers
|
24
29
|
|
25
30
|
if compose_file.exist?
|
26
|
-
task :
|
31
|
+
task :stop_containers => [:environment] do
|
27
32
|
docker_compose 'stop'
|
28
33
|
end
|
29
34
|
|
30
|
-
task :
|
35
|
+
task :destroy_containers => [:stop_containers] do
|
31
36
|
docker_compose 'rm -fv'
|
32
37
|
end
|
33
38
|
end
|
@@ -37,10 +42,23 @@ module MiriamTech
|
|
37
42
|
end
|
38
43
|
|
39
44
|
task :build => :environment do
|
40
|
-
docker "build #{docker_build_arguments.join(' ')} -t #{image_name}#{build_tag} #{root_path}"
|
45
|
+
docker "build #{docker_build_arguments(build_args: build_args).join(' ')} -t #{image_name}#{build_tag} -t #{image_name}#{build_counter} #{root_path}"
|
46
|
+
end
|
47
|
+
|
48
|
+
task :test => [:environment, :destroy_containers] do
|
49
|
+
at_exit { Rake::Task[:destroy_containers].execute }
|
41
50
|
end
|
42
51
|
|
43
|
-
task :
|
52
|
+
task :save, [:path] => :environment do | t, args |
|
53
|
+
args.with_defaults(path: File.join(root_path, '.docker', 'image.tar'))
|
54
|
+
FileUtils.mkdir_p File.dirname(args[:path])
|
55
|
+
docker "save #{image_name}#{build_tag} -o #{args[:path]}"
|
56
|
+
end
|
57
|
+
|
58
|
+
task :load, :path do | t, args |
|
59
|
+
args.with_defaults(path: File.join(root_path, '.docker', 'image.tar'))
|
60
|
+
docker "load -i #{args[:path]}"
|
61
|
+
end
|
44
62
|
|
45
63
|
task :push do
|
46
64
|
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.5.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:
|
11
|
+
date: 2022-02-15 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
|