miriamtech-gocd 0.1.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/run_tests.sh +3 -1
- data/lib/miriamtech/gocd/artifacts.rb +41 -0
- data/lib/miriamtech/gocd/docker.rb +35 -0
- data/lib/miriamtech/gocd/dsl.rb +4 -0
- data/lib/miriamtech/gocd/images.rb +6 -19
- data/lib/miriamtech/gocd/lambda.rb +2 -0
- data/lib/miriamtech/gocd/paths.rb +17 -0
- data/lib/miriamtech/gocd/tasks.rb +45 -0
- data/lib/miriamtech/gocd/version.rb +1 -1
- data/miriamtech-gocd.gemspec +2 -0
- metadata +34 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7af105d0fe88fb0fbcb692f0544c4d8e0dc13ba2215aacc966fe301f1b561702
|
4
|
+
data.tar.gz: da1f9a676b5d24d63f3cd4301a042a1077894e63d71415d348b7ba3ad6f68b0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b66b0848bd393d63fb6983d5d2f14e1ad636b55b4877cde6749abe0788299624eb8738191387ba216506820e1598ca3f84a8c5e86e73b79c6b62db2c4b959627
|
7
|
+
data.tar.gz: 60515e501ddbdecc09810703a91721cf0d1f094df762549847f625db7fc62028b0465540a391e5d1e6563b663295f71b4ada532606b23345bd32b3d1c9b12b8b
|
data/bin/run_tests.sh
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
module MiriamTech
|
2
|
+
module GoCD
|
3
|
+
module DSL
|
4
|
+
def capture_artifacts(prefix = project_name, workdir:, path:, &block)
|
5
|
+
with_artifacts_volume(prefix) do |volume_name|
|
6
|
+
begin
|
7
|
+
yield "-v #{volume_name}:#{workdir}/#{path}"
|
8
|
+
ensure
|
9
|
+
copy_artifacts_from_volume(volume_name, local_path: path)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def with_artifacts_volume(prefix = project_name, &block)
|
15
|
+
artifacts_volume = sanitized_volume_name("#{prefix}#{build_tag}")
|
16
|
+
docker "volume create #{artifacts_volume}"
|
17
|
+
yield artifacts_volume
|
18
|
+
ensure
|
19
|
+
docker "volume rm #{artifacts_volume}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def copy_artifacts_from_volume(volume, local_path:)
|
23
|
+
container_id = `docker create -v #{volume}:/artifacts_volume #{WORKER_IMAGE} cp -a /artifacts_volume /artifacts_tmp`.chomp
|
24
|
+
begin
|
25
|
+
docker "start -i #{container_id}"
|
26
|
+
cd root_path do
|
27
|
+
sh "docker cp #{container_id}:/artifacts_tmp/. #{local_path}"
|
28
|
+
end
|
29
|
+
ensure
|
30
|
+
docker "rm -v #{container_id}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def sanitized_volume_name(name)
|
37
|
+
name.gsub(/[^-_\.A-Za-z0-9]/, '_')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module MiriamTech
|
2
|
+
module GoCD
|
3
|
+
module DSL
|
4
|
+
def project_name(env = ENV)
|
5
|
+
(env['GO_PIPELINE_NAME'] || File.basename(File.expand_path('.'))).downcase
|
6
|
+
end
|
7
|
+
|
8
|
+
def build_tag(env = ENV)
|
9
|
+
@build_tag ||= generate_build_tag(env)
|
10
|
+
end
|
11
|
+
|
12
|
+
def docker(string)
|
13
|
+
sh "docker #{string}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def docker_compose(string)
|
17
|
+
# PIPELINE_NAME = (ENV['GO_PIPELINE_NAME'] || 'ilien').downcase
|
18
|
+
cd root_path do
|
19
|
+
sh "docker-compose -p #{project_name} -f docker-compose.yml #{string}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def generate_build_tag(env)
|
26
|
+
if revision = env['GO_PIPELINE_COUNTER']
|
27
|
+
@build_tag =":#{revision}"
|
28
|
+
else
|
29
|
+
@build_tag = ""
|
30
|
+
end
|
31
|
+
env['BUILD_TAG'] = @build_tag
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/miriamtech/gocd/dsl.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
module MiriamTech
|
2
2
|
module GoCD
|
3
3
|
module DSL
|
4
|
-
|
5
|
-
@build_tag || generate_build_tag
|
6
|
-
end
|
4
|
+
WORKER_IMAGE = 'debian:buster'
|
7
5
|
|
8
6
|
def pull(image_name)
|
9
|
-
|
7
|
+
docker "pull #{image_name}#{build_tag}"
|
10
8
|
end
|
11
9
|
|
12
10
|
def push(image_name, tag = nil)
|
13
11
|
if tag
|
14
|
-
|
15
|
-
|
12
|
+
docker "tag #{image_name}#{build_tag} #{image_name}:#{tag}"
|
13
|
+
docker "push #{image_name}:#{tag}"
|
16
14
|
else
|
17
|
-
|
15
|
+
docker "push #{image_name}#{build_tag}"
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
@@ -25,21 +23,10 @@ module MiriamTech
|
|
25
23
|
images.each do |image|
|
26
24
|
next unless image.match(/:(\d+)\z/)
|
27
25
|
if $1.to_i < revision_number - number_to_keep
|
28
|
-
|
26
|
+
docker "image rm #{image}"
|
29
27
|
end
|
30
28
|
end
|
31
29
|
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def generate_build_tag
|
36
|
-
if revision = ENV['GO_PIPELINE_COUNTER']
|
37
|
-
@build_tag =":#{revision}"
|
38
|
-
else
|
39
|
-
@build_tag = ""
|
40
|
-
end
|
41
|
-
ENV['BUILD_TAG'] = @build_tag
|
42
|
-
end
|
43
30
|
end
|
44
31
|
end
|
45
32
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module MiriamTech
|
4
|
+
module GoCD
|
5
|
+
module DSL
|
6
|
+
def root_path
|
7
|
+
cwd = Pathname.new(File.expand_path('.'))
|
8
|
+
path = Pathname.new(cwd)
|
9
|
+
begin
|
10
|
+
return path if path.join('Dockerfile').exist?
|
11
|
+
path = path.parent
|
12
|
+
end until path.root?
|
13
|
+
cwd
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rake/clean'
|
3
|
+
|
4
|
+
module MiriamTech
|
5
|
+
module GoCD
|
6
|
+
module DSL
|
7
|
+
def define_gocd_tasks(
|
8
|
+
image_name,
|
9
|
+
revisions_to_keep: 10)
|
10
|
+
|
11
|
+
task :default => [:test]
|
12
|
+
task :full => [:clobber, :build]
|
13
|
+
|
14
|
+
CLEAN.add(root_path + '/test/reports')
|
15
|
+
task :clean do
|
16
|
+
docker_compose "stop"
|
17
|
+
end
|
18
|
+
|
19
|
+
task :clobber => :cleanup_old_images do
|
20
|
+
docker_compose "rm -fv"
|
21
|
+
end
|
22
|
+
|
23
|
+
task :cleanup_old_images do
|
24
|
+
cleanup_old_images(image_name, revisions_to_keep)
|
25
|
+
end
|
26
|
+
|
27
|
+
task :build do
|
28
|
+
docker "build --force-rm -t #{image_name}#{build_tag} #{root_path}"
|
29
|
+
end
|
30
|
+
|
31
|
+
task :test
|
32
|
+
|
33
|
+
task :push do
|
34
|
+
push(image_name)
|
35
|
+
push(image_name, 'latest')
|
36
|
+
end
|
37
|
+
|
38
|
+
task :deploy do
|
39
|
+
pull(image_name)
|
40
|
+
push(image_name, 'deployed')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/miriamtech-gocd.gemspec
CHANGED
@@ -29,4 +29,6 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 2.0"
|
30
30
|
spec.add_development_dependency "rake", ">= 10.0"
|
31
31
|
spec.add_development_dependency "minitest", "~> 5.0"
|
32
|
+
spec.add_development_dependency 'rspec-expectations'
|
33
|
+
spec.add_development_dependency 'rspec-mocks'
|
32
34
|
end
|
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.2.4
|
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: 2020-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-expectations
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-mocks
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description:
|
56
84
|
email:
|
57
85
|
- ken@miriamtech.com
|
@@ -69,9 +97,13 @@ files:
|
|
69
97
|
- bin/run_tests.sh
|
70
98
|
- bin/setup
|
71
99
|
- lib/miriamtech/gocd.rb
|
100
|
+
- lib/miriamtech/gocd/artifacts.rb
|
101
|
+
- lib/miriamtech/gocd/docker.rb
|
72
102
|
- lib/miriamtech/gocd/dsl.rb
|
73
103
|
- lib/miriamtech/gocd/images.rb
|
74
104
|
- lib/miriamtech/gocd/lambda.rb
|
105
|
+
- lib/miriamtech/gocd/paths.rb
|
106
|
+
- lib/miriamtech/gocd/tasks.rb
|
75
107
|
- lib/miriamtech/gocd/version.rb
|
76
108
|
- miriamtech-gocd.gemspec
|
77
109
|
homepage: https://www.miriamtech.com
|