start-console.sh 2.5 KB

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