From c8834c1440e44f978ecffe09f77a05b9924121f8 Mon Sep 17 00:00:00 2001 From: Jonathan Lehman Date: Tue, 31 Jan 2017 17:26:17 -0500 Subject: [PATCH] Set REQUEST_ID env --- README.md | 1 + lib/slugbuilder/builder.rb | 6 ++++-- spec/slugbuilder/builder_spec.rb | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 60d10b8..b674a56 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,7 @@ Alternatively, a block can be passed to the `initialize` method to the same effe - `repo` String: The git repo identifier - `git_ref` String: The git branchname or SHA - `git_sha` String: The git SHA (even if the git ref was a branch name) + - `request_id` String: The unique id of the build request - `stats` Hash: - setup `Float`: Amount of time spent in setup - build `Float`: Total amount of time spent in build (compile/build/slug) diff --git a/lib/slugbuilder/builder.rb b/lib/slugbuilder/builder.rb index eb3c025..768af4a 100644 --- a/lib/slugbuilder/builder.rb +++ b/lib/slugbuilder/builder.rb @@ -45,9 +45,9 @@ def build(clear_cache: false, env: {}, prebuild: nil, postbuild: nil, slug_name: output: build_output.join('') } - postbuild.call(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, stats: stats, slug: File.join(@output_dir, @slug_file)) if postbuild + postbuild.call(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, request_id: @request_id, stats: stats, slug: File.join(@output_dir, @slug_file)) if postbuild if block_given? - yield(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, stats: stats, slug: File.join(@output_dir, @slug_file)) + yield(repo: @repo, git_ref: @git_ref, git_sha: @git_sha, request_id: @request_id, stats: stats, slug: File.join(@output_dir, @slug_file)) end return true rescue => e @@ -94,6 +94,8 @@ def set_environment load_env_file("#{@cache_dir}/env") load_env_file("#{@build_dir}/.env") ENV['STACK'] = 'cedar-14' + @request_id = SecureRandom.urlsafe_base64(32) + ENV['REQUEST_ID'] = @request_id @env.each do |k, v| ENV[k.to_s] = v.to_s diff --git a/spec/slugbuilder/builder_spec.rb b/spec/slugbuilder/builder_spec.rb index 14f1e6c..452c76b 100644 --- a/spec/slugbuilder/builder_spec.rb +++ b/spec/slugbuilder/builder_spec.rb @@ -102,14 +102,14 @@ def self.call(args) it 'accepts a postbuild Proc' do my_proc = ->(args) do - expect(args.keys).to include(:repo, :git_ref, :git_sha, :stats, :slug) + expect(args.keys).to include(:repo, :git_ref, :git_sha, :request_id, :stats, :slug) end builder.build(postbuild: my_proc) end it 'accepts a postbuild block' do builder.build do |args| - expect(args.keys).to include(:repo, :git_ref, :git_sha, :stats, :slug) + expect(args.keys).to include(:repo, :git_ref, :git_sha, :request_id, :stats, :slug) end end end