Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Apr 26, 2024
1 parent a6039e6 commit 262ccfd
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 1 deletion.
63 changes: 63 additions & 0 deletions .github/workflows/temp-test-k3s.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: temp test
on:
push:
branches:
- e2e-k3s

env:
TEST_USERNAME: admin
TEST_PASSWORD: password
CATTLE_BOOTSTRAP_PASSWORD: password
TEST_BASE_URL: https://127.0.0.1:8005
API: https://127.0.0.1
TEST_PROJECT_ID: rancher-dashboard
CYPRESS_API_URL: http://139.59.134.103:1234/
TEST_RUN_ID: ${{github.run_number}}-${{github.run_attempt}}-${{github.event.pull_request.title || github.event.head_commit.message}}
# Build the dashboard to use in tests. When set to false it will grab `latest` from CDN (useful for running e2e tests quickly)
BUILD_DASHBOARD: false

E2E_BUILD_DIST_NAME: dist
E2E_BUILD_DIST_DIR: dist
E2E_BUILD_DIST_EMBER_NAME: dist_ember
E2E_BUILD_DIST_EMBER_DIR: dist_ember

jobs:
# e2e-ui-build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# with:
# fetch-depth: 1
# - uses: actions/setup-node@v3
# with:
# node-version: '14.x'
# cache: 'yarn'
# - name: Install packages
# run: yarn install:ci
# - name: Build e2e
# run: yarn e2e:build
# - name: Upload e2e build
# uses: actions/upload-artifact@v4
# with:
# name: ${{ env.E2E_BUILD_DIST_NAME }}
# path: ${{ env.E2E_BUILD_DIST_DIR }}/
# if-no-files-found: error
# retention-days: 10
# compression-level: 9
# - name: Upload e2e build ember
# uses: actions/upload-artifact@v4
# with:
# name: ${{ env.E2E_BUILD_DIST_EMBER_NAME }}
# path: ${{ env.E2E_BUILD_DIST_EMBER_DIR }}/
# if-no-files-found: error
# retention-days: 10
# compression-level: 9
test-k3s:
# needs: e2e-ui-build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Run Rancher
run: yarn e2e:k3s
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
if-no-files-found: error
retention-days: 10
compression-level: 9

e2e-test:
if: "!contains( github.event.pull_request.labels.*.name, 'ci/skip-e2e')"
needs: e2e-ui-build
Expand Down Expand Up @@ -118,7 +119,7 @@ jobs:
path: ${{ env.E2E_BUILD_DIST_EMBER_DIR }}

- name: Run Rancher
run: yarn e2e:docker
run: yarn e2e:k3s

- name: Setup Rancher and user
run: |
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"e2e:pre-dev": "yarn docker:local:stop && yarn docker:local:start && NODE_ENV=dev TEST_INSTRUMENT=true yarn build",
"e2e:dev": "START_SERVER_AND_TEST_INSECURE=1 server-test start:dev https-get://localhost:8005 cy:run:sorry",
"e2e:build": "mkdir dist && TEST_INSTRUMENT=true ./scripts/build-e2e",
"e2e:k3s": "./scripts/e2e-k3s-start",
"e2e:docker": "yarn docker:local:stop && ./scripts/e2e-docker-start ",
"e2e:prod": "BUILD_DASHBOARD=$BUILD_DASHBOARD GREP_TAGS=$GREP_TAGS TEST_USERNAME=$TEST_USERNAME TEST_BASE_URL=https://127.0.0.1/dashboard yarn cy:run:sorry",
"coverage": "npx nyc merge coverage coverage/coverage.json",
Expand Down
130 changes: 130 additions & 0 deletions scripts/e2e-k3s-start
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env bash

K3S_VERSION=v1.28.8+k3s1

# Image version
# RANCHER_IMG_VERSION=v2.9-c9be13b09329bbee60a5f6419d500198f83c44d1-head
RANCHER_IMG_VERSION=v2.9-head
DASHBOARD_URL=127.0.0.1.sslip.io

DIR=$(cd $(dirname $0)/..; pwd)

# See `script/build-e2e`. This is the ui builds we wish to test
DASHBOARD_DIST=${DIR}/dist
EMBER_DIST=${DIR}/dist_ember

echo "Installing k3s (with kubectl)....."
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="$K3S_VERSION" sh -

sudo k3s kubectl get nodes
k3s kubectl get nodes
kubectl get nodes


# okay=0

# while [ $okay -lt 20 ]; do
# STATUS=$(curl --silent --head -k http://localhost:8080/version | awk '/^HTTP/{print $2}')

# echo "Status: $STATUS (Try: $okay)"

# okay=$((okay+1))

# if [ "$STATUS" == "200" ]; then
# okay=100
# else
# sleep 5
# fi
# done

# if [ "$STATUS" != "200" ]; then
# echo "Dashboard did not become available in a reasonable time"
# exit 1
# fi



echo "Installing helm....."
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

echo "Installing cert-manager....."
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.7.1/cert-manager.crds.yaml
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install cert-manager jetstack/cert-manager \
--namespace cert-manager \
--create-namespace \
--version v1.7.1

echo "Wait for cert manager to come up..... TODO: RC"
kubectl get pods --namespace cert-manager

echo "Setting up Rancher Repo....."
helm repo add rancher-latest https://releases.rancher.com/server-charts/latest
helm repo update

# TODO: RC wire in host name to e2e tests

echo "Installing Rancher....."
kubectl create ns cattle-system
helm install rancher rancher-latest/rancher \
--namespace cattle-system \
--set hostname=$DASHBOARD_URL \
--set replicas=1 \
--set 'extraEnv[0].name=CATTLE_AGENT_IMAGE' \
--set 'extraEnv[0].value=rancher/rancher:$RANCHER_IMG_VERSION' \
--set rancherImage=rancher/rancher \
--set rancherImageTag=$RANCHER_IMG_VERSION \
--set rancherImagePullPolicy=Always \
--set 'extraEnv[0].name=CATTLE_UI_OFFLINE_PREFERRED' \
--set 'extraEnv[0].value=true' \
--set 'extraEnv[0].name=CATTLE_BOOTSTRAP_PASSWORD' \
--set 'extraEnv[0].value=password' \
--set passwordMinLength=3 \

echo "Waiting for Rancher to come up..."
# Wait for Rancher to come up
kubectl -n cattle-system rollout status deploy/rancher

echo "Waiting for dashboard UI to be reachable (initial 20s wait) ..."

sleep 20

echo "Waiting for dashboard UI to be reachable ..."

okay=0

while [ $okay -lt 20 ]; do
STATUS=$(curl --silent --head -k $DASHBOARD_URL/dashboard/ | awk '/^HTTP/{print $2}')

echo "Status: $STATUS (Try: $okay)"

okay=$((okay+1))

if [ "$STATUS" == "200" ]; then
okay=100
else
sleep 5
fi
done

if [ "$STATUS" != "200" ]; then
echo "Dashboard did not become available in a reasonable time"
exit 1
fi

echo "Updating UI within Rancher container"

# Map latest build into Rancher TODO: RC
POD_NAME=${kubectl get pods --selector=app=rancher -n cattle-system | tail -n 1 | cut -d ' ' -f1|tr '\n' ' '}
echo "POD NAME: $POD_NAME"

# Note - these will pick the first container within the pod, so replicas=1 above is imporatnt
kubectl cp $DASHBOARD_DIST $POD_NAME:/usr/share/rancher/ui-dashboard/dashboard # TODO: RC probably copeis folder INTO target folder
kubectl cp $EMBER_DIST $POD_NAME:/usr/share/rancher/ui # TODO: RC probably copeis folder INTO target folder
# -v ${DASHBOARD_DIST}:/usr/share/rancher/ui-dashboard/dashboard \
# -v ${EMBER_DIST}:/usr/share/rancher/ui \

echo "Dashboard UI is ready"

0 comments on commit 262ccfd

Please sign in to comment.