putpaws 0.1.3 → 0.1.4

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: f0adf3a9b8987d214af5c9a2c8348554ef7a34a47bc4ff55a1ea677c628d3fa2
4
- data.tar.gz: 15edd0ace3e1eeded5bc3687fc0f7b02e3189f50bf78255d708308818e861fa1
3
+ metadata.gz: d38b16d5a4fc24915b8bde117f9fda98d0fb6418989eebf98385e86ad724dd32
4
+ data.tar.gz: c3ee3c20989376d82da51e970aa23ab2995af32c39b0e37524c7fa915cf9a8f9
5
5
  SHA512:
6
- metadata.gz: 124c94a1b9b20738b48a2de2fe124847930d7ac4fdc921ae7519fa3b8bbe678a5743514258bbffabb3815aa933377f21ea388ee31600a8e211be49ad76af147c
7
- data.tar.gz: afabd0af48a055ddd0ee8a7e4604700d0fc9b810978a181e6513569d53d9f410ee62cf83e05d34f5ffdb1fdb3c2d42e8c03ded2815316e529df4f568b48d9744
6
+ metadata.gz: e2d00b74e706f5c9192a455bd7919845c4afeb06d2c3db9cd17c2030689cdc2858cc439efb6dd360cc8b9d4eb3fe6fceb6e9a62fb361de1ff0b8d30be4be10c2
7
+ data.tar.gz: 49fbf55b6659a02a563792d4ab406bbe1f583e84abf82eee10c5c52b12bbcb3da42d539fb1346dc10dd4a4a6ba70df427b8ddc5f1b5edf7c07e775c4b314fb72
data/README.md CHANGED
@@ -182,6 +182,15 @@ so you can identify them on the AWS console and on the task list of `ecs:attach`
182
182
  `ecs:run` and `ecs:shell` require `network` and `target` in `.putpaws/application.json`,
183
183
  which refer to the `network` / `target` sections of `.putpaws/infra.json` (the same ones used by scheduler).
184
184
 
185
+ ### CodeBuild
186
+
187
+ Start the CI build. By default it is fire-and-forget; pass `wait=true` to wait
188
+ until the build completes (phases are printed) and exit non-zero on failure.
189
+
190
+ ```
191
+ bundle exec putpaws awesome-api-staging code_build:build branch=main wait=true
192
+ ```
193
+
185
194
  ### CloudWatch Logs
186
195
 
187
196
  `tail -f`
@@ -41,6 +41,23 @@ module Putpaws::CodeBuild
41
41
  codebuild_client.start_build(**params)
42
42
  end
43
43
 
44
+ def wait_until_build_complete(build_id, timeout: 3600, interval: 10)
45
+ deadline = Time.now + timeout
46
+ last_phase = nil
47
+ loop do
48
+ res = codebuild_client.batch_get_builds(ids: [build_id])
49
+ build = res.builds.first
50
+ raise "Build not found: #{build_id}" unless build
51
+ if build.current_phase != last_phase
52
+ last_phase = build.current_phase
53
+ puts " phase: #{last_phase}"
54
+ end
55
+ return build if build.build_status != 'IN_PROGRESS'
56
+ raise "Timed out waiting for build to complete: #{build_id}" if Time.now > deadline
57
+ sleep interval
58
+ end
59
+ end
60
+
44
61
  def build_source_version(type:, version:)
45
62
  type = type.to_sym
46
63
  if type == :branch
@@ -15,7 +15,7 @@ namespace :code_build do
15
15
  set :codebuild_project, codebuild_project
16
16
  end
17
17
 
18
- desc "Start build."
18
+ desc "Start build. Pass wait=true to wait until the build completes and fail on error. (Ex) branch=main wait=true"
19
19
  task build: :set_project do
20
20
  aws = Putpaws::CodeBuild::ProjectCommand.config(fetch(:app))
21
21
 
@@ -30,10 +30,22 @@ namespace :code_build do
30
30
  end
31
31
  codebuild_project = fetch(:codebuild_project)
32
32
  aws.codebuild_project = codebuild_project
33
- aws.start_build_with_specific_version(
34
- source_version: source_version,
35
- environment_variables: ENV['env'] ? JSON.parse(ENV['env']) : {},
33
+ res = aws.start_build_with_specific_version(
34
+ source_version: source_version,
35
+ environment_variables: ENV['env'] ? JSON.parse(ENV['env']) : {},
36
36
  buildspec_override: ENV['buildspec']
37
37
  )
38
+ build = res.build
39
+ puts "Build started: #{build.id}"
40
+
41
+ if ENV['wait']
42
+ puts "Waiting for the build to complete..."
43
+ build = aws.wait_until_build_complete(build.id)
44
+ if build.build_status == 'SUCCEEDED'
45
+ puts "Build succeeded: #{build.id}"
46
+ else
47
+ raise "Build #{build.build_status.downcase}: #{build.id}"
48
+ end
49
+ end
38
50
  end
39
51
  end
@@ -1,3 +1,3 @@
1
1
  module Putpaws
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: putpaws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - metheglin