start-console.sh 2.5 KB

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