From 32af3063d87efea8549ef62a893e8c53384ad7c2 Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Thu, 16 Jan 2025 08:54:32 +0100 Subject: [PATCH] adding steps to the action --- .github/workflows/a.yml | 32 +++++------ scripts/pit/lib/lib-cc.sh | 90 ++++++++----------------------- scripts/pit/lib/lib-playwright.sh | 2 + scripts/pit/lib/lib-utils.sh | 16 +++--- 4 files changed, 45 insertions(+), 95 deletions(-) diff --git a/.github/workflows/a.yml b/.github/workflows/a.yml index c36adc91..c504a0d3 100644 --- a/.github/workflows/a.yml +++ b/.github/workflows/a.yml @@ -18,34 +18,30 @@ jobs: echo "export PATH='$PATH'" > path.sh apt-get update apt-get install -y vim iputils-ping sudo unzip wget jq curl - npm install playwright - ./node_modules/.bin/playwright install-deps >/dev/null - ./node_modules/.bin/playwright install chromium + # npm install playwright + # ./node_modules/.bin/playwright install-deps >/dev/null + # ./node_modules/.bin/playwright install chromium - - uses: browser-actions/setup-chrome@latest - with: - chrome-version: stable + # - uses: browser-actions/setup-chrome@latest + # with: + # chrome-version: stable - uses: actions/setup-node@v4 with: node-version: '18' - - uses: actions/setup-java@v4 - with: - java-version: '21' - distribution: 'temurin' - - uses: stCarolas/setup-maven@v5 - with: - maven-version: '3.9.0' + # - uses: actions/setup-java@v4 + # with: + # java-version: '21' + # distribution: 'temurin' + # - uses: stCarolas/setup-maven@v5 + # with: + # maven-version: '3.9.0' - name: Set up Helm uses: azure/setup-helm@v3.5 - name: Create k8s Kind Cluster uses: helm/kind-action@v1 with: install_only: false - # - name: Install Socat - # run: | - # sudo apt-get update - # sudo apt-get install -y socat - - name: Instal Kind and Control Center + - name: Run PiT env: CC_KEY: ${{ secrets.CC_KEY }} CC_CERT: ${{ secrets.CC_CERT }} diff --git a/scripts/pit/lib/lib-cc.sh b/scripts/pit/lib/lib-cc.sh index 26598c92..e51e52ec 100644 --- a/scripts/pit/lib/lib-cc.sh +++ b/scripts/pit/lib/lib-cc.sh @@ -10,25 +10,12 @@ CC_TLS=control-center-tls CC_CLUSTER=cc-cluster CC_NS=control-center -getPids() { - H=`grep -a "" /proc/*/cmdline 2>/dev/null | xargs -0 | grep -v grep | perl -pe 's|/proc/(.*?)/cmdline:|$1 |g'` - if [ -n "$H" ] - then - _P=`echo "$H" | grep "$1" | awk '{print $1}'` - else - _P=`ps -feaw | grep "$1" | grep -v grep | awk '{print $2}'` - fi - [ -n "$_P" ] && echo "$_P" && return 0 || return 1 -} - startCloudProvider() { docker container inspect kind-cloud-provider >/dev/null 2>&1 && log "Docker Kind Cloud Provider already running" && return - log "Starting Docker KinD Cloud Provider" - cmd="docker run --name kind-cloud-provider --rm -d --network kind \ - -v /var/run/docker.sock:/var/run/docker.sock \ - rophy/cloud-provider-kind:0.4.0-20241026-r1" - echo "#" $cmd - eval "$cmd" + runCmd "$TEST" "Starting Docker KinD Cloud Provider" \ + "docker run --name kind-cloud-provider --rm -d --network kind \ + -v /var/run/docker.sock:/var/run/docker.sock \ + rophy/cloud-provider-kind:0.4.0-20241026-r1" } stopCloudProvider() { @@ -40,17 +27,18 @@ startPortForward() { [ -z "$3" ] && echo "startPortForward name-space service port" && return 1 H=`getPids "kubectl port-forward $2"` [ -n "$H" ] && return 0 - + KUBECTL=`which kubectl` log "Starting k8s port-forward $1 $2 $3 -> $4" if isLinux || isMac ; then - sudo KUBECONFIG="$HOME/.kube/config" kubectl port-forward $2 $4:$3 -n $1 & + log "listening to ports <1024 requires sudo, type your password if requested" + sudo true || return 1 + sudo KUBECONFIG="$HOME/.kube/config" $KUBECTL port-forward $2 $4:$3 -n $1 & else - kubectl port-forward $2 $4:$3 -n $1 & + $KUBECTL port-forward $2 $4:$3 -n $1 & fi } stopPortForward() { - set -x H=`getPids kubectl "port-forward service/$1"` [ -z "$H" ] && return 0 log "Stoping k8s port-forward $1 (pid $H)" @@ -66,22 +54,21 @@ stopForwardIngress() { } createCluster() { - log "Creating cluster" - echo "# kind create cluster --name $CC_CLUSTER" - kind create cluster --name $CC_CLUSTER || return 1 - kubectl config use-context kind-$CC_CLUSTER - kubectl config set-context --current --namespace=$CC_NS + runCmd "$TEST" "Creating KinD cluster: $CC_CLUSTER" \ + "kind create cluster --name $CC_CLUSTER" || return 1 + runCmd "$TEST" "Setting default namespace $CC_NS" \ + "kubectl config set-context --current --namespace=$CC_NS" } deleteCluster() { - log "Deleting cluster" - kind delete cluster --name $CC_CLUSTER + runCmd "$TEST" "Deleting Cluster $CC_CLUSTER" \ + "kind delete cluster --name $CC_CLUSTER" || return 1 } installCC() { - log "Installing Control Center" - [ -n "$DEBUG" ] && D=--debug - cmd="helm install control-center oci://docker.io/vaadin/control-center \ + [ -n "$VERBOSE" ] && D=--debug + runCmd "$TEST" "Installing Vaadin Control Center" \ + "helm install control-center oci://docker.io/vaadin/control-center \ -n $CC_NS --create-namespace \ --set domain=$CC_DOMAIN \ --set user.email=$CC_EMAIL \ @@ -91,8 +78,6 @@ installCC() { --set keycloak.tlsSecret=$CC_TLS \ --set livenessProbe.failureThreshold=10 \ --wait $D" - echo "#" $cmd - eval $cmd || return 1 } waitForCC() { @@ -114,41 +99,6 @@ waitForCC() { done } -installDashBoard() { - helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard \ - --create-namespace --namespace kubernetes-dashboard || return 1 - - cat << EOF | kubectl create -n kubernetes-dashboard -f - >/dev/null 2>&1 -apiVersion: v1 -kind: ServiceAccount -metadata: - name: admin-user - namespace: kubernetes-dashboard ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: admin-user -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: cluster-admin -subjects: -- kind: ServiceAccount - name: admin-user - namespace: kubernetes-dashboard -EOF -cc_auth=`kubectl -n kubernetes-dashboard create token admin-user` -[ -z "$cc_auth" ] && return 1 -startPortForward kubernetes-dashboard service/kubernetes-dashboard-kong-proxy 443 8443 -log "Login into dashboard with this token: $cc_auth" -} - -uninstallDashBoard() { - stopPortForward kubernetes-dashboard - kubectl delete ns kubernetes-dashboard -} - uninstallCC() { kubectl delete ns $CC_NS kubectl delete ns ingress-nginx @@ -160,7 +110,8 @@ installTls() { echo -e "$CC_CERT" > $f1 f2=/tmp/cc-tls.key echo -e "$CC_KEY" > $f2 - kubectl -n $CC_NS create secret tls $CC_TLS --key "$f2" --cert "$f1" + runCmd "$TEST" "Creating TLS secret $CC_TLS" \ + "kubectl -n $CC_NS create secret tls $CC_TLS --key '$f2' --cert '$f1'" rm -f $f1 $f2 } @@ -182,6 +133,7 @@ runControlCenter() { test=`computeAbsolutePath`/its/cc-setup.js checkPort 443 || return 1 runPlaywrightTests "$test" "" "prod" "control-center" --url=https://$CC_CONTROL --email=$CC_EMAIL + stopForwardIngress deleteCluster ;; stop) diff --git a/scripts/pit/lib/lib-playwright.sh b/scripts/pit/lib/lib-playwright.sh index e70fb390..3f6888e0 100644 --- a/scripts/pit/lib/lib-playwright.sh +++ b/scripts/pit/lib/lib-playwright.sh @@ -35,6 +35,8 @@ runPlaywrightTests() { _pfile="playwright-$_mode-"`uname`".out" [ -f "$_test_file" ] && checkPlaywrightInstallation "$_test_file" || return 0 + + set +x _args="$* --name=$_name --mode=$_mode" isHeadless && _args="$_args --headless" PATH=$PATH runToFile "'$NODE' '$_test_file' $_args" "$_pfile" "$VERBOSE" true diff --git a/scripts/pit/lib/lib-utils.sh b/scripts/pit/lib/lib-utils.sh index 538e9377..acb4a766 100644 --- a/scripts/pit/lib/lib-utils.sh +++ b/scripts/pit/lib/lib-utils.sh @@ -37,14 +37,14 @@ restoreProKey() { ## get pids for process getPids() { - if type pgrep >/dev/null 2>&1; then - _P=`pgrep "$1"` - elif type tasklist >/dev/null 2>&1; then - _P=`tasklist | findstr "$1" | awk '{print $2}'` - else - err "No pgrep or tasklist installed" && exit 1 + H=`grep -a "" /proc/*/cmdline 2>/dev/null | xargs -0 | grep -v grep | perl -pe 's|/proc/(.*?)/cmdline:|$1 |g'` + if [ -n "$H" ] + then + _P=`echo "$H" | grep "$1" | awk '{print $1}'` + else + _P=`ps -feaw | grep "$1" | grep -v grep | awk '{print $2}'` fi - [ -n "$_P" ] && echo "$_P" && return 0 || return 1 + [ -n "$_P" ] && echo "$_P" | tr "\n" " " && return 0 || return 1 } ## Kills a process with its children and wait until complete @@ -95,7 +95,7 @@ warn() { print '> ' 0 33 "$*" } cmd() { - cmd_=`printf "$*" | perl -pe 's|\n|\\\\\\\n|g'` + cmd_=`printf "$*" | tr -s " " | perl -pe 's|\n|\\\\\\\n|g'` print ' ' 1 34 " $cmd_" } dim() {