[Groonga-commit] groonga/heroku-buildpack-rroonga at 11af6d1 [master] Require Groonga and Ruby buildpacks

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Feb 23 01:12:14 JST 2016


Kouhei Sutou	2016-02-23 01:12:14 +0900 (Tue, 23 Feb 2016)

  New Revision: 11af6d1bb0bf83210b7ca9129e171fd04c5b5158
  https://github.com/groonga/heroku-buildpack-rroonga/commit/11af6d1bb0bf83210b7ca9129e171fd04c5b5158

  Message:
    Require Groonga and Ruby buildpacks

  Modified files:
    README.md
    bin/compile
    bin/detect
    bin/release

  Modified: README.md (+3 -1)
===================================================================
--- README.md    2016-02-21 11:54:41 +0900 (d84eb9e)
+++ README.md    2016-02-23 01:12:14 +0900 (ecf3fb1)
@@ -4,7 +4,9 @@ This is a Heroku buildpack of [Rroonga](http://ranguba.org/#about-rroonga).
 
 ## Usage
 
-    heroku create --buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/groonga/rroonga.tgz
+    heroku apps:create --buildpack https://codon-buildpacks.s3.amazonaws.com/buildpacks/groonga/groonga.tgz
+    heroku buildpacks:add heroku/ruby
+    heroku buildpacks:add https://codon-buildpacks.s3.amazonaws.com/buildpacks/groonga/rroonga.tgz
 
 Add `rroonga` entry to your `Gemfile`:
 

  Modified: bin/compile (+21 -109)
===================================================================
--- bin/compile    2016-02-21 11:54:41 +0900 (bf214b1)
+++ bin/compile    2016-02-23 01:12:14 +0900 (07e099c)
@@ -54,94 +54,6 @@ class Arguments < Struct.new(:build_dir, :cache_dir, :env_dir)
   end
 end
 
-class BuildpackBuilder
-  def initialize(label, name, arguments)
-    @label = label
-    @name = name
-    @arguments = arguments
-  end
-
-  def build
-    puts("-----> Building buildpack: #{@label}")
-    Dir.mktmpdir do |tmpdir|
-      Dir.chdir(tmpdir) do
-        download
-        detect
-        compile
-        release
-      end
-    end
-  end
-
-  private
-  def url
-    "https://codon-buildpacks.s3.amazonaws.com/buildpacks/#{@name}.tgz"
-  end
-
-  def base_name
-    url.split("/").last
-  end
-
-  def download
-    puts("-----> Downloading buildpack: #{url}")
-
-    if url.end_with?(".tgz")
-      sh("curl",
-         "--silent",
-         "--remote-name",
-         "--location",
-         url)
-      sh("tar", "xf", base_name)
-      rm(base_name)
-    else
-      sh("git",
-         "clone",
-         "--depth", "1",
-         url,
-         ".")
-      rm_r(".git")
-    end
-  end
-
-  def detect
-    puts("-----> Detecting buildpack: #{@label}")
-
-    run_script("bin/detect", @arguments.build_dir)
-  end
-
-  def compile
-    puts("-----> Compiling buildpack: #{@label}")
-
-    Dir.mktmpdir do |env_dir|
-      new_environment_variables.each do |name, value|
-        File.open("#{env_dir}/#{name}", "w") do |file|
-          file.print(value)
-        end
-      end
-      run_script("bin/compile",
-                 @arguments.build_dir,
-                 @arguments.cache_dir,
-                 env_dir)
-    end
-  end
-
-  def release
-    puts("-----> Releasing buildpack: #{@label}")
-
-    run_script("bin/release", @arguments.build_dir, :out => "config.yaml")
-    YAML.load_file("config.yaml")
-  end
-
-  def run_script(script, *arguments)
-    chmod(0755, script)
-    sh(new_environment_variables, script, *arguments)
-  end
-
-  def new_environment_variables
-    merge_environment_variables(@arguments.environment_variables)
-  end
-end
-
 def prepend_path_to_environment_variable(name, *paths)
   new_paths = paths + [ENV[name]]
   ENV[name] = new_paths.compact.join(File::PATH_SEPARATOR)
@@ -149,16 +61,25 @@ end
 
 def setup_groonga_environment_variables(build_dir)
   prefix = File.join(build_dir, "vendor", "groonga")
+  mecab_prefix = File.join(build_dir, "vendor", "mecab")
 
   prepend_path_to_environment_variable("PATH",
                                        File.join(prefix, "bin"),
                                        File.join(prefix, "sbin"))
 
   prepend_path_to_environment_variable("LD_LIBRARY_PATH",
+                                       File.join(mecab_prefix, "lib"))
+  prepend_path_to_environment_variable("LD_LIBRARY_PATH",
                                        File.join(prefix, "lib"))
 
   prepend_path_to_environment_variable("PKG_CONFIG_PATH",
                                        File.join(prefix, "lib", "pkgconfig"))
+
+  ENV["MECABRC"] = File.join(mecab_prefix, "etc", "mecabrc")
+
+  ENV["GRN_PLUGINS_DIR"] = File.join(prefix, "lib", "groonga", "plugins")
+  ENV["GRN_RUBY_SCRIPTS_DIR"] =
+    File.join(prefix, "lib", "groonga", "scripts", "ruby")
 end
 
 def setup_ruby_environment_variables(build_dir)
@@ -176,6 +97,15 @@ def setup_ruby_environment_variables(build_dir)
   prepend_path_to_environment_variable("GEM_PATH", gem_paths)
 end
 
+def update_mecabrc(mecabrc, prefix)
+  sh("sed", "-i.bak", "-e", "s,/app,#{prefix},g", mecabrc)
+  begin
+    yield
+  ensure
+    mv("#{mecabrc}.bak", mecabrc)
+  end
+end
+
 arguments = Arguments.new(*ARGV)
 
 groonga_base_path = File.join(arguments.build_dir, "groonga")
@@ -184,31 +114,13 @@ groonga_database_path = File.join(groonga_base_path, "data", "db")
 mkdir_p(File.dirname(groonga_database_path))
 ENV["GROONGA_DATABASE_PATH"] = groonga_database_path
 
-builder = BuildpackBuilder.new("Groonga", "groonga/groonga", arguments)
-groonga_config = builder.build
 setup_groonga_environment_variables(arguments.build_dir)
-
-builder = BuildpackBuilder.new("Ruby", "heroku/ruby", arguments)
-ruby_config = builder.build
 setup_ruby_environment_variables(arguments.build_dir)
 
 puts("-----> Initializing database")
 Dir.chdir(arguments.build_dir) do
-  sh(merge_environment_variables(arguments.environment_variables),
-     "bundle", "exec", "ruby", File.join("groonga", "init.rb"))
-end
-
-config = Marshal.load(Marshal.dump(ruby_config))
-config["addons"] ||= []
-config["addons"] += groonga_config["addons"] || []
-
-config["config_vars"] ||= {}
-config["config_vars"].merge!(groonga_config["config_vars"])
-
-Dir.chdir(arguments.build_dir) do
-  output_dir = File.join("var", "tmp")
-  mkdir_p(output_dir)
-  File.open(File.join(output_dir, "config.yaml"), "w") do |config_yaml|
-    config_yaml.puts(config.to_yaml)
+  update_mecabrc(ENV["MECABRC"], arguments.build_dir) do
+    sh(merge_environment_variables(arguments.environment_variables),
+       "bundle", "exec", "ruby", File.join("groonga", "init.rb"))
   end
 end

  Modified: bin/detect (+1 -2)
===================================================================
--- bin/detect    2016-02-21 11:54:41 +0900 (202b7c0)
+++ bin/detect    2016-02-23 01:12:14 +0900 (89634be)
@@ -3,8 +3,7 @@
 build_dir = ARGV.first
 
 init_rb = File.join(build_dir, "groonga", "init.rb")
-gemfile = File.join(build_dir, "Gemfile")
-if File.exist?(init_rb) and File.exist?(gemfile)
+if File.exist?(init_rb)
   puts("Rroonga")
   exit(true)
 else

  Modified: bin/release (+1 -5)
===================================================================
--- bin/release    2016-02-21 11:54:41 +0900 (e21464b)
+++ bin/release    2016-02-23 01:12:14 +0900 (ebf6adc)
@@ -1,7 +1,3 @@
 #!/usr/bin/env ruby
 
-build_dir = ARGV.first
-
-config_yaml = File.join(build_dir, "var", "tmp", "config.yaml")
-puts(File.read(config_yaml))
-
+puts({}.to_yaml)
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index