homebrew-core/Formula/k3d.rb

49 lines
1.9 KiB
Ruby

class K3d < Formula
desc "Little helper to run Rancher Lab's k3s in Docker"
homepage "https://github.com/rancher/k3d"
url "https://github.com/rancher/k3d/archive/v3.0.1.tar.gz"
sha256 "bcf9cf273033a81a97698c37cbf29146c17997f4bf3bedcd9fcf55db106b8db2"
license "MIT"
livecheck do
url :stable
regex(/^v?(\d+(?:\.\d+)+)$/i)
end
bottle do
cellar :any_skip_relocation
rebuild 1
sha256 "030e83d57d78de00e91a3384bdb33e3a3867284dcd21652edfc98a4df978987e" => :catalina
sha256 "556bbfae79432b1da4ede6c762a530f3e3eaa105e3a7675b49aa2e2a68282ce9" => :mojave
sha256 "3d0ba472925d3a2a5dc1e9a0f9bf1f3f548650192f5989bffba7d635188871fe" => :high_sierra
end
depends_on "go" => :build
def install
system "go", "build",
"-mod", "vendor",
"-ldflags", "-s -w -X github.com/rancher/k3d/v#{version.major}/version.Version=v#{version}"\
" -X github.com/rancher/k3d/v#{version.major}/version.K3sVersion=latest",
"-trimpath", "-o", bin/"k3d"
# Install bash completion
output = Utils.safe_popen_read("#{bin}/k3d", "completion", "bash")
(bash_completion/"k3d").write output
# Install zsh completion
output = Utils.safe_popen_read("#{bin}/k3d", "completion", "zsh")
(zsh_completion/"_k3d").write output
end
test do
assert_match "k3d version v#{version}\nk3s version latest (default)", shell_output("#{bin}/k3d --version")
# Either docker is not present or it is, where the command will fail in the first case.
# In any case I wouldn't expect a cluster with name 6d6de430dbd8080d690758a4b5d57c86 to be present
# (which is the md5sum of 'homebrew-failing-test')
output = shell_output("#{bin}/k3d cluster get 6d6de430dbd8080d690758a4b5d57c86 2>&1", 1).split("\n").pop
assert_match output,
"\x1B\[31mFATA\x1B\[0m\[0000\]\ No\ nodes\ found\ for\ cluster\ '6d6de430dbd8080d690758a4b5d57c86'\ "
end
end