Skip to content

Commit

Permalink
Handle to get hostname IP
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Nov 13, 2024
1 parent 640539a commit 1646d11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ KEDA_TAG_PREV_VERSION := $(or $(KEDA_TAG_PREV_VERSION),$(KEDA_TAG_PREV_VERSION),
KEDA_TAG_VERSION := $(or $(KEDA_TAG_VERSION),$(KEDA_TAG_VERSION),2.16.0-selenium-grid)
KEDA_BASED_NAME := $(or $(KEDA_BASED_NAME),$(KEDA_BASED_NAME),ndviet)
KEDA_BASED_TAG := $(or $(KEDA_BASED_TAG),$(KEDA_BASED_TAG),2.16.0-selenium-grid)
LOCAL_HOSTNAME := $(shell hostname -I | awk '{for(i=1;i<=NF;i++) if ($$i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$$/) {print $$i; exit}}')

all: hub \
distributor \
Expand All @@ -50,6 +51,7 @@ all: hub \
video

check_dev_env:
echo $(LOCAL_HOSTNAME)
./tests/charts/make/chart_check_env.sh

setup_dev_env:
Expand Down Expand Up @@ -830,7 +832,7 @@ test_node_docker: hub standalone_docker standalone_chrome standalone_firefox sta
echo UID=$$(id -u) >> .env ; \
echo BINDING_VERSION=$(BINDING_VERSION) >> .env ; \
echo BASE_VERSION=$(BASE_VERSION) >> .env ; \
echo HOST_IP=$$(hostname -I | awk '{print $$1}') >> .env ; \
echo HOST_IP=$(LOCAL_HOSTNAME) >> .env ; \
if [ "$(PLATFORMS)" = "linux/amd64" ]; then \
NODE_EDGE=edge ; \
NODE_CHROME=chrome ; \
Expand Down Expand Up @@ -910,7 +912,7 @@ chart_render_template:

chart_test_autoscaling_disabled:
PLATFORMS=$(PLATFORMS) TEST_CHROMIUM=true RELEASE_NAME=selenium SELENIUM_GRID_AUTOSCALING=false CHART_ENABLE_TRACING=true \
SECURE_INGRESS_ONLY_GENERATE=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -i) SELENIUM_GRID_PORT=443 EXTERNAL_UPLOADER_CONFIG=true \
SECURE_INGRESS_ONLY_GENERATE=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$(LOCAL_HOSTNAME) SELENIUM_GRID_PORT=443 EXTERNAL_UPLOADER_CONFIG=true \
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) KEDA_BASED_NAME=$(KEDA_BASED_NAME) KEDA_BASED_TAG=$(KEDA_BASED_TAG) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) BASE_VERSION=$(BASE_VERSION) \
TEMPLATE_OUTPUT_FILENAME="k8s_nodeChromium_enableTracing_secureIngress_generateCerts_ingressPublicIP_subPath.yaml" \
./tests/charts/make/chart_test.sh NoAutoscaling
Expand All @@ -925,7 +927,7 @@ chart_test_autoscaling_deployment_https:

chart_test_autoscaling_deployment:
PLATFORMS=$(PLATFORMS) TEST_EXISTING_KEDA=true RELEASE_NAME=selenium CHART_ENABLE_TRACING=true TEST_PATCHED_KEDA=false \
SECURE_CONNECTION_SERVER=true SECURE_USE_EXTERNAL_CERT=true SERVICE_TYPE_NODEPORT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -i) SELENIUM_GRID_PORT=31444 \
SECURE_CONNECTION_SERVER=true SECURE_USE_EXTERNAL_CERT=true SERVICE_TYPE_NODEPORT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$(LOCAL_HOSTNAME) SELENIUM_GRID_PORT=31444 \
SELENIUM_GRID_AUTOSCALING_MIN_REPLICA=1 SET_MAX_REPLICAS=3 TEST_DELAY_AFTER_TEST=2 SELENIUM_GRID_MONITORING=false \
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) KEDA_BASED_NAME=$(KEDA_BASED_NAME) KEDA_BASED_TAG=$(KEDA_BASED_TAG) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) BASE_VERSION=$(BASE_VERSION) \
TEMPLATE_OUTPUT_FILENAME="k8s_prefixSelenium_enableTracing_secureServer_externalCerts_nodePort_autoScaling_scaledObject_existingKEDA_subPath.yaml" \
Expand All @@ -941,7 +943,7 @@ chart_test_autoscaling_job_https:

chart_test_autoscaling_job_hostname:
PLATFORMS=$(PLATFORMS) CHART_ENABLE_TRACING=true CHART_ENABLE_BASIC_AUTH=true BASIC_AUTH_EMBEDDED_URL=true TEST_PATCHED_KEDA=false \
SECURE_INGRESS_ONLY_DEFAULT=true SECURE_USE_EXTERNAL_CERT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -i) SELENIUM_GRID_PORT=443 \
SECURE_INGRESS_ONLY_DEFAULT=true SECURE_USE_EXTERNAL_CERT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$(LOCAL_HOSTNAME) SELENIUM_GRID_PORT=443 \
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) KEDA_BASED_NAME=$(KEDA_BASED_NAME) KEDA_BASED_TAG=$(KEDA_BASED_TAG) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) BASE_VERSION=$(BASE_VERSION) \
TEMPLATE_OUTPUT_FILENAME="k8s_enableTracing_basicAuth_secureIngress_externalCerts_ingressPublicIP_autoScaling_originKEDA_scaledJob_subPath.yaml" \
./tests/charts/make/chart_test.sh JobAutoscaling
Expand All @@ -956,7 +958,7 @@ chart_test_autoscaling_job:
chart_test_autoscaling_playwright_connect_grid:
PLATFORMS=$(PLATFORMS) CHART_ENABLE_TRACING=true CHART_ENABLE_BASIC_AUTH=true MATRIX_TESTS=CDPTests SCALING_STRATEGY=accurate \
BASIC_AUTH_USERNAME=docker-selenium BASIC_AUTH_PASSWORD=2NMI4jdBi6k7bENoeUfV25295VvzwAE9chM24a+2VL95uOHozo \
SECURE_INGRESS_ONLY_DEFAULT=true SECURE_USE_EXTERNAL_CERT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$$(hostname -i) SELENIUM_GRID_PORT=443 \
SECURE_INGRESS_ONLY_DEFAULT=true SECURE_USE_EXTERNAL_CERT=true SELENIUM_GRID_PROTOCOL=https SELENIUM_GRID_HOST=$(LOCAL_HOSTNAME) SELENIUM_GRID_PORT=443 \
VERSION=$(TAG_VERSION) VIDEO_TAG=$(FFMPEG_TAG_VERSION)-$(BUILD_DATE) KEDA_BASED_NAME=$(KEDA_BASED_NAME) KEDA_BASED_TAG=$(KEDA_BASED_TAG) NAMESPACE=$(NAMESPACE) BINDING_VERSION=$(BINDING_VERSION) BASE_VERSION=$(BASE_VERSION) \
TEMPLATE_OUTPUT_FILENAME="k8s_playwright_connect_grid_basicAuth_secureIngress_ingressPublicIP_autoScaling_patchKEDA.yaml" \
./tests/charts/make/chart_test.sh JobAutoscaling
Expand Down
2 changes: 1 addition & 1 deletion charts/selenium-grid/certs/gen-cert-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ SERVER_KEYSTORE=${SERVER_KEYSTORE:-server.jks}
SERVER_KEYSTORE_PASSPWD=${SERVER_KEYSTORE_PASSPWD:-server.pass}
BASE64_ONLY=${BASE64_ONLY:-0}
if [ -n "${ADD_IP_ADDRESS}" ] && [ "${ADD_IP_ADDRESS}" = "hostname" ]; then
ADD_IP_ADDRESS=",IP:$(hostname -I | awk '{print $1}')"
ADD_IP_ADDRESS=",IP:$(hostname -I | awk '{for(i=1;i<=NF;i++) if ($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {printf "%s%s", sep, $i; sep=",IP:"}}')"
else
ADD_IP_ADDRESS=${ADD_IP_ADDRESS}
fi
Expand Down
11 changes: 6 additions & 5 deletions tests/charts/make/chart_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TEST_PATCHED_KEDA=${TEST_PATCHED_KEDA:-"false"}
BASIC_AUTH_EMBEDDED_URL=${BASIC_AUTH_EMBEDDED_URL:-"false"}
SELENIUM_GRID_MONITORING=${SELENIUM_GRID_MONITORING:-"true"}
TEST_EXISTING_PTS=${TEST_EXISTING_PTS:-"false"}
LOCAL_HOSTNAME=$(hostname -I | awk '{for(i=1;i<=NF;i++) if ($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {print $i; exit}}')

cleanup() {
# Get the list of pods
Expand Down Expand Up @@ -191,16 +192,16 @@ fi

if [ "${CHART_ENABLE_INGRESS_HOSTNAME}" = "true" ]; then
if [[ ! $(cat /etc/hosts) == *"${HOSTNAME_ADDRESS}"* ]]; then
sudo -- sh -c -e "echo \"$(hostname -i) ${HOSTNAME_ADDRESS}\" >> /etc/hosts"
sudo -- sh -c -e "echo \"${LOCAL_HOSTNAME} ${HOSTNAME_ADDRESS}\" >> /etc/hosts"
fi
if [[ ! $(cat /etc/hosts) == *"alertmanager.${HOSTNAME_ADDRESS}"* ]]; then
sudo -- sh -c -e "echo \"$(hostname -i) alertmanager.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
sudo -- sh -c -e "echo \"${LOCAL_HOSTNAME} alertmanager.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
fi
if [[ ! $(cat /etc/hosts) == *"grafana.${HOSTNAME_ADDRESS}"* ]]; then
sudo -- sh -c -e "echo \"$(hostname -i) grafana.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
sudo -- sh -c -e "echo \"${LOCAL_HOSTNAME} grafana.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
fi
if [[ ! $(cat /etc/hosts) == *"pts.${HOSTNAME_ADDRESS}"* ]]; then
sudo -- sh -c -e "echo \"$(hostname -i) pts.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
sudo -- sh -c -e "echo \"${LOCAL_HOSTNAME} pts.${HOSTNAME_ADDRESS}\" >> /etc/hosts"
fi
ping -c 2 ${HOSTNAME_ADDRESS}
HELM_COMMAND_SET_IMAGES="${HELM_COMMAND_SET_IMAGES} \
Expand Down Expand Up @@ -250,7 +251,7 @@ if [ "${SECURE_INGRESS_ONLY_GENERATE}" = "true" ] && [ "${RENDER_HELM_TEMPLATE_O
--set tls.ingress.generateTLS=true \
--set tls.ingress.defaultCN=${SELENIUM_GRID_HOST} \
--set tls.ingress.defaultSANList[0]=${SELENIUM_GRID_HOST} \
--set tls.ingress.defaultIPList[0]=$(hostname -I | awk '{print $1}') \
--set tls.ingress.defaultIPList[0]=${LOCAL_HOSTNAME} \
"
fi

Expand Down

0 comments on commit 1646d11

Please sign in to comment.