hako-codebuild 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hako-codebuild.gemspec +26 -0
- data/lib/hako-codebuild/version.rb +3 -0
- data/lib/hako/scripts/codebuild_tag.rb +60 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -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
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -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
|
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -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).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -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__)
|
data/bin/setup
ADDED
@@ -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,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: []
|