hako-codebuild 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43c32f9ace72090ba04ada0eeb7d3f685d3b65c931ae92dd35086e93fbcc97c5
4
+ data.tar.gz: 1a9f0fa56ff12482fd4b5bd7e6fafbb98a628ac4feb3d88c20b1cd091d6cd4ba
5
+ SHA512:
6
+ metadata.gz: a7fad80e25ecb5762b6cca592a05e03554630043716080c0ba87ce2f941f226eb28d2948a9aaea7db96a809df37eab865740dbaa9b0067f8c07401a70734b23d
7
+ data.tar.gz: 745733672707c2f4503b303a63f00702ee9320ddf8a674838db8635e07b7120e938f308e83bf396fb5f58117cd6bc341e645b0b941abaca43346c55d3f8629be
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in hako-codebuild.gemspec
6
+ gemspec
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ hako-codebuild (0.1.0)
5
+ aws-sdk-codebuild
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ aws-eventstream (1.0.1)
11
+ aws-partitions (1.96.0)
12
+ aws-sdk-codebuild (1.13.0)
13
+ aws-sdk-core (~> 3)
14
+ aws-sigv4 (~> 1.0)
15
+ aws-sdk-core (3.22.1)
16
+ aws-eventstream (~> 1.0)
17
+ aws-partitions (~> 1.0)
18
+ aws-sigv4 (~> 1.0)
19
+ jmespath (~> 1.0)
20
+ aws-sigv4 (1.0.3)
21
+ jmespath (1.4.0)
22
+ rake (12.3.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler
29
+ hako-codebuild!
30
+ rake
31
+
32
+ BUNDLED WITH
33
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Sorah Fukumori
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # hako-codebuild
2
+
3
+ [hako](https://github.com/eagletmt/hako) scripts to update image tag of `app` container to the commit SHA of the latest succeeded build in a specified CodeBuild project
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'hako-codebuild'
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ``` jsonnet
14
+ {
15
+ scripts: [
16
+ {
17
+ type: 'codebuild_tag',
18
+ region: 'us-west-2',
19
+ project: 'your-codebuild-project',
20
+ },
21
+ ],
22
+ }
23
+ ```
24
+
25
+ ```
26
+ hako deploy --tag codebuild your-app.jsonnet
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sorah/hako-codebuild.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hako/codebuild"
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__)
@@ -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,26 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "hako-codebuild/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hako-codebuild"
7
+ spec.version = HakoCodebuild::VERSION
8
+ spec.authors = ["Sorah Fukumori"]
9
+ spec.email = ["her@sorah.jp"]
10
+
11
+ spec.summary = %q{Hako script to retrieve a latest commit from AWS CodeBuild as a image tag}
12
+ spec.homepage = "https://github.com/sorah/hako-codebuild"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "aws-sdk-codebuild"
23
+
24
+ spec.add_development_dependency "bundler"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,3 @@
1
+ module HakoCodebuild
2
+ VERSION="0.1.0"
3
+ end
@@ -0,0 +1,60 @@
1
+ require 'hako/script'
2
+ require 'aws-sdk-codebuild'
3
+
4
+ module Hako
5
+ module Scripts
6
+ class CodebuildTag < Script
7
+ class NoSuccessfulBuildError < StandardError; end
8
+
9
+ TARGET_TAG = 'codebuild'
10
+
11
+ def configure(options)
12
+ super
13
+ @region = options['region']
14
+ @project_name = options.fetch('project', @app.id)
15
+ end
16
+
17
+ def deploy_starting(containers)
18
+ app = containers.fetch('app')
19
+ if app.definition['tag'] == TARGET_TAG
20
+ rewrite_tag(app)
21
+ end
22
+ end
23
+
24
+ alias_method :oneshot_starting, :deploy_starting
25
+
26
+ def codebuild
27
+ @codebuild ||= begin
28
+ options = {}
29
+ options[:region] = @region if @region
30
+ Aws::CodeBuild::Client.new(options)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def rewrite_tag(app)
37
+ tag = fetch_version
38
+ app.definition['tag'] = tag
39
+ Hako.logger.info("Rewrite tag to #{app.image_tag}")
40
+ end
41
+
42
+ def fetch_version
43
+ codebuild.list_builds_for_project(project_name: @project_name, sort_order: 'DESCENDING').each do |page|
44
+ builds = codebuild.batch_get_builds(ids: page.ids).builds.map do |build|
45
+ [build.id, build]
46
+ end.to_h
47
+
48
+ page.ids.each do |id|
49
+ build = builds.fetch(id)
50
+ next unless build.build_status == 'SUCCEEDED'
51
+ return build.source_version
52
+ end
53
+ end
54
+ raise NoSuccessfulBuildError
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hako-codebuild
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sorah Fukumori
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk-codebuild
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - her@sorah.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - hako-codebuild.gemspec
72
+ - lib/hako-codebuild/version.rb
73
+ - lib/hako/scripts/codebuild_tag.rb
74
+ homepage: https://github.com/sorah/hako-codebuild
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.1.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Hako script to retrieve a latest commit from AWS CodeBuild as a image tag
97
+ test_files: []