diff --git a/.travis.yml b/.travis.yml index 47902dd4f..96555b98f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,13 +33,14 @@ before_install: # available on travis. - pip install "docker~=4.2.0" + # Fix to avoid rebuilding images already built + - remove_docker_mirror_on_travis + + # Explicitly set a namespace to use - export K8S_NAMESPACE=binderhub-test install: - # Fix to avoid rebuilding images already built - - remove_docker_mirror_on_travis - # Setup our minikube based Kubernetes cluster - setup_minikube - setup_kubectl @@ -80,23 +81,49 @@ jobs: - stage: test name: main script: - - ./ci/test-main + - ./testing/local-binder-k8s-hub/install-jupyterhub-chart + - await_jupyterhub + - pytest -m "not auth_test" --log-cli-level=10 -vsx --cov binderhub + - stage: test name: auth script: - - ./ci/test-auth + - ./testing/local-binder-k8s-hub/install-jupyterhub-chart --auth + - await_jupyterhub + - pytest -m "auth_test" --log-cli-level=10 -vsx --cov binderhub + - stage: test name: helm script: - - ./ci/test-helm + # Prepare + - echo "Preparing local BinderHub Helm chart" + - helm dependency update ./helm-chart/binderhub + - (cd helm-chart && chartpress) + - git --no-pager diff + + # Install + - echo "Installing local BinderHub Helm chart with JupyterHub as a dependency into k8s cluster" + - generate_binderhub_chart_config_remote + - | + helm upgrade --install --create-namespace --namespace $K8S_NAMESPACE \ + binderhub-test helm-chart/binderhub \ + --values testing/k8s-binder-k8s-hub/binderhub-chart-config.yaml \ + --values testing/k8s-binder-k8s-hub/binderhub-chart-config-remote.yaml + - await_binderhub + + # Test + - export BINDER_URL=http://$(minikube ip):30901 + - echo "Running tests against $BINDER_URL" + - mark="remote${GITHUB_ACCESS_TOKEN:+ and not github_api}" + - pytest -vsx -m "$mark" --log-cli-level=10 --cov binderhub + - stage: publish name: publish:helm-chart - install: - - remove_docker_mirror_on_travis + install: # overrides default - setup_helm - pip install chartpress - script: + script: # overrides default - ./ci/publish after_failure: - echo "Required dummy override of default 'after_failure' in .travis.yml." diff --git a/ci/common b/ci/common index b02189f85..dcbbcf3fe 100755 --- a/ci/common +++ b/ci/common @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Use https://www.shellcheck.net/ to reduce mistakes if you make changes to this file. remove_docker_mirror_on_travis() { @@ -13,7 +13,6 @@ remove_docker_mirror_on_travis() { sudo systemctl restart docker docker ps -a } -export -f remove_docker_mirror_on_travis setup_kubectl () { echo "setup kubectl" @@ -21,13 +20,11 @@ setup_kubectl () { chmod +x kubectl sudo mv kubectl /usr/local/bin/ } -export -f setup_kubectl setup_helm () { echo "setup helm ${HELM_VERSION}" curl -sf https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | DESIRED_VERSION=v${HELM_VERSION} bash } -export -f setup_helm setup_minikube () { # install conntrack for minikube with k8s 1.18.2 @@ -44,7 +41,6 @@ setup_minikube () { sudo CHANGE_MINIKUBE_NONE_USER=true minikube start --vm-driver=none --kubernetes-version=v${KUBE_VERSION} minikube update-context } -export -f setup_minikube await_jupyterhub() { kubectl rollout status --watch --timeout 300s deployment/proxy --namespace ${K8S_NAMESPACE:-binderhub-test} \ @@ -55,13 +51,22 @@ await_jupyterhub() { fi ) } -export -f await_jupyterhub await_binderhub() { await_jupyterhub kubectl rollout status --watch --timeout 300s deployment/binder --namespace ${K8S_NAMESPACE:-binderhub-test} } -export -f await_binderhub + +generate_binderhub_chart_config_remote () { + file=testing/k8s-binder-k8s-hub/binderhub-chart-config-remote.yaml + echo "config:" > $file + echo " BinderHub:" >> $file + echo " hub_url: http://$(minikube ip):30902" + if [[ ! -z "$GITHUB_ACCESS_TOKEN" ]]; then + echo " GitHubRepoProvider:" >> $file + echo " access_token: $GITHUB_ACCESS_TOKEN" >> $file + fi +} full_namespace_report () { # list config (secret,configmap) @@ -94,4 +99,3 @@ full_namespace_report () { ) | xargs --max-args 1 --no-run-if-empty --max-lines \ sh -c 'printf "\nPending user pod detected ($0)\n - Logs of deploy/user-scheduler:\n"; kubectl logs --all-containers deploy/user-scheduler --namespace ${K8S_NAMESPACE:-binderhub-test}' } -export -f full_namespace_report diff --git a/ci/test-auth b/ci/test-auth deleted file mode 100755 index 146c24285..000000000 --- a/ci/test-auth +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -ex -./testing/local-binder-k8s-hub/install-jupyterhub-chart --auth -await_jupyterhub - -pytest -m "auth_test" --log-cli-level=10 -vsx --cov binderhub diff --git a/ci/test-helm b/ci/test-helm deleted file mode 100755 index 4f6de78eb..000000000 --- a/ci/test-helm +++ /dev/null @@ -1,64 +0,0 @@ -#!/bin/bash -# test helm deployment -# - build and install helm chart -# - run tests marked with 'remote' - -set -ex - -# Is there a standard interface name? -for iface in eth0 ens4 enp0s3; do - IP=$(ifconfig $iface | grep 'inet' | cut -d: -f2 | awk '{print $2}'); - if [ -n "$IP" ]; then - echo "IP: $IP" - break - fi -done -if [ -z "$IP" ]; then - echo "Failed to get IP, current interfaces:" - ifconfig -a - exit 2 -fi -export BINDER_URL=http://$IP:30901 -export HUB_URL=http://$IP:30902 - -cat < helm-chart/travis-binder.yaml -config: - BinderHub: - hub_url: http://$IP:30902 -EOF - -if [[ ! -z "$GITHUB_ACCESS_TOKEN" ]]; then - cat <> helm-chart/travis-binder.yaml - GitHubRepoProvider: - access_token: '$GITHUB_ACCESS_TOKEN' -EOF -fi - -echo "building helm chart" -cd helm-chart -helm repo add --force-update jupyterhub https://jupyterhub.github.io/helm-chart -helm dependency update ./binderhub -chartpress -cd .. -# git diff will show us the result of the chartpress render. -# This should only include the tags for chartpress images. -git --no-pager diff -docker images | sort - -echo "installing binderhub helm chart" - -cat helm-chart/travis-binder.yaml - -helm upgrade --install --create-namespace binderhub-test \ - --namespace $K8S_NAMESPACE \ - helm-chart/binderhub \ - -f testing/k8s-binder-k8s-hub/binderhub-chart-config.yaml \ - -f helm-chart/travis-binder.yaml -await_binderhub - -echo "running tests against $BINDER_URL" -mark="remote" -if [[ -z "$GITHUB_ACCESS_TOKEN" ]]; then - mark="$mark and not github_api" -fi -pytest -vsx -m "$mark" --log-cli-level=10 --cov binderhub diff --git a/ci/test-main b/ci/test-main deleted file mode 100755 index 43b2a53b4..000000000 --- a/ci/test-main +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# main test script: runs the basic Python tests, -# with JupyterHub launched via helm - -./testing/local-binder-k8s-hub/install-jupyterhub-chart -await_jupyterhub - -pytest -m "not auth_test" --log-cli-level=10 -vsx --cov binderhub