homebrew-core/Formula/djl-serving.rb

52 lines
1.6 KiB
Ruby

class DjlServing < Formula
desc "This module contains an universal model serving implementation"
homepage "https://github.com/deepjavalibrary/djl-serving"
url "https://publish.djl.ai/djl-serving/serving-0.20.0.tar"
sha256 "d9dec82d0087a5c7c3daf941834ac51ad1fb8b8f1a8d444daf372ce33c18ea1d"
license "Apache-2.0"
# `djl-serving` versions aren't considered released until a corresponding
# release is created in the main `deepjavalibrary/djl` repository.
livecheck do
url "https://github.com/deepjavalibrary/djl"
strategy :github_latest
end
bottle do
sha256 cellar: :any_skip_relocation, all: "94aaecfa8f346f98dec8cfadc7e9381b4eebaae1570c4faa4efe818dc37e8c2e"
end
depends_on "openjdk"
def install
# Install files
rm_rf Dir["bin/*.bat"]
mv "bin/serving", "bin/djl-serving"
libexec.install Dir["*"]
env = { MODEL_SERVER_HOME: "${MODEL_SERVER_HOME:-#{var}}" }
env.merge!(Language::Java.overridable_java_home_env)
(bin/"djl-serving").write_env_script "#{libexec}/bin/djl-serving", env
end
service do
run [opt_bin/"djl-serving", "run"]
keep_alive true
end
test do
port = free_port
(testpath/"config.properties").write <<~EOS
inference_address=http://127.0.0.1:#{port}
management_address=http://127.0.0.1:#{port}
EOS
ENV["MODEL_SERVER_HOME"] = testpath
cp_r Dir["#{libexec}/*"], testpath
fork do
exec bin/"djl-serving -f config.properties"
end
sleep 30
cmd = "http://127.0.0.1:#{port}/ping"
assert_match "{}\n", shell_output("curl --fail #{cmd}")
end
end