From 990150aabdbf159812f631360050fd9f4eb8967a Mon Sep 17 00:00:00 2001 From: stekole Date: Sun, 9 Feb 2025 23:31:55 -0500 Subject: [PATCH] Adding github actions tests --- .github/workflows/github-actions-demo.yaml | 4 +- run.sh | 96 +++++++++++++--------- test/k6.js | 2 +- 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/.github/workflows/github-actions-demo.yaml b/.github/workflows/github-actions-demo.yaml index 89ff1ef..ff92b03 100644 --- a/.github/workflows/github-actions-demo.yaml +++ b/.github/workflows/github-actions-demo.yaml @@ -88,7 +88,7 @@ jobs: # # minikube image load microblog # moved to run.sh - name: Setup TLS run: | - openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=microblog.dev" + openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/CN=example.com" kubectl create secret tls tls-secret --namespace=ingress-nginx --cert=tls.crt --key=tls.key -n ingress-nginx - name: Configure ingress with expect # why expect? :https://github.com/kubernetes/minikube/issues/8283 run: | @@ -136,4 +136,6 @@ jobs: kubectl get ingress -A curl -v -k https://example.com:${NODEPORT}/hello kubectl logs -n ingress-nginx -l app.kubernetes.io/component=controller + curl https://github.com/grafana/k6/releases/download/v0.56.0/k6-v0.56.0-linux-amd64.tar.gz -L | tar xvz + sudo cp k6-v0.56.0-linux-amd64/k6 /usr/local/bin k6 run --vus 10 ./test/k6.js diff --git a/run.sh b/run.sh index c128a2c..1e5ccb9 100755 --- a/run.sh +++ b/run.sh @@ -10,16 +10,52 @@ while [[ "$#" -gt 0 ]]; do esac shift done + # Install required tools on Mac if [[ "$OSTYPE" == "darwin"* ]]; then brew install docker k6 helm minikube kubectl kubectx go argocd elif [[ "$CICD" == true ]]; then + curl -LO https://github.com/kubernetes/minikube/releases/latest/download/minikube-linux-amd64 + sudo install minikube-linux-amd64 /usr/local/bin/minikube && rm minikube-linux-amd64 curl -sSL -o argocd-linux-amd64 https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64 sudo install -m 555 argocd-linux-amd64 /usr/local/bin/argocd rm argocd-linux-amd64 - sudo apt-get update; sudo apt-get install -y expect minikube + sudo apt-get update; sudo apt-get install -y expect fi +function wait_for_healthy_apps() { + local timeout=$1 + local start_time=$(date +%s) + + while true; do + current_time=$(date +%s) + elapsed=$((current_time - start_time)) + + if [ $elapsed -ge $timeout ]; then + echo "Timeout reached after $((timeout/60)) minutes - exiting" + return 1 + fi + + echo "Checking application health status... ${elapsed}s elapsed" + still_waiting=false + while IFS= read -r line; do + name=$(echo "$line" | awk '{print $1}') + status=$(echo "$line" | awk '{print $5}') + health=$(echo "$line" | awk '{print $6}') + if [ "$health" != "Healthy" ] || [ "$status" == "Unknown" ]; then + echo "App $name is in health:$health status:$status state" + still_waiting=true + fi + done < <(argocd app list | tail -n +2) + argocd app list | tail -n +2 + if [ "$still_waiting" == false ]; then + echo "All applications are healthy!" + return 0 + fi + sleep 5 + done +} + # Setup Kubernetes environment/ comment this out if not using minikube minikube start minikube addons enable registry @@ -37,7 +73,7 @@ if ! kubectl get namespace argocd &>/dev/null; then echo "Creating ArgoCD namespace and installing ArgoCD..." kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml - echo "sleeping for 40 seconds to allowing argo to start and deploy ... .. ." + echo "sleeping for 40 seconds to allowing argo to deploy and start ... .. ." sleep 40 else @@ -51,7 +87,7 @@ kubectl apply -f charts/bootstrap/ docker build . -t sample-app minikube image load sample-app -# echo "sleeping for 30 seconds to allowing argo to start and deploy ... .. ." +# echo "sleeping for 30 seconds to allowing argo to deploy and start ... .. ." # sleep 30 # Get ArgoCD admin password and setup port-forward @@ -82,50 +118,35 @@ ARGO_SECRET=$(kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpa echo "Waiting for argocd-server to be ready..." sleep 20 kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=argocd-server -n argocd --timeout=120s +# if [[ "$CICD" == true ]]; then +# echo "CICD is true, skipping argocd login" +# # this is busted +# argocd login $(minikube service argocd-server --url -n argocd) --username admin --password ${ARGO_SECRET} --insecure +# else +# kubectl port-forward svc/argocd-server -n argocd 8080:443 & +# argocd login localhost:8080 --username admin --password ${ARGO_SECRET} --insecure + +# fi +sleep 20 kubectl port-forward svc/argocd-server -n argocd 8080:443 & +sleep 5 argocd login localhost:8080 --username admin --password ${ARGO_SECRET} --insecure -timeout=600 # 10 minutes -start_time=$(date +%s) -while true; do - current_time=$(date +%s) - elapsed=$((current_time - start_time)) - - if [ $elapsed -ge $timeout ]; then - echo "Timeout reached after 5 minutes - exiting" - exit 1 - fi - - echo "Checking application health status... ${elapsed}s elapsed" - still_waiting=false - while IFS= read -r line; do - name=$(echo "$line" | awk '{print $1}') - status=$(echo "$line" | awk '{print $5}') - health=$(echo "$line" | awk '{print $6}') - if [ "$health" != "Healthy" ] || [ "$status" == "Unknown" ]; then - echo "App $name is in health:$health status:$status state" - still_waiting=true - #argocd app sync ${name} - fi - done < <(argocd app list | tail -n +2) - argocd app list | tail -n +2 - if [ "$still_waiting" == false ]; then - echo "All applications are healthy!" - break - fi - sleep 5 -done +timeout=600 # 10 minutes +wait_for_healthy_apps $timeout kubectl apply -f charts/monitoring/ sleep 10 # deploy the app through argocd kubectl apply -f charts/applications.yaml - -echo "shutting down the argocd port-forward" -pgrep -f "kubectl port-forward svc/argocd-server -n argocd 8080:443" | xargs kill -echo "" +wait_for_healthy_apps $timeout +if [[ "$CICD" == true ]]; then + echo "shutting down the argocd port-forward" + pgrep -f "kubectl port-forward svc/argocd-server -n argocd 8080:443" | xargs kill + echo "" +fi # Cleanup unset ARGO_SECRET @@ -149,3 +170,4 @@ Check out the readme for more detailed information - enjoy! EOF + diff --git a/test/k6.js b/test/k6.js index 9628959..7b784c7 100644 --- a/test/k6.js +++ b/test/k6.js @@ -7,7 +7,7 @@ const BASE_URL = __ENV.BASE_URL || 'https://example.com'; export const options = { stages: [ { duration: '30s', target: 100 }, - { duration: '15m', target: 1000 }, + { duration: '1m', target: 1000 }, { duration: '30s', target: 0 }, ], thresholds: {