{"action":"created","comment":{"url":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/comments/61883163","id":61883163,"diff_hunk":"@@ -16,163 +16,125 @@\n # See the License for the specific language governing permissions and\n # limitations under the License.\n #\n-require_relative 'helper'\n \n-class Chef\n-  class Resource::OmnibusBuild < Resource::LWRPBase\n-    resource_name :omnibus_build\n-\n-    actions :execute\n-    default_action :execute\n-\n-    attribute :project_name,\n-              kind_of: String,\n-              name_attribute: true\n-    attribute :project_dir,\n-              kind_of: String,\n-              required: true\n-    attribute :install_dir,\n-              kind_of: String,\n-              default: lazy { |r| Chef::Platform.windows? ? ::File.join(ENV['SYSTEMDRIVE'], r.project_name) : \"/opt/#{r.project_name}\" }\n-    attribute :base_dir,\n-              kind_of: String,\n-              default: lazy { Chef::Platform.windows? ? ::File.join(ENV['SYSTEMDRIVE'], 'omnibus-ruby') : '/var/cache/omnibus' }\n-    attribute :log_level,\n-              kind_of: Symbol,\n-              equal_to: [:internal, :debug, :info, :warn, :error, :fatal],\n-              default: :internal\n-    attribute :config_file,\n-              kind_of: String,\n-              default: lazy { |r| ::File.join(r.project_dir, 'omnibus.rb') }\n-    attribute :config_overrides,\n-              kind_of: Hash,\n-              default: {}\n-    attribute :expire_cache,\n-              kind_of: [TrueClass, FalseClass],\n-              default: false\n-    attribute :build_user,\n-              kind_of: String,\n-              default: lazy { |r| r.node['omnibus']['build_user'] }\n-    attribute :environment,\n-              kind_of: Hash,\n-              default: {}\n-  end\n+module OmnibusCookbook\n+  class OmnibusBuild < Chef::Resource\n+    require_relative 'helper'\n \n-  class Provider::OmnibusBuild < Provider::LWRPBase\n-    include Omnibus::Helper\n+    resource_name :omnibus_build\n \n     provides :omnibus_build\n \n+    property :project_name, String, name_property: true\n+    property :project_dir, String, required: true\n+    property :install_dir, String, default: lazy { default_install_dir }\n+    property :base_dir, String, default: lazy { default_base_dir }\n+    property :log_level, [:internal, :debug, :info, :warn, :error, :fatal], default: :internal\n+    property :config_file, String, default: lazy { default_config_file }\n+    property :config_overrides, Hash, default: {}\n+    property :expire_cache, [TrueClass, FalseClass], default: false\n+    property :build_user, String, default: lazy { node['omnibus']['build_user'] } # evil. leaving for back-compat. should be removed.\n+    property :environment, Hash, default: lazy { default_environment }\n+\n+    # Enable why-run\n     def whyrun_supported?\n       true\n     end\n \n-    action(:execute) do\n-      converge_by(\"execute #{new_resource}\") do\n-        prepare_build_enviornment\n-        # bundle install\n-        execute_with_omnibus_toolchain(bundle_install_command)\n-        # omnibus build\n-        execute_with_omnibus_toolchain(\"bundle exec #{build_command}\")\n-      end\n-    end\n-\n-    protected\n-\n-    def bundle_install_command\n-      if ::File.exist?(::File.join(new_resource.project_dir, 'Gemfile.lock'))\n-        'bundle install --without development --deployment'\n-      else\n-        'bundle install --without development --path vendor/bundle'\n-      end\n-    end\n-\n-    def build_command\n-      [\n-        'omnibus',\n-        'build',\n-        new_resource.project_name,\n-        \"--log-level #{new_resource.log_level}\",\n-        \"--config #{new_resource.config_file}\",\n-        new_resource.config_overrides.empty? ? '' : \"--override #{new_resource.config_overrides.map { |k, v| \"#{k}:#{v}\" }.join(' ')}\"\n-      ].join(' ')\n+    #######################################\n+    # helpers for default property settings\n+    #######################################\n+    def default_install_dir\n+      Chef::Platform.windows? ? ::File.join(ENV['SYSTEMDRIVE'], project_name) : \"/opt/#{project_name}\"\n     end\n \n-    def prepare_build_enviornment\n-      # Optionally wipe all caches (including the git cache)\n-      if new_resource.expire_cache\n-        cache = Resource::Directory.new(new_resource.base_dir, run_context)\n-        cache.recursive(true)\n-        cache.run_action(:delete)\n-      end\n-\n-      # Clean up various directories from the last build\n-      %W(\n-        #{new_resource.base_dir}/build/#{new_resource.project_name}/*.manifest\n-        #{new_resource.base_dir}/pkg\n-        #{new_resource.project_dir}/pkg\n-        #{new_resource.install_dir}\n-      ).each do |directory|\n-        d = Resource::Directory.new(directory, run_context)\n-        d.recursive(true)\n-        d.run_action(:delete)\n-      end\n-\n-      # Create required build directories with the correct ownership\n-      %W(\n-        #{new_resource.base_dir}\n-        #{new_resource.install_dir}\n-      ).each do |directory|\n-        d = Resource::Directory.new(directory, run_context)\n-        d.owner(new_resource.build_user)\n-        d.run_action(:create)\n-      end\n+    def default_base_dir\n+      Chef::Platform.windows? ? ::File.join(ENV['SYSTEMDRIVE'], 'omnibus-ruby') : '/var/cache/omnibus'\n     end\n \n-    def execute_with_omnibus_toolchain(command)\n-      execute = Resource::Execute.new(\"#{new_resource.project_name}: #{command}\", run_context)\n-      execute.command(\n-        <<-CODE.gsub(/^ {10}/, '')\n-          . #{::File.join(build_user_home, 'load-omnibus-toolchain.sh')}\n-          #{command}\n-        CODE\n-      )\n-      execute.cwd(new_resource.project_dir)\n-      execute.environment(environment)\n-      execute.user(new_resource.build_user)\n-      execute.run_action(:run)\n+    def default_config_file\n+      ::File.join(project_dir, 'omnibus.rb')\n     end\n \n-    def environment\n-      environment = new_resource.environment || {}\n-      # Ensure we inheriet the calling procceses $PATH\n-      environment['PATH'] = ENV['PATH']\n-      # We need to all underlying build process respect the build user\n-      # as specified by the `build_user` attribute.\n-      environment['USER']     = new_resource.build_user\n-      environment['USERNAME'] = new_resource.build_user\n-      environment['LOGNAME']  = new_resource.build_user\n-      # Ensure we don't inherit the $TMPDIR of the calling process. $TMPDIR\n-      # is set per user so we can hit permission issues when we execute\n-      # the build as a different user.\n-      environment['TMPDIR'] = nil if mac_os_x?\n-      environment\n+    def default_environment\n+      {\n+        'PATH' => ENV['PATH'],\n+        'USER' => build_user,\n+        'USERNAME' => build_user,\n+        'LOGNAME' => build_user,\n+        'TMPDIR' => nil\n+      }","path":"libraries/omnibus_build.rb","position":177,"original_position":177,"commit_id":"8213f68ac0b3d1a712a9f7c5084df0a320689e6d","original_commit_id":"8213f68ac0b3d1a712a9f7c5084df0a320689e6d","user":{"login":"schisamo","id":6164,"avatar_url":"https://avatars.githubusercontent.com/u/6164?v=3","gravatar_id":"","url":"https://api.github.com/users/schisamo","html_url":"https://github.com/schisamo","followers_url":"https://api.github.com/users/schisamo/followers","following_url":"https://api.github.com/users/schisamo/following{/other_user}","gists_url":"https://api.github.com/users/schisamo/gists{/gist_id}","starred_url":"https://api.github.com/users/schisamo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/schisamo/subscriptions","organizations_url":"https://api.github.com/users/schisamo/orgs","repos_url":"https://api.github.com/users/schisamo/repos","events_url":"https://api.github.com/users/schisamo/events{/privacy}","received_events_url":"https://api.github.com/users/schisamo/received_events","type":"User","site_admin":false},"body":"The previous `environment` method was not just default values. The `PATH`, `USER`, `USERNAME`, `LOGNAME` and `TMPDIR` values are required for every forked process or builds will fail on many older Unixes _and_ Mac OS X. Please restore the previous logic including comments which explain the purpose of each env var we set.","created_at":"2016-05-03T13:46:22Z","updated_at":"2016-05-03T13:46:22Z","html_url":"https://github.com/chef-cookbooks/omnibus/pull/165#discussion_r61883163","pull_request_url":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/165","_links":{"self":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/comments/61883163"},"html":{"href":"https://github.com/chef-cookbooks/omnibus/pull/165#discussion_r61883163"},"pull_request":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/165"}}},"pull_request":{"url":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/165","id":68640859,"html_url":"https://github.com/chef-cookbooks/omnibus/pull/165","diff_url":"https://github.com/chef-cookbooks/omnibus/pull/165.diff","patch_url":"https://github.com/chef-cookbooks/omnibus/pull/165.patch","issue_url":"https://api.github.com/repos/chef-cookbooks/omnibus/issues/165","number":165,"state":"open","locked":false,"title":"refactor omnibus_build resource","user":{"login":"someara","id":69068,"avatar_url":"https://avatars.githubusercontent.com/u/69068?v=3","gravatar_id":"","url":"https://api.github.com/users/someara","html_url":"https://github.com/someara","followers_url":"https://api.github.com/users/someara/followers","following_url":"https://api.github.com/users/someara/following{/other_user}","gists_url":"https://api.github.com/users/someara/gists{/gist_id}","starred_url":"https://api.github.com/users/someara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/someara/subscriptions","organizations_url":"https://api.github.com/users/someara/orgs","repos_url":"https://api.github.com/users/someara/repos","events_url":"https://api.github.com/users/someara/events{/privacy}","received_events_url":"https://api.github.com/users/someara/received_events","type":"User","site_admin":false},"body":"LWRP DSL to Custom Resource DSL","created_at":"2016-05-02T23:59:15Z","updated_at":"2016-05-03T13:46:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f75af4dd9ac3b1b5c41194cd6e52434e431993a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/165/commits","review_comments_url":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/165/comments","review_comment_url":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chef-cookbooks/omnibus/issues/165/comments","statuses_url":"https://api.github.com/repos/chef-cookbooks/omnibus/statuses/8213f68ac0b3d1a712a9f7c5084df0a320689e6d","head":{"label":"someara:fixitfixitfixit","ref":"fixitfixitfixit","sha":"8213f68ac0b3d1a712a9f7c5084df0a320689e6d","user":{"login":"someara","id":69068,"avatar_url":"https://avatars.githubusercontent.com/u/69068?v=3","gravatar_id":"","url":"https://api.github.com/users/someara","html_url":"https://github.com/someara","followers_url":"https://api.github.com/users/someara/followers","following_url":"https://api.github.com/users/someara/following{/other_user}","gists_url":"https://api.github.com/users/someara/gists{/gist_id}","starred_url":"https://api.github.com/users/someara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/someara/subscriptions","organizations_url":"https://api.github.com/users/someara/orgs","repos_url":"https://api.github.com/users/someara/repos","events_url":"https://api.github.com/users/someara/events{/privacy}","received_events_url":"https://api.github.com/users/someara/received_events","type":"User","site_admin":false},"repo":{"id":57442002,"name":"omnibus","full_name":"someara/omnibus","owner":{"login":"someara","id":69068,"avatar_url":"https://avatars.githubusercontent.com/u/69068?v=3","gravatar_id":"","url":"https://api.github.com/users/someara","html_url":"https://github.com/someara","followers_url":"https://api.github.com/users/someara/followers","following_url":"https://api.github.com/users/someara/following{/other_user}","gists_url":"https://api.github.com/users/someara/gists{/gist_id}","starred_url":"https://api.github.com/users/someara/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/someara/subscriptions","organizations_url":"https://api.github.com/users/someara/orgs","repos_url":"https://api.github.com/users/someara/repos","events_url":"https://api.github.com/users/someara/events{/privacy}","received_events_url":"https://api.github.com/users/someara/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/someara/omnibus","description":"Prepares a machine to be an Omnibus builder. ┬──┬◡ﾉ(° -°ﾉ)","fork":true,"url":"https://api.github.com/repos/someara/omnibus","forks_url":"https://api.github.com/repos/someara/omnibus/forks","keys_url":"https://api.github.com/repos/someara/omnibus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/someara/omnibus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/someara/omnibus/teams","hooks_url":"https://api.github.com/repos/someara/omnibus/hooks","issue_events_url":"https://api.github.com/repos/someara/omnibus/issues/events{/number}","events_url":"https://api.github.com/repos/someara/omnibus/events","assignees_url":"https://api.github.com/repos/someara/omnibus/assignees{/user}","branches_url":"https://api.github.com/repos/someara/omnibus/branches{/branch}","tags_url":"https://api.github.com/repos/someara/omnibus/tags","blobs_url":"https://api.github.com/repos/someara/omnibus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/someara/omnibus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/someara/omnibus/git/refs{/sha}","trees_url":"https://api.github.com/repos/someara/omnibus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/someara/omnibus/statuses/{sha}","languages_url":"https://api.github.com/repos/someara/omnibus/languages","stargazers_url":"https://api.github.com/repos/someara/omnibus/stargazers","contributors_url":"https://api.github.com/repos/someara/omnibus/contributors","subscribers_url":"https://api.github.com/repos/someara/omnibus/subscribers","subscription_url":"https://api.github.com/repos/someara/omnibus/subscription","commits_url":"https://api.github.com/repos/someara/omnibus/commits{/sha}","git_commits_url":"https://api.github.com/repos/someara/omnibus/git/commits{/sha}","comments_url":"https://api.github.com/repos/someara/omnibus/comments{/number}","issue_comment_url":"https://api.github.com/repos/someara/omnibus/issues/comments{/number}","contents_url":"https://api.github.com/repos/someara/omnibus/contents/{+path}","compare_url":"https://api.github.com/repos/someara/omnibus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/someara/omnibus/merges","archive_url":"https://api.github.com/repos/someara/omnibus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/someara/omnibus/downloads","issues_url":"https://api.github.com/repos/someara/omnibus/issues{/number}","pulls_url":"https://api.github.com/repos/someara/omnibus/pulls{/number}","milestones_url":"https://api.github.com/repos/someara/omnibus/milestones{/number}","notifications_url":"https://api.github.com/repos/someara/omnibus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/someara/omnibus/labels{/name}","releases_url":"https://api.github.com/repos/someara/omnibus/releases{/id}","deployments_url":"https://api.github.com/repos/someara/omnibus/deployments","created_at":"2016-04-30T12:59:43Z","updated_at":"2016-04-30T12:59:43Z","pushed_at":"2016-05-03T09:46:07Z","git_url":"git://github.com/someara/omnibus.git","ssh_url":"git@github.com:someara/omnibus.git","clone_url":"https://github.com/someara/omnibus.git","svn_url":"https://github.com/someara/omnibus","homepage":"","size":750,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"chef-cookbooks:master","ref":"master","sha":"348d0cc8c4d198de315046aa290e5bbc62bc65a2","user":{"login":"chef-cookbooks","id":3617830,"avatar_url":"https://avatars.githubusercontent.com/u/3617830?v=3","gravatar_id":"","url":"https://api.github.com/users/chef-cookbooks","html_url":"https://github.com/chef-cookbooks","followers_url":"https://api.github.com/users/chef-cookbooks/followers","following_url":"https://api.github.com/users/chef-cookbooks/following{/other_user}","gists_url":"https://api.github.com/users/chef-cookbooks/gists{/gist_id}","starred_url":"https://api.github.com/users/chef-cookbooks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef-cookbooks/subscriptions","organizations_url":"https://api.github.com/users/chef-cookbooks/orgs","repos_url":"https://api.github.com/users/chef-cookbooks/repos","events_url":"https://api.github.com/users/chef-cookbooks/events{/privacy}","received_events_url":"https://api.github.com/users/chef-cookbooks/received_events","type":"Organization","site_admin":false},"repo":{"id":9323824,"name":"omnibus","full_name":"chef-cookbooks/omnibus","owner":{"login":"chef-cookbooks","id":3617830,"avatar_url":"https://avatars.githubusercontent.com/u/3617830?v=3","gravatar_id":"","url":"https://api.github.com/users/chef-cookbooks","html_url":"https://github.com/chef-cookbooks","followers_url":"https://api.github.com/users/chef-cookbooks/followers","following_url":"https://api.github.com/users/chef-cookbooks/following{/other_user}","gists_url":"https://api.github.com/users/chef-cookbooks/gists{/gist_id}","starred_url":"https://api.github.com/users/chef-cookbooks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chef-cookbooks/subscriptions","organizations_url":"https://api.github.com/users/chef-cookbooks/orgs","repos_url":"https://api.github.com/users/chef-cookbooks/repos","events_url":"https://api.github.com/users/chef-cookbooks/events{/privacy}","received_events_url":"https://api.github.com/users/chef-cookbooks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chef-cookbooks/omnibus","description":"Prepares a machine to be an Omnibus builder. ┬──┬◡ﾉ(° -°ﾉ)","fork":false,"url":"https://api.github.com/repos/chef-cookbooks/omnibus","forks_url":"https://api.github.com/repos/chef-cookbooks/omnibus/forks","keys_url":"https://api.github.com/repos/chef-cookbooks/omnibus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chef-cookbooks/omnibus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chef-cookbooks/omnibus/teams","hooks_url":"https://api.github.com/repos/chef-cookbooks/omnibus/hooks","issue_events_url":"https://api.github.com/repos/chef-cookbooks/omnibus/issues/events{/number}","events_url":"https://api.github.com/repos/chef-cookbooks/omnibus/events","assignees_url":"https://api.github.com/repos/chef-cookbooks/omnibus/assignees{/user}","branches_url":"https://api.github.com/repos/chef-cookbooks/omnibus/branches{/branch}","tags_url":"https://api.github.com/repos/chef-cookbooks/omnibus/tags","blobs_url":"https://api.github.com/repos/chef-cookbooks/omnibus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chef-cookbooks/omnibus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chef-cookbooks/omnibus/git/refs{/sha}","trees_url":"https://api.github.com/repos/chef-cookbooks/omnibus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chef-cookbooks/omnibus/statuses/{sha}","languages_url":"https://api.github.com/repos/chef-cookbooks/omnibus/languages","stargazers_url":"https://api.github.com/repos/chef-cookbooks/omnibus/stargazers","contributors_url":"https://api.github.com/repos/chef-cookbooks/omnibus/contributors","subscribers_url":"https://api.github.com/repos/chef-cookbooks/omnibus/subscribers","subscription_url":"https://api.github.com/repos/chef-cookbooks/omnibus/subscription","commits_url":"https://api.github.com/repos/chef-cookbooks/omnibus/commits{/sha}","git_commits_url":"https://api.github.com/repos/chef-cookbooks/omnibus/git/commits{/sha}","comments_url":"https://api.github.com/repos/chef-cookbooks/omnibus/comments{/number}","issue_comment_url":"https://api.github.com/repos/chef-cookbooks/omnibus/issues/comments{/number}","contents_url":"https://api.github.com/repos/chef-cookbooks/omnibus/contents/{+path}","compare_url":"https://api.github.com/repos/chef-cookbooks/omnibus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chef-cookbooks/omnibus/merges","archive_url":"https://api.github.com/repos/chef-cookbooks/omnibus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chef-cookbooks/omnibus/downloads","issues_url":"https://api.github.com/repos/chef-cookbooks/omnibus/issues{/number}","pulls_url":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls{/number}","milestones_url":"https://api.github.com/repos/chef-cookbooks/omnibus/milestones{/number}","notifications_url":"https://api.github.com/repos/chef-cookbooks/omnibus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chef-cookbooks/omnibus/labels{/name}","releases_url":"https://api.github.com/repos/chef-cookbooks/omnibus/releases{/id}","deployments_url":"https://api.github.com/repos/chef-cookbooks/omnibus/deployments","created_at":"2013-04-09T14:56:46Z","updated_at":"2016-01-12T19:48:30Z","pushed_at":"2016-05-03T09:46:07Z","git_url":"git://github.com/chef-cookbooks/omnibus.git","ssh_url":"git@github.com:chef-cookbooks/omnibus.git","clone_url":"https://github.com/chef-cookbooks/omnibus.git","svn_url":"https://github.com/chef-cookbooks/omnibus","homepage":"","size":860,"stargazers_count":16,"watchers_count":16,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":37,"mirror_url":null,"open_issues_count":4,"forks":37,"open_issues":4,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/165"},"html":{"href":"https://github.com/chef-cookbooks/omnibus/pull/165"},"issue":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/issues/165"},"comments":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/issues/165/comments"},"review_comments":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/165/comments"},"review_comment":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/pulls/165/commits"},"statuses":{"href":"https://api.github.com/repos/chef-cookbooks/omnibus/statuses/8213f68ac0b3d1a712a9f7c5084df0a320689e6d"}}}}