diff --git a/VERSION b/VERSION index 7db2672..a2e1aa9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.26 +0.1.27 diff --git a/formula/ih-core.rb b/formula/ih-core.rb index 112abde..8d1183f 100644 --- a/formula/ih-core.rb +++ b/formula/ih-core.rb @@ -1,5 +1,5 @@ class IhCore < Formula - VERSION="0.1.26" + VERSION="0.1.27" desc "Brew formula for installing core tools used at Included Health engineering." homepage "https://github.com/ConsultingMD/homebrew-ih-public" license "CC BY-NC-ND 4.0" diff --git a/lib/core/rancher/default/11_rancher.sh b/lib/core/rancher/default/11_rancher.sh new file mode 100644 index 0000000..902b91d --- /dev/null +++ b/lib/core/rancher/default/11_rancher.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +function ih-rancher-validate() { + + if command -v rdctl >/dev/null; then + echo "✅ Rancher CLI rdctl is available in PATH..." + else + echo "❗ Rancher CLI rdctl is not available in PATH, add $HOME/.rd/bin/ to your PATH." + return 1 + fi + + local config + if config=$(rdctl list-settings); then + echo "✅ Rancher desktop appears to be running" + else + echo "❗ Rancher does does not appear to be running. You must start Rancher Desktop through Finder or by running 'rdctl start'." + return 1 + fi + + local config_version + local kubernetes_enabled + local container_engine + local admin_access + + config_version=$(echo "$config" | jq -r '.version') + kubernetes_enabled=$(echo "$config" | jq -r '.kubernetes.enabled') + container_engine=$(echo "$config" | jq -r '.containerEngine.name') + admin_access=$(echo "$config" | jq -r '.application.adminAccess') + + if [[ "${config_version:-}" -eq "6" ]]; then + echo "✅ Rancher config version is as expected..." + else + echo "❗ Rancher config version is ${config_version:-} (expected 6). Update Rancher Desktop." + return 1 + fi + + if [[ "${kubernetes_enabled:-true}" == 'squid' ]]; then + echo "✅ Kubernetes is disabled..." + else + echo "⚠️ Kubernetes is enabled, which steals port 443. If you need port 443, disable kubernetes by running 'rdctl set --kubernetes-enabled=false'." + fi + + if [[ "${container_engine:-}" == "moby" ]]; then + echo "✅ Using dockerd container engine..." + else + echo "❗ Using incorrect container engine '${container_engine:-}' (expected moby). Switch to dockerd by running 'rdctl set --container-engine.name=moby'" + return 1 + fi + + if [[ "${admin_access:-}" == "true" ]]; then + echo "✅ Admin access is configured to support networking." + else + echo "❗ Rancher Desktop needs admin access to configure networking. Run 'rdctl set --application.admin-access=true', then restart Rancher Desktop." + exit 1 + fi + + echo "Rancher configuration seems to be correct." + echo "If you still need help, include the output above in your message to #infrastructure-support." +} diff --git a/lib/core/rancher/step.sh b/lib/core/rancher/step.sh index db9bc89..1eb7e97 100644 --- a/lib/core/rancher/step.sh +++ b/lib/core/rancher/step.sh @@ -6,94 +6,97 @@ function ih::setup::core.rancher::help() { echo 'Install Rancher Desktop as an alternative to Docker Desktop' } +RANCHER_AUGMENT_SRC="$IH_CORE_LIB_DIR/core/rancher/default/11_rancher.sh" +RANCHER_AUGMENT_DST="$IH_DEFAULT_DIR/11_rancher.sh" + # Check if the step has been installed and return 0 if it has. # Otherwise return 1. function ih::setup::core.rancher::test() { - # Check if Rancher was installed manually - brew list rancher > /dev/null 2>&1 - RANCHER_INSTALLED=$? - - #Check if IH Rancher is already installed - brew list ih-rancher > /dev/null 2>&1 - IH_RANCHER_INSTALLED=$? + # Check if Rancher was installed manually + brew list rancher >/dev/null 2>&1 + RANCHER_INSTALLED=$? + #Check if IH Rancher is already installed + brew list ih-rancher >/dev/null 2>&1 + IH_RANCHER_INSTALLED=$? - if [ $RANCHER_INSTALLED -eq 0 ] - then - ih::log::debug "Rancher Desktop was installed manually and should be uninstalled" - return 1 - fi + if [ $RANCHER_INSTALLED -eq 0 ]; then + ih::log::debug "Rancher Desktop was installed manually and should be uninstalled" + return 1 + fi - if [ $IH_RANCHER_INSTALLED -eq 1 ] - then - ih::log::debug "IH-Rancher should be listed as a cask" - return 1 - fi + if [ $IH_RANCHER_INSTALLED -eq 1 ]; then + ih::log::debug "IH-Rancher should be listed as a cask" + return 1 + fi + if ! ih::file::check-file-in-sync "$RANCHER_AUGMENT_SRC" "$RANCHER_AUGMENT_DST"; then + ih::log::debug "Augment script not in sync" + return 1 + fi - # Check for PLIST FILE - PLISTFILE="$HOME/Library/Preferences/io.rancherdesktop.profile.defaults.plist" - if [ -f "$PLISTFILE" ]; then - return 0 - fi - - ih::log::debug "Rancher Desktop is not available" + # Check for PLIST FILE + PLISTFILE="$HOME/Library/Preferences/io.rancherdesktop.profile.defaults.plist" + if [ ! -f "$PLISTFILE" ]; then return 1 + fi + + return 0 } function ih::setup::core.rancher::deps() { echo "core.shell" } - function ih::setup::core.rancher::install() { - local THIS_DIR="$IH_CORE_LIB_DIR/core/rancher" - - cp "${THIS_DIR}/io.rancherdesktop.profile.defaults.plist" "$HOME/Library/Preferences/io.rancherdesktop.profile.defaults.plist" - - # Check if Rancher was installed manually - brew list rancher > /dev/null 2>&1 - RANCHER_INSTALLED=$? - - #Check if IH Rancher is already installed - brew list ih-rancher > /dev/null 2>&1 - IH_RANCHER_INSTALLED=$? - - - # If rancher or ih-rancher is already installed reset to factory - if [ $RANCHER_INSTALLED -eq 0 ] || [ $IH_RANCHER_INSTALLED -eq 0 ] - then - $(/Applications/Rancher\ Desktop.app/Contents/Resources/resources/darwin/bin/rdctl factory-reset) - fi - - # Check if Rancher was installed manually with brew - if [ $RANCHER_INSTALLED -eq 0 ] - then - echo "Rancher Desktop was installed previously with brew command. In order to avoid any conflicts this script will uninstall that package". - echo "You may be required to enter your password" - brew uninstall rancher + local THIS_DIR="$IH_CORE_LIB_DIR/core/rancher" + + cp -f "$RANCHER_AUGMENT_SRC" "$RANCHER_AUGMENT_DST" + + echo "A configuration file for Rancher Desktop will be copied to your system" + echo "You may be required to enter your password" + sudo cp "${THIS_DIR}/io.rancherdesktop.profile.defaults.plist" "$HOME/Library/Preferences/io.rancherdesktop.profile.defaults.plist" + + # Check if Rancher was installed manually + brew list rancher >/dev/null 2>&1 + RANCHER_INSTALLED=$? + + #Check if IH Rancher is already installed + brew list ih-rancher >/dev/null 2>&1 + IH_RANCHER_INSTALLED=$? + + # If rancher or ih-rancher is already installed reset to factory + if [ $RANCHER_INSTALLED -eq 0 ] || [ $IH_RANCHER_INSTALLED -eq 0 ]; then + $(/Applications/Rancher\ Desktop.app/Contents/Resources/resources/darwin/bin/rdctl factory-reset) + fi + + # Check if Rancher was installed manually with brew + if [ $RANCHER_INSTALLED -eq 0 ]; then + echo "Rancher Desktop was installed previously with brew command. In order to avoid any conflicts this script will uninstall that package". + echo "You may be required to enter your password" + brew uninstall rancher + fi + + CASKSUCCEEDED=1 + # Installation and configuration of Rancher Desktop + for _ in 1 2 3; do + + # Check if we have a Mac M1 and the terminal is running over x86 + if [[ $(sysctl -n sysctl.proc_translated) -eq 1 ]] && [ $(arch) = "i386" ]; then + arch -arm64 -c brew reinstall ih-rancher + else + brew reinstall ih-rancher fi + CASKSUCCEEDED=$? + if [ $CASKSUCCEEDED -eq 0 ]; then + break + fi + done - CASKSUCCEEDED=1 - # Installation and configuration of Rancher Desktop - for _ in 1 2 3; do - - # Detect Rosetta - if [[ $(sysctl -n sysctl.proc_translated) -eq 1 ]]; then - # Rosetta Active - arch -arm64 -c brew reinstall ih-rancher - else - brew reinstall ih-rancher - fi - - CASKSUCCEEDED=$? - if [ $CASKSUCCEEDED -eq 0 ]; then - break - fi - done - + # Continue with the setting just if the cask was installed successfully + if [ $CASKSUCCEEDED -eq 0 ]; then rm -rf ~/.rd $(/Applications/Rancher\ Desktop.app/Contents/Resources/resources/darwin/bin/rdctl start) # Check for docker binary in /usr/local/bin @@ -102,13 +105,19 @@ function ih::setup::core.rancher::install() { DOCKERCOMPOSEBIN=/usr/local/bin/docker-compose if [ ! -f "$DOCKERBIN" ]; then - echo "In order to continue with Rancher configuration and be able to use this engine, some IDEs require the creation of symlinks for remote Python interpreters" - echo "Your password is required for the creation of symlink mentioned above" - sudo ln -s $HOME/.rd/bin/docker /usr/local/bin/docker - if [ ! -f "$DOCKERCOMPOSEBIN" ]; then - sudo ln -s $HOME/.rd/bin/docker-compose /usr/local/bin/docker-compose - fi + echo "In order to continue with Rancher configuration and be able to use this engine, some IDEs require the creation of symlinks for remote Python interpreters" + echo "Your password is required for the creation of symlink mentioned above" + sudo ln -s $HOME/.rd/bin/docker /usr/local/bin/docker + if [ ! -f "$DOCKERCOMPOSEBIN" ]; then + sudo ln -s $HOME/.rd/bin/docker-compose /usr/local/bin/docker-compose + fi fi - + echo "Rancher Desktop has been installed successfully" + else + ih::log::warn "Could not install Rancher Desktop" + echo "There was an error with Rancher Desktop Installation. Please contact support + in the #developer-tools channel in Slack (https://ih-epdd.slack.com/archives/C04LPMF4YPL)" + return 1 + fi }