Add mix elasticsearch.install
task
This will be helpful for making projects initialize their own version of elasticsearch for development purposes.
This commit is contained in:
parent
13d98ad1d1
commit
5c4562e68d
2 changed files with 49 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -18,3 +18,5 @@ erl_crash.dump
|
|||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
||||
|
||||
vendor/
|
||||
|
|
47
lib/mix/elasticsearch.install.ex
Normal file
47
lib/mix/elasticsearch.install.ex
Normal file
|
@ -0,0 +1,47 @@
|
|||
defmodule Mix.Tasks.Elasticsearch.Install do
|
||||
@moduledoc """
|
||||
Downloads a version of Elasticsearch with `curl` to a directory of your
|
||||
choosing.
|
||||
"""
|
||||
|
||||
def run(args) do
|
||||
with {[{:version, version}], [location], _} <- OptionParser.parse(args, switches: [ version: :string ]) do
|
||||
download_elasticsearch(version, location)
|
||||
download_kibana(version, location)
|
||||
else
|
||||
_ ->
|
||||
Mix.raise """
|
||||
Invalid options. See `mix help elasticsearch.install`
|
||||
"""
|
||||
end
|
||||
end
|
||||
|
||||
defp download_elasticsearch(version, location) do
|
||||
name = "elasticsearch-#{version}"
|
||||
tar = "#{name}.tar.gz"
|
||||
|
||||
System.cmd("curl", ["-L", "-O", "https://artifacts.elastic.co/downloads/elasticsearch/#{tar}"], cd: location)
|
||||
unpack(tar, name, "elasticsearch", location)
|
||||
end
|
||||
|
||||
defp download_kibana(version, location) do
|
||||
name =
|
||||
case :os.type do
|
||||
{:unix, :darwin} ->
|
||||
"kibana-#{version}-darwin-x86_64"
|
||||
other ->
|
||||
Mix.raise "Unsupported system for Kibana: #{inspect other}"
|
||||
end
|
||||
|
||||
tar = "#{name}.tar.gz"
|
||||
|
||||
System.cmd("curl", ["-L", "-O", "https://artifacts.elastic.co/downloads/kibana/#{tar}"], cd: location)
|
||||
unpack(tar, name, "kibana", location)
|
||||
end
|
||||
|
||||
defp unpack(tar, name, alias, location) do
|
||||
System.cmd("tar", ["-zxvf", tar], cd: location)
|
||||
System.cmd("rm", [tar], cd: location)
|
||||
System.cmd("mv", [name, alias], cd: location)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue