miriamtech-gocd 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 90f71635373adde9608df1adc1c8f6d9049ba4cb4b8d0701685b6d9765149f60
4
- data.tar.gz: b1a5730065101e6c5a878ffc0ada32e63d38bac6e0b3e51af3273e155abb176b
3
+ metadata.gz: 8a10182274162c0b910f57a828489a5e86fa51db950d91587edd67f0b615f559
4
+ data.tar.gz: c6cc4e741228ce382ec5d560e18cc413f533aaa022d1f652ac5c13485b28985c
5
5
  SHA512:
6
- metadata.gz: a8599fd38d61b862666129dbb371ba6a1c3dc875c9e1df30a864b96e2b516c8b3f076839f24bef74b1c1fd9eb6edba8261c6e9e65ee0e7bdf0b2fe066c15660b
7
- data.tar.gz: e8cc17e24f9d678a82dc2909385401af2b8f5c64ae1a990b0a7092656f4ddc1bd9106884f633678f64016697ed791ccaef4786a10f5cd7ad257a1134d23ce4fd
6
+ metadata.gz: e01bb5e1af5fc7b3371e0c9ec67757e54c3c0bac6ed75b867218d25d08c12bd511a3090ed863b5499c0b7acf27008cf4852ac1e03b84a0e8dbd376bc4b0223b2
7
+ data.tar.gz: 9b5bf6810a10726ee56810a24fdf3d17031b06a68dd92c1dd30887262f5a70ae563a8657afa21ef2dbf9fc0a8c3c338f737735f0d624567f170a67ab50844808
@@ -20,6 +20,8 @@ if [ ! -z "${TEST_NAME}" ]; then
20
20
  fi
21
21
  echo "Running: ${METHOD_NAME}"
22
22
  ${COMMAND} ${FILENAME} --name "${METHOD_NAME}"
23
- else
23
+ elif [ ! -z "${FILENAME}" ]; then
24
24
  ${COMMAND} ${FILENAME}
25
+ else
26
+ rake
25
27
  fi
@@ -0,0 +1,25 @@
1
+ module MiriamTech
2
+ module GoCD
3
+ module DSL
4
+ def with_artifacts_volume(prefix = project_name, &block)
5
+ artifacts_volume = "#{prefix}#{build_tag}".gsub('[/:]', '_')
6
+ docker "volume create #{artifacts_volume}"
7
+ yield artifacts_volume
8
+ ensure
9
+ docker "volume rm #{artifacts_volume}"
10
+ end
11
+
12
+ def copy_artifacts_from_volume(volume, local_path:)
13
+ container_id = `docker create -v #{volume}:/artifacts_volume #{WORKER_IMAGE} cp -a /artifacts_volume /artifacts_tmp`.chomp
14
+ begin
15
+ docker "start -i #{container_id}"
16
+ cd root_path do
17
+ sh "docker cp #{container_id}:/artifacts_tmp/. #{local_path}"
18
+ end
19
+ ensure
20
+ docker "rm -v #{container_id}"
21
+ end
22
+ end
23
+ end
24
+ end
25
+ 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
@@ -1,4 +1,8 @@
1
+ require_relative 'artifacts'
2
+ require_relative 'docker'
1
3
  require_relative 'images'
2
4
  require_relative 'lambda'
5
+ require_relative 'paths'
6
+ require_relative 'tasks'
3
7
 
4
8
  self.extend MiriamTech::GoCD::DSL
@@ -1,20 +1,18 @@
1
1
  module MiriamTech
2
2
  module GoCD
3
3
  module DSL
4
- def build_tag
5
- @build_tag || generate_build_tag
6
- end
4
+ WORKER_IMAGE = 'debian:buster'
7
5
 
8
6
  def pull(image_name)
9
- sh "docker pull #{image_name}#{build_tag}"
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
- sh "docker tag #{image_name}#{build_tag} #{image_name}:#{tag}"
15
- sh "docker push #{image_name}:#{tag}"
12
+ docker "tag #{image_name}#{build_tag} #{image_name}:#{tag}"
13
+ docker "push #{image_name}:#{tag}"
16
14
  else
17
- sh "docker push #{image_name}#{build_tag}"
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
- sh "docker image rm #{image}"
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,44 @@
1
+ require 'pathname'
2
+
3
+ module MiriamTech
4
+ module GoCD
5
+ module DSL
6
+ def define_gocd_tasks(
7
+ image_name,
8
+ revisions_to_keep: 10)
9
+
10
+ task :default => [:test]
11
+ task :full => [:clobber, :build]
12
+
13
+ CLEAN.add(root_path + '/test/reports')
14
+ task :clean do
15
+ docker_compose "stop"
16
+ end
17
+
18
+ task :clobber => :cleanup_old_images do
19
+ docker_compose "rm -fv"
20
+ end
21
+
22
+ task :cleanup_old_images do
23
+ cleanup_old_images(image_name, revisions_to_keep)
24
+ end
25
+
26
+ task :build do
27
+ docker "build --force-rm -t #{image_name}#{build_tag} #{root_path}"
28
+ end
29
+
30
+ task :test
31
+
32
+ task :push do
33
+ push(image_name)
34
+ push(image_name, 'latest')
35
+ end
36
+
37
+ task :deploy do
38
+ pull(image_name)
39
+ push(image_name, 'deployed')
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,5 +1,5 @@
1
1
  module MiriamTech
2
2
  module GoCD
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  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.1.0
4
+ version: 0.2.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: 2019-10-30 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -69,9 +69,13 @@ files:
69
69
  - bin/run_tests.sh
70
70
  - bin/setup
71
71
  - lib/miriamtech/gocd.rb
72
+ - lib/miriamtech/gocd/artifacts.rb
73
+ - lib/miriamtech/gocd/docker.rb
72
74
  - lib/miriamtech/gocd/dsl.rb
73
75
  - lib/miriamtech/gocd/images.rb
74
76
  - lib/miriamtech/gocd/lambda.rb
77
+ - lib/miriamtech/gocd/paths.rb
78
+ - lib/miriamtech/gocd/tasks.rb
75
79
  - lib/miriamtech/gocd/version.rb
76
80
  - miriamtech-gocd.gemspec
77
81
  homepage: https://www.miriamtech.com