Skip to content

Commit

Permalink
better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
skaes committed Feb 9, 2024
1 parent eca4042 commit 3bfd1d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
2 changes: 0 additions & 2 deletions lib/fpm/fry/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,6 @@ def create(image)

def destroy(container)
return unless container
logger.info("destroying container #{container}")
logger.info(caller.join("\n"))

url = self.url('containers', container)
res = agent.delete(
Expand Down
25 changes: 13 additions & 12 deletions lib/fpm/fry/command/cook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
module FPM; module Fry
class Command::Cook < Command

class BuildFailed < StandardError
include FPM::Fry::WithData
end

option '--keep', :flag, 'Keep the container after build'
option '--overwrite', :flag, 'Overwrite package', default: true
option '--verbose', :flag, 'Verbose output', default: false
Expand Down Expand Up @@ -213,15 +217,13 @@ def pull_base_image!

def build!
container = create_build_container
begin
start_build_container(container)
attach_to_build_container_and_stream_logs(container)
wait_for_build_container_to_shut_down(container)
yield container
ensure
unless keep?
client.destroy(container)
end
start_build_container(container)
attach_to_build_container_and_stream_logs(container)
wait_for_build_container_to_shut_down(container)
yield container
ensure
unless keep?
client.destroy(container) if container
end
end

Expand Down Expand Up @@ -260,7 +262,7 @@ def start_build_container(container)

def attach_to_build_container_and_stream_logs(container)
url = client.url('containers',container,'attach?stderr=1&stdout=1&stream=1&logs=1')
res = client.post(
client.post(
path: url,
body: '',
expects: [200],
Expand All @@ -271,7 +273,6 @@ def attach_to_build_container_and_stream_logs(container)
Excon::Middleware::Mock
]
)
puts "----> #{res.inspect} <------"
rescue Excon::Error
logger.error "could not attach to container #{container}, url: #{url}"
raise
Expand All @@ -285,7 +286,7 @@ def wait_for_build_container_to_shut_down(container)
)
json = JSON.parse(res.body)
if json["StatusCode"] != 0
raise Fry::WithData("Build failed", json)
raise BuildFailed.new("Build failed", json)
end
rescue Excon::Error
logger.error "could not wait successfully for container #{container}, url: #{url}"
Expand Down

0 comments on commit 3bfd1d0

Please sign in to comment.