|
1 |
| -#!/usr/bin/env bash |
2 |
| - |
3 |
| -secretname=$(kubectl get serviceaccount default --namespace=kube-system -o jsonpath='{.secrets[0].name}') |
4 |
| -endpoint=$(kubectl config view -o json | jq '{myctx: .["current-context"], ctxs: .contexts[], clusters: .clusters[]}' | jq 'select(.myctx == .ctxs.name)' | jq 'select(.ctxs.context.cluster == .clusters.name)' | jq '.clusters.cluster.server' -r) |
5 |
| - |
6 |
| -args="--net=host" |
7 |
| -if [[ $OSTYPE == darwin* ]] || [[ "$(< /proc/version)" == *@(Microsoft|WSL)* ]]; then |
8 |
| - args="-p 9000:9000" |
9 |
| -fi |
10 |
| - |
11 |
| -docker pull quay.io/openshift/origin-console:latest |
12 |
| - |
13 |
| -echo "Using $endpoint" |
14 |
| -docker run -it $args \ |
15 |
| - -e BRIDGE_USER_AUTH="disabled" \ |
16 |
| - -e BRIDGE_K8S_MODE="off-cluster" \ |
17 |
| - -e BRIDGE_K8S_MODE_OFF_CLUSTER_ENDPOINT=$endpoint \ |
18 |
| - -e BRIDGE_K8S_MODE_OFF_CLUSTER_SKIP_VERIFY_TLS=true \ |
19 |
| - -e BRIDGE_K8S_AUTH="bearer-token" \ |
20 |
| - -e BRIDGE_K8S_AUTH_BEARER_TOKEN=$(kubectl get secret "$secretname" --namespace=kube-system -o template --template='{{.data.token}}' | base64 --decode) \ |
21 |
| - quay.io/openshift/origin-console:latest |
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Colors definition |
| 4 | +readonly RED=$(tput setaf 1) |
| 5 | +readonly RESET=$(tput sgr0) |
| 6 | +readonly BLUE=$(tput setaf 2) |
| 7 | + |
| 8 | +# Add port as 9000:9000 as arg when the SO is MacOS or Win |
| 9 | +add_host_port_arg (){ |
| 10 | + args="--net=host" |
| 11 | + if [[ "$OSTYPE" == "darwin"* ]] || [[ "$(< /proc/version)" == *"@(Microsoft|WSL)"* ]]; then |
| 12 | + args="-p 9000:9000" |
| 13 | + fi |
| 14 | +} |
| 15 | + |
| 16 | +pull_ocp_console_image (){ |
| 17 | + docker pull quay.io/openshift/origin-console:latest |
| 18 | +} |
| 19 | + |
| 20 | +run_docker_console (){ |
| 21 | + secretname=$(kubectl get serviceaccount default --namespace=kube-system -o jsonpath='{.secrets[0].name}') |
| 22 | + endpoint=$(kubectl config view -o json | jq '{myctx: .["current-context"], ctxs: .contexts[], clusters: .clusters[]}' | jq 'select(.myctx == .ctxs.name)' | jq 'select(.ctxs.context.cluster == .clusters.name)' | jq '.clusters.cluster.server' -r) |
| 23 | + |
| 24 | + echo -e "Using $endpoint" |
| 25 | + command -v docker run -it $args \ |
| 26 | + -e BRIDGE_USER_AUTH="disabled" \ |
| 27 | + -e BRIDGE_K8S_MODE="off-cluster" \ |
| 28 | + -e BRIDGE_K8S_MODE_OFF_CLUSTER_ENDPOINT=$endpoint \ |
| 29 | + -e BRIDGE_K8S_MODE_OFF_CLUSTER_SKIP_VERIFY_TLS=true \ |
| 30 | + -e BRIDGE_K8S_AUTH="bearer-token" \ |
| 31 | + -e BRIDGE_K8S_AUTH_BEARER_TOKEN=$(kubectl get secret "$secretname" --namespace=kube-system -o template --template='{{.data.token}}' | base64 --decode) \ |
| 32 | + quay.io/openshift/origin-console:latest &> /dev/null |
| 33 | + |
| 34 | + docker_exists=${?}; if [[ ${docker_exists} -ne 0 ]]; then |
| 35 | + echo -e "${BLUE}The OLM is accessible via web console at:${RESET}" |
| 36 | + echo -e "${BLUE}https://localhost:9000/${RESET}" |
| 37 | + else |
| 38 | + echo -e "${RED}Unable to run the console locally. May this port is in usage already. ${RESET}" |
| 39 | + echo -e "${RED}Check if the OLM is not accessible via web console at: https://localhost:9000/. ${RESET}" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +# Calling the functions |
| 47 | +add_host_port_arg |
| 48 | +pull_ocp_console_image |
| 49 | +run_docker_console |
| 50 | + |
| 51 | + |
0 commit comments