miriamtech-gocd 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 90f71635373adde9608df1adc1c8f6d9049ba4cb4b8d0701685b6d9765149f60
4
+ data.tar.gz: b1a5730065101e6c5a878ffc0ada32e63d38bac6e0b3e51af3273e155abb176b
5
+ SHA512:
6
+ metadata.gz: a8599fd38d61b862666129dbb371ba6a1c3dc875c9e1df30a864b96e2b516c8b3f076839f24bef74b1c1fd9eb6edba8261c6e9e65ee0e7bdf0b2fe066c15660b
7
+ data.tar.gz: e8cc17e24f9d678a82dc2909385401af2b8f5c64ae1a990b0a7092656f4ddc1bd9106884f633678f64016697ed791ccaef4786a10f5cd7ad257a1134d23ce4fd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.5
7
+ before_install: gem install bundler -v 2.0.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ Initial release.
6
+
7
+ * Core: `build_tag`
8
+ * Docker: `push`, `pull`, `cleanup_old_images`
9
+ * AWS: `invoke_lambda`
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in miriamtech-gocd.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # MiriamTech::GoCD
2
+
3
+ This is a library of common code for our GoCD pipelines.
4
+
5
+ ## Usage
6
+
7
+ In your Rakefile, use:
8
+
9
+ ```
10
+ require 'miriamtech/gocd'
11
+ ```
12
+
13
+ ## Development
14
+
15
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
16
+
17
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
18
+
19
+ ## Contributing
20
+
21
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/miriamtech-gocd.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "miriamtech/gocd"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/run_tests.sh ADDED
@@ -0,0 +1,25 @@
1
+ #!/bin/bash -e
2
+ #
3
+ # Invoke me from Atom with:
4
+ # All: bin/run_tests.sh
5
+ # File: bin/run_tests.sh {relative_path}
6
+ # Single: bin/run_tests.sh {relative_path} {line_number} "{regex}"
7
+
8
+ FILENAME=$1
9
+ LINE_NUMBER=$2
10
+ TEST_NAME=$3
11
+
12
+ COMMAND="ruby -Itest"
13
+ export BUILD_TAG=""
14
+
15
+ if [ ! -z "${TEST_NAME}" ]; then
16
+ if [[ "${TEST_NAME}" =~ 'test_' ]]; then
17
+ METHOD_NAME=${TEST_NAME}
18
+ else
19
+ METHOD_NAME=test_${TEST_NAME//[[:space:]]/_}
20
+ fi
21
+ echo "Running: ${METHOD_NAME}"
22
+ ${COMMAND} ${FILENAME} --name "${METHOD_NAME}"
23
+ else
24
+ ${COMMAND} ${FILENAME}
25
+ fi
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,2 @@
1
+ require "miriamtech/gocd/version"
2
+ require "miriamtech/gocd/dsl"
@@ -0,0 +1,4 @@
1
+ require_relative 'images'
2
+ require_relative 'lambda'
3
+
4
+ self.extend MiriamTech::GoCD::DSL
@@ -0,0 +1,45 @@
1
+ module MiriamTech
2
+ module GoCD
3
+ module DSL
4
+ def build_tag
5
+ @build_tag || generate_build_tag
6
+ end
7
+
8
+ def pull(image_name)
9
+ sh "docker pull #{image_name}#{build_tag}"
10
+ end
11
+
12
+ def push(image_name, tag = nil)
13
+ if tag
14
+ sh "docker tag #{image_name}#{build_tag} #{image_name}:#{tag}"
15
+ sh "docker push #{image_name}:#{tag}"
16
+ else
17
+ sh "docker push #{image_name}#{build_tag}"
18
+ end
19
+ end
20
+
21
+ def cleanup_old_images(image_name, number_to_keep)
22
+ revision_number = ENV["GO_PIPELINE_COUNTER"].to_i
23
+ return unless revision_number > number_to_keep
24
+ images = `docker images --format "{{.Repository}}:{{.Tag}}" #{image_name}`.split(/\s+/)
25
+ images.each do |image|
26
+ next unless image.match(/:(\d+)\z/)
27
+ if $1.to_i < revision_number - number_to_keep
28
+ sh "docker image rm #{image}"
29
+ end
30
+ end
31
+ 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
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ module MiriamTech
2
+ module GoCD
3
+ module DSL
4
+ def invoke_lambda(lambda)
5
+ Tempfile.open(lambda) do |temp|
6
+ sh "aws lambda invoke --function-name #{lambda} #{temp.path}"
7
+ puts temp.read
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module MiriamTech
2
+ module GoCD
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "miriamtech/gocd/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "miriamtech-gocd"
7
+ spec.version = MiriamTech::GoCD::VERSION
8
+ spec.authors = ["Ken Treis"]
9
+ spec.email = ["ken@miriamtech.com"]
10
+
11
+ spec.summary = %q{Utilities for building apps in Docker containers with GoCD}
12
+ spec.homepage = "https://www.miriamtech.com"
13
+
14
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/miriamtech/gocd"
18
+ spec.metadata["changelog_uri"] = "https://github.com/miriamtech/gocd/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
+ spec.add_development_dependency "rake", ">= 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: miriamtech-gocd
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ken Treis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description:
56
+ email:
57
+ - ken@miriamtech.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/run_tests.sh
70
+ - bin/setup
71
+ - lib/miriamtech/gocd.rb
72
+ - lib/miriamtech/gocd/dsl.rb
73
+ - lib/miriamtech/gocd/images.rb
74
+ - lib/miriamtech/gocd/lambda.rb
75
+ - lib/miriamtech/gocd/version.rb
76
+ - miriamtech-gocd.gemspec
77
+ homepage: https://www.miriamtech.com
78
+ licenses: []
79
+ metadata:
80
+ allowed_push_host: https://rubygems.org
81
+ homepage_uri: https://www.miriamtech.com
82
+ source_code_uri: https://github.com/miriamtech/gocd
83
+ changelog_uri: https://github.com/miriamtech/gocd/blob/master/CHANGELOG.md
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.7.6.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Utilities for building apps in Docker containers with GoCD
104
+ test_files: []