start-console.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. CONSOLE_IMAGE=${CONSOLE_IMAGE:="quay.io/openshift/origin-console:latest"}
  4. CONSOLE_PORT=${CONSOLE_PORT:=9000}
  5. echo "Starting local OpenShift console..."
  6. BRIDGE_USER_AUTH="disabled"
  7. BRIDGE_K8S_MODE="off-cluster"
  8. BRIDGE_K8S_AUTH="bearer-token"
  9. BRIDGE_K8S_MODE_OFF_CLUSTER_SKIP_VERIFY_TLS=true
  10. BRIDGE_K8S_MODE_OFF_CLUSTER_ENDPOINT=$(oc whoami --show-server)
  11. # The monitoring operator is not always installed (e.g. for local OpenShift). Tolerate missing config maps.
  12. set +e
  13. BRIDGE_K8S_MODE_OFF_CLUSTER_THANOS=$(oc -n openshift-config-managed get configmap monitoring-shared-config -o jsonpath='{.data.thanosPublicURL}' 2>/dev/null)
  14. BRIDGE_K8S_MODE_OFF_CLUSTER_ALERTMANAGER=$(oc -n openshift-config-managed get configmap monitoring-shared-config -o jsonpath='{.data.alertmanagerPublicURL}' 2>/dev/null)
  15. set -e
  16. BRIDGE_K8S_AUTH_BEARER_TOKEN=$(oc whoami --show-token 2>/dev/null)
  17. BRIDGE_USER_SETTINGS_LOCATION="localstorage"
  18. # Don't fail if the cluster doesn't have gitops.
  19. set +e
  20. GITOPS_HOSTNAME=$(oc -n openshift-gitops get route cluster -o jsonpath='{.spec.host}' 2>/dev/null)
  21. set -e
  22. if [ -n "$GITOPS_HOSTNAME" ]; then
  23. BRIDGE_K8S_MODE_OFF_CLUSTER_GITOPS="https://$GITOPS_HOSTNAME"
  24. fi
  25. echo "API Server: $BRIDGE_K8S_MODE_OFF_CLUSTER_ENDPOINT"
  26. echo "Console Image: $CONSOLE_IMAGE"
  27. echo "Console URL: http://localhost:${CONSOLE_PORT}"
  28. # Prefer podman if installed. Otherwise, fall back to docker.
  29. if [ -x "$(command -v podman)" ]; then
  30. if [ "$(uname -s)" = "Linux" ]; then
  31. # Use host networking on Linux since host.containers.internal is unreachable in some environments.
  32. BRIDGE_PLUGINS="${npm_package_consolePlugin_name}=http://localhost:9001"
  33. podman run --pull always --rm --network=host --env-file <(set | grep BRIDGE) $CONSOLE_IMAGE
  34. else
  35. BRIDGE_PLUGINS="${npm_package_consolePlugin_name}=http://host.containers.internal:9001"
  36. podman run --pull always --rm -p "$CONSOLE_PORT":9000 --env-file <(set | grep BRIDGE) $CONSOLE_IMAGE
  37. fi
  38. else
  39. BRIDGE_PLUGINS="${npm_package_consolePlugin_name}=http://host.docker.internal:9001"
  40. docker run --pull always --rm -p "$CONSOLE_PORT":9000 --env-file <(set | grep BRIDGE) $CONSOLE_IMAGE
  41. fi