diff --git a/.github/workflows/crc.yaml b/.github/workflows/crc.yaml new file mode 100644 index 000000000..06ebf9285 --- /dev/null +++ b/.github/workflows/crc.yaml @@ -0,0 +1,73 @@ +name: Test Tekton-Cache on CRC +on: + push: + branches: + - main + +jobs: + build: + name: Run E2E Tests on CRC + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + go: + - '1.22' + env: + SHELL: /bin/bash + KUBECONFIG: '/Users/runner/.kube/config' + + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + with: + ref: ${{ github.sha }} + - uses: imjasonh/setup-ko@v0.7 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ matrix.go }} + - name: Download and install CRC + run: | + wget "https://developers.redhat.com/content-gateway/file/pub/openshift-v4/clients/crc/2.40.0/crc-linux-amd64.tar.xz" + tar -xf crc-linux-amd64.tar.xz --directory /usr/local/bin --strip-components=1 crc-linux-2.40.0-amd64/crc + - name: Testing CRC + run: | + which crc + crc --help + + - name: Install required virtualization software + run: | + sudo apt-get update + sudo apt install qemu-kvm libvirt-daemon libvirt-daemon-system + sudo usermod -a -G libvirt $USER + + - name: Install yq + run: | + sudo wget https://github.com/mikefarah/yq/releases/download/v4.31.2/yq_linux_amd64 -O /usr/local/bin/yq + sudo chmod +x /usr/local/bin/yq + yq --version + + - name: Set the crc config + env: + PULL_SECRET_CONTENT: ${{ secrets.CRC_TOKEN }} + run: | + crc config set preset microshift + echo "$PULL_SECRET_CONTENT" > pull-secret + crc config set pull-secret-file pull-secret + crc config set network-mode user + crc config set memory 14000 + - name: Setup the crc + run: sudo -su $USER crc setup + - name: Start the crc + run: sudo -su $USER crc start + - name: Set Creds + run: | + sudo -su $USER crc oc-env + echo "KUBECONFIG=$HOME/.crc/machines/crc/kubeconfig" >> $GITHUB_ENV + + + - name: Install Tekton Pipelines + run: | + chmod +x tests/crc_test.sh + ./tests/crc_test.sh diff --git a/tests/crc_test.sh b/tests/crc_test.sh new file mode 100644 index 000000000..6cb338acf --- /dev/null +++ b/tests/crc_test.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +function start_registry() { + running="$(docker inspect -f '{{.State.Running}}' ${REG_NAME} 2>/dev/null || echo false)" + + if [[ ${running} != "true" ]];then + docker rm -f kind-registry || true + docker run \ + -d --restart=always -p "127.0.0.1:5000:5000" \ + -e REGISTRY_HTTP_SECRET=secret \ + --name "${REG_NAME}" \ + registry:2 + fi +} + +function install_pipeline_crd() { + curl https://storage.googleapis.com/tekton-releases/pipeline/latest/release.notags.yaml | yq 'del(.spec.template.spec.containers[].securityContext.runAsUser, .spec.template.spec.containers[].securityContext.runAsGroup)' | oc apply -f - + # Wait for pods to be running in the namespaces we are deploying to + wait_until_pods_running tekton-pipelines || fail_test "Tekton Pipeline did not come up" +} + +function wait_until_pods_running() { + echo -n "Waiting until all pods in namespace $1 are up" + for i in {1..150}; do # timeout after 5 minutes + local pods="$(kubectl get pods --no-headers -n $1 2>/dev/null)" + # All pods must be running + local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l) + if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then + local all_ready=1 + while read pod ; do + local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`) + # All containers must be ready + [[ -z ${status[0]} ]] && all_ready=0 && break + [[ -z ${status[1]} ]] && all_ready=0 && break + [[ ${status[0]} -lt 1 ]] && all_ready=0 && break + [[ ${status[1]} -lt 1 ]] && all_ready=0 && break + [[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break + done <<< $(echo "${pods}" | grep -v Completed) + if (( all_ready )); then + echo -e "\nAll pods are up:\n${pods}" + return 0 + fi + fi + echo -n "." + sleep 2 + done + echo -e "\n\nERROR: timeout waiting for pods to come up\n${pods}" + return 1 +} + +main() { + start_registry + + install_pipeline_crd + kubectl -n tekton-pipelines patch cm feature-flags -p '{"data": {"enable-step-actions": "true"}}' + + make e2e +} + +main