class Influxdb < Formula desc "Time series, events, and metrics database" homepage "https://influxdata.com/time-series-platform/influxdb/" url "https://github.com/influxdata/influxdb.git", tag: "v2.6.1", revision: "9dcf880fe081b7b45117b56eafb1aa8acfa1565f" license "MIT" head "https://github.com/influxdata/influxdb.git", branch: "master" # The regex below omits a rogue `v9.9.9` tag that breaks version comparison. livecheck do url :stable regex(/^v?((?!9\.9\.9)\d+(?:\.\d+)+)$/i) end bottle do sha256 cellar: :any_skip_relocation, arm64_ventura: "c7631840c61c20fc289748ee995b7f880c96143236b40766b04860f6dc77a4af" sha256 cellar: :any_skip_relocation, arm64_monterey: "19828b7089a667999c35b5fd0230211e8f31fbfadf19ed1a7fc871de5647f5a0" sha256 cellar: :any_skip_relocation, arm64_big_sur: "eb73569a5e5e6c5d57a0726970b55263ec9f262746733959eaf83e867c0cd20c" sha256 cellar: :any_skip_relocation, ventura: "94f50e4434f9a3afb2430d134d87526c202e22383df70d32e7ef776edd3d3a2e" sha256 cellar: :any_skip_relocation, monterey: "088b718a0cc45d19a11b4a26b076421e3d98d25820f0c46802ad4cb8cca2202d" sha256 cellar: :any_skip_relocation, big_sur: "0c339719cc4f7fa6ec81dfab5d7ce7e5bd8627162373744aacf61e7a9ee8b036" sha256 cellar: :any_skip_relocation, x86_64_linux: "1619d5a1cd7bae3b3c1b68de1121df2db8bde180bdbea4452571bedfb7743eb3" end depends_on "breezy" => :build depends_on "go" => :build depends_on "pkg-config" => :build depends_on "protobuf" => :build depends_on "rust" => :build # NOTE: The version here is specified in the go.mod of influxdb. # If you're upgrading to a newer influxdb version, check to see if this needs upgraded too. resource "pkg-config-wrapper" do url "https://github.com/influxdata/pkg-config/archive/refs/tags/v0.2.11.tar.gz" sha256 "52b22c151163dfb051fd44e7d103fc4cde6ae8ff852ffc13adeef19d21c36682" livecheck do url "https://raw.githubusercontent.com/influxdata/influxdb/v#{LATEST_VERSION}/go.mod" regex(/pkg-config\s+v?(\d+(?:\.\d+)+)/i) end end # NOTE: The version/URL here is specified in scripts/fetch-ui-assets.sh in influxdb. # If you're upgrading to a newer influxdb version, check to see if this needs upgraded too. resource "ui-assets" do url "https://github.com/influxdata/ui/releases/download/OSS-v2.6.1/build.tar.gz" sha256 "345192ad60e62136163b651c4b6d1549baa456901646b44c23c94a6b67e6ef5c" livecheck do url "https://raw.githubusercontent.com/influxdata/influxdb/v#{LATEST_VERSION}/scripts/fetch-ui-assets.sh" regex(/UI_RELEASE=["']?OSS[._-]v?(\d+(?:\.\d+)+)["']?$/i) end end def install # Set up the influxdata pkg-config wrapper to enable just-in-time compilation & linking # of the Rust components in the server. resource("pkg-config-wrapper").stage do system "go", "build", *std_go_args(output: buildpath/"bootstrap/pkg-config") end ENV.prepend_path "PATH", buildpath/"bootstrap" # Extract pre-build UI resources to the location expected by go-bindata. resource("ui-assets").stage(buildpath/"static/data/build") # Embed UI files into the Go source code. system "make", "generate-web-assets" # Build the server. ldflags = %W[ -s -w -X main.version=#{version} -X main.commit=#{Utils.git_short_head(length: 10)} -X main.date=#{time.iso8601} ] system "go", "build", *std_go_args(output: bin/"influxd", ldflags: ldflags), "-tags", "assets,sqlite_foreign_keys,sqlite_json", "./cmd/influxd" data = var/"lib/influxdb2" data.mkpath # Generate default config file. config = buildpath/"config.yml" config.write Utils.safe_popen_read(bin/"influxd", "print-config", "--bolt-path=#{data}/influxdb.bolt", "--engine-path=#{data}/engine") (etc/"influxdb2").install config # Create directory for DB stdout+stderr logs. (var/"log/influxdb2").mkpath end def caveats <<~EOS This formula does not contain command-line interface; to install it, run: brew install influxdb-cli EOS end service do run bin/"influxd" keep_alive true working_dir HOMEBREW_PREFIX log_path var/"log/influxdb2/influxd_output.log" error_log_path var/"log/influxdb2/influxd_output.log" environment_variables INFLUXD_CONFIG_PATH: etc/"influxdb2/config.yml" end test do influxd_port = free_port influx_host = "http://localhost:#{influxd_port}" ENV["INFLUX_HOST"] = influx_host influxd = fork do exec "#{bin}/influxd", "--bolt-path=#{testpath}/influxd.bolt", "--engine-path=#{testpath}/engine", "--http-bind-address=:#{influxd_port}", "--log-level=error" end sleep 30 # Check that the server has properly bundled UI assets and serves them as HTML. curl_output = shell_output("curl --silent --head #{influx_host}") assert_match "200 OK", curl_output assert_match "text/html", curl_output ensure Process.kill("TERM", influxd) Process.wait influxd end end