Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2E: Use Helm instead of Docker #10897

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ on:
description: 'Environment to run tests against'
type: environment
required: true

env:
TEST_USERNAME: admin
TEST_PASSWORD: password
CATTLE_BOOTSTRAP_PASSWORD: password
TEST_BASE_URL: https://127.0.0.1/dashboard
API: https://127.0.0.1
TEST_BASE_URL: https://127.0.0.1.sslip.io
API: https://127.0.0.1.sslip.io
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}}
Expand All @@ -37,30 +37,29 @@ jobs:
if: "!contains( github.event.pull_request.labels.*.name, 'ci/skip-e2e')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup env
uses: ./.github/actions/setup
- 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

- uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Setup env
uses: ./.github/actions/setup
- 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

e2e-test:
if: "!contains( github.event.pull_request.labels.*.name, 'ci/skip-e2e')"
Expand Down Expand Up @@ -114,7 +113,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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
"cy:run:sorry": "./scripts/e2e $SPEC_FILE",
"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=false ./scripts/build-e2e",
"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 $RANCHER_VERSION_E2E",
"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",
"e2e:prod": "BUILD_DASHBOARD=$BUILD_DASHBOARD GREP_TAGS=$GREP_TAGS TEST_USERNAME=$TEST_USERNAME TEST_BASE_URL=$TEST_BASE_URL/dashboard API=$API yarn cy:run:sorry",
"coverage": "npx nyc merge coverage coverage/coverage.json",
"storybook": "cd storybook && yarn install && yarn storybook",
"build-storybook": "cd storybook && yarn install --no-lockfile && NODE_OPTIONS=--max_old_space_size=4096 yarn build-storybook --quiet",
Expand Down
119 changes: 119 additions & 0 deletions scripts/e2e-k3s-start
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#!/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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be passed in?

DASHBOARD_URL="${TEST_BASE_URL#https://}"
NAMESPACE=cattle-system

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 -
export KUBECONFIG=~/.kube/config
mkdir ~/.kube 2> /dev/null
sudo k3s kubectl config view --raw > "$KUBECONFIG"
chmod 600 "$KUBECONFIG"

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 "Cert manager pods should be up"
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 $NAMESPACE
helm install rancher rancher-latest/rancher \
--namespace cattle-system \
--set hostname=$DASHBOARD_URL \
--set replicas="1" \
--set rancherImage="rancher/rancher" \
--set rancherImageTag="$RANCHER_IMG_VERSION" \
--set rancherImagePullPolicy="Always" \
--set extraEnv\[0\].name="CATTLE_AGENT_IMAGE" \
--set-string extraEnv\[0\].value="rancher/rancher:$RANCHER_IMG_VERSION" \
--set extraEnv\[1\].name="CATTLE_UI_OFFLINE_PREFERRED" \
--set-string extraEnv\[1\].value="true" \
--set extraEnv\[2\].name="CATTLE_BOOTSTRAP_PASSWORD" \
--set-string extraEnv\[2\].value="password" \
--set extraEnv\[3\].name="CATTLE_PASSWORD_MIN_LENGTH" \
--set-string extraEnv\[3\].value="3"

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

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

okay=0

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

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.........."
# Note - these will pick the first container within the pod, so replicas=1 above is important
POD_NAME=$(kubectl get pods --selector=app=rancher -n $NAMESPACE | tail -n 1 | cut -d ' ' -f1)
echo "POD NAME: $POD_NAME"
if [ "$POD_NAME" == "" ]; then
echo "Failed to find rancher pod"
exit 1
fi

# Remove root folders that container UIs
kubectl exec $POD_NAME -n $NAMESPACE -- sh -c 'rm -rf /usr/share/rancher/ui-dashboard/dashboard'
kubectl exec $POD_NAME -n $NAMESPACE -- sh -c 'rm -rf /usr/share/rancher/ui'

# Copy local builds to root folders that should contain UIs
mv $DASHBOARD_DIST dashboard
mv $EMBER_DIST ui
kubectl cp dashboard $POD_NAME:/usr/share/rancher/ui-dashboard -n $NAMESPACE
kubectl cp ui $POD_NAME:/usr/share/rancher -n $NAMESPACE

# Final validation
STATUS=$(curl --silent --location --head -k $DASHBOARD_URL/dashboard/ | awk -F'HTTP/2 ' '{print $2}' | awk 'length { print $1}')
echo "Status: $STATUS"

if [ "$STATUS" != "200" ]; then
echo "After updating dashboard with dev build it is no longer available"
exit 1
fi

echo "Dashboard UI is ready"
Loading