Skip to content

Commit

Permalink
Merge branch 'develop' into typing-hookspecs
Browse files Browse the repository at this point in the history
  • Loading branch information
fangchenli authored Nov 9, 2023
2 parents 32c6ccb + 748bb6a commit 4b0a718
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
name: "Kubernetes Tests"
name: "Local Integration Tests"

env:
TEST_USERNAME: "test-user"
TEST_PASSWORD: "P@sswo3d"
NEBARI_IMAGE_TAG: "main"

on:
pull_request:
paths:
- ".github/workflows/kubernetes_test.yaml"
- ".github/workflows/test_local_integration.yaml"
- "tests/**"
- "scripts/**"
- "src/**"
Expand All @@ -16,7 +21,7 @@ on:
- develop
- release/\d{4}.\d{1,2}.\d{1,2}
paths:
- ".github/workflows/kubernetes_test.yaml"
- ".github/workflows/test_local_integration.yaml"
- "tests/**"
- "scripts/**"
- "src/**"
Expand All @@ -30,23 +35,18 @@ on:
type: string

jobs:
test-kubernetes:
name: "Kubernetes Tests"
test-local-integration:
runs-on: "cirun-runner--${{ github.run_id }}"
defaults:
run:
shell: bash -l {0}
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
steps:

- name: "Set NEBARI_IMAGE_TAG=main"
run: |
echo "NEBARI_IMAGE_TAG=main" >> "$GITHUB_ENV"
echo "GITHUB_BASE_REF: ${GITHUB_BASE_REF}"
echo "GITHUB_HEAD_REF: ${GITHUB_HEAD_REF}"
echo "GITHUB_REF: ${GITHUB_REF}"
- name: 'Checkout Infrastructure'
uses: actions/checkout@main
with:
fetch-depth: 0

- name: Checkout the branch from the PR that triggered the job
if: ${{ github.event_name == 'issue_comment' }}
Expand All @@ -61,33 +61,31 @@ jobs:
env:
CONDA: /home/runnerx/miniconda3
with:
auto-update-conda: true
python-version: 3.8
miniconda-version: "latest"
- name: Install Nebari

- name: Install Nebari and playwright
run: |
conda install --quiet --yes -c anaconda pip
pip install .[dev]
playwright install
- name: Download and Install Kubectl
run: |
mkdir -p bin
pushd bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.19.0/bin/linux/amd64/kubectl
chmod +x kubectl
- uses: azure/setup-kubectl@v3
with:
version: v1.19.16

echo "$PWD" >> $GITHUB_PATH
popd
- name: Enable docker permissions for user
run: |
sudo docker ps
sudo usermod -aG docker $USER && newgrp docker
docker info
docker ps
- name: Get routing table for docker pods
run: |
ip route
- name: Initialize Nebari Cloud
run: |
mkdir -p local-deployment
Expand All @@ -99,59 +97,51 @@ jobs:
sed -i -E 's/(mem_guarantee):\s+[A-Za-z0-9\.]+/\1: 0.25G/g' "nebari-config.yaml"
cat nebari-config.yaml
- name: Deploy Nebari
working-directory: local-deployment
run: |
cd local-deployment
nebari deploy --config nebari-config.yaml --disable-prompt
- name: Basic kubectl checks after deployment
if: always()
run: |
kubectl get all,cm,secret,ing -A
- name: Check github-actions.nebari.dev resolves
run: |
nslookup github-actions.nebari.dev
- name: Curl jupyterhub login page
run: |
curl -k https://github-actions.nebari.dev/hub/home -i
### CYPRESS TESTS
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '16'
- name: npm version
run: |
npm --version
- name: Install Cypress dependencies
run: |
sudo apt-get -y update
sudo apt-get install -y libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb
- name: Get nebari-config.yaml full path
run: echo "NEBARI_CONFIG_PATH=`realpath ./local-deployment/nebari-config.yaml`" >> "$GITHUB_ENV"

- name: Create example-user
working-directory: local-deployment
run: |
export CYPRESS_EXAMPLE_USER_NAME=example-user
export CYPRESS_EXAMPLE_USER_PASSWORD=P@sswo3d
nebari keycloak adduser --user "${TEST_USERNAME}" "${TEST_PASSWORD}" --config nebari-config.yaml
nebari keycloak listusers --config nebari-config.yaml
echo "CYPRESS_EXAMPLE_USER_NAME=${CYPRESS_EXAMPLE_USER_NAME}" >> $GITHUB_ENV
echo "CYPRESS_EXAMPLE_USER_PASSWORD=${CYPRESS_EXAMPLE_USER_PASSWORD}" >> $GITHUB_ENV
- uses: actions/setup-node@v3
with:
node-version: 16

nebari keycloak adduser --user "${CYPRESS_EXAMPLE_USER_NAME}" "${CYPRESS_EXAMPLE_USER_PASSWORD}" --config "${NEBARI_CONFIG_PATH}"
nebari keycloak listusers --config "${NEBARI_CONFIG_PATH}"
- name: Get nebari-config.yaml full path
run: echo "NEBARI_CONFIG_PATH=`realpath ./local-deployment/nebari-config.yaml`" >> "$GITHUB_ENV"

- name: Cypress run
uses: cypress-io/github-action@v4
uses: cypress-io/github-action@v6
env:
CYPRESS_EXAMPLE_USER_NAME: ${{ env.TEST_USERNAME }}
CYPRESS_EXAMPLE_USER_PASSWORD: ${{ env.TEST_PASSWORD }}
CYPRESS_BASE_URL: https://github-actions.nebari.dev/
with:
working-directory: tests/tests_e2e

- name: Playwright Tests
env:
KEYCLOAK_USERNAME: ${{ env.CYPRESS_EXAMPLE_USER_NAME }}
KEYCLOAK_PASSWORD: ${{ env.CYPRESS_EXAMPLE_USER_PASSWORD }}
KEYCLOAK_USERNAME: ${{ env.TEST_USERNAME }}
KEYCLOAK_PASSWORD: ${{ env.TEST_PASSWORD }}
NEBARI_FULL_URL: https://github-actions.nebari.dev/
working-directory: tests/tests_e2e/playwright
run: |
Expand All @@ -171,20 +161,22 @@ jobs:
./tests/tests_e2e/playwright/videos/
- name: Deployment Pytests
env:
KEYCLOAK_USERNAME: ${{ env.TEST_USERNAME }}
KEYCLOAK_PASSWORD: ${{ env.TEST_PASSWORD }}
run: |
export KEYCLOAK_USERNAME=${CYPRESS_EXAMPLE_USER_NAME}
export KEYCLOAK_PASSWORD=${CYPRESS_EXAMPLE_USER_PASSWORD}
pytest tests/tests_deployment/ -v -s
- name: JupyterHub Notebook Tests
timeout-minutes: 2
# run jhub-client after pytest since jhubctl can cleanup
# the running server
env:
JUPYTERHUB_USERNAME: ${{ env.TEST_USERNAME }}
JUPYTERHUB_PASSWORD: ${{ env.TEST_PASSWORD }}
run: |
sleep 60
export JUPYTERHUB_USERNAME=${CYPRESS_EXAMPLE_USER_NAME}
export JUPYTERHUB_PASSWORD=${CYPRESS_EXAMPLE_USER_PASSWORD}
jhubctl --verbose run --hub=https://github-actions.nebari.dev \
jhubctl --verbose run --hub=https://github-actions.nebari.dev\
--auth-type=keycloak \
--validate --no-verify-ssl \
--kernel python3 \
Expand All @@ -193,6 +185,7 @@ jobs:
### CLEANUP AFTER TESTS
- name: Cleanup nebari deployment
if: always()
working-directory: local-deployment
run: |
cd local-deployment
nebari destroy --config nebari-config.yaml --disable-prompt
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ci:
repos:
# general
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
exclude: "^docs-sphinx/cli.html"
Expand Down Expand Up @@ -53,13 +53,13 @@ repos:

# python
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.10.1
hooks:
- id: black
args: ["--line-length=88", "--exclude=/src/_nebari/template/"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.4
hooks:
- id: ruff
args: ["--fix"]
Expand All @@ -75,7 +75,7 @@ repos:

# terraform
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.83.4
rev: v1.83.5
hooks:
- id: terraform_fmt
args:
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ dependencies = [
"rich==13.5.1",
"ruamel.yaml==0.17.32",
"typer==0.9.0",
"packaging==23.2",
]

[project.optional-dependencies]
Expand Down
52 changes: 44 additions & 8 deletions src/_nebari/provider/cloud/google_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import os
import subprocess
from typing import Dict, List
from typing import Dict, List, Set

from _nebari import constants
from _nebari.provider.cloud.commons import filter_by_highest_supported_k8s_version
Expand Down Expand Up @@ -30,14 +30,14 @@ def projects() -> Dict[str, str]:


@functools.lru_cache()
def regions(project: str) -> Dict[str, str]:
"""Return a dict of available regions."""
def regions() -> Set[str]:
"""Return a set of available regions."""
check_credentials()
output = subprocess.check_output(
["gcloud", "compute", "regions", "list", "--project", project, "--format=json"]
["gcloud", "compute", "regions", "list", "--format=json(name)"]
)
data = json.loads(output.decode("utf-8"))
return {_["description"]: _["name"] for _ in data}
data = json.loads(output)
return {_["name"] for _ in data}


@functools.lru_cache()
Expand Down Expand Up @@ -89,6 +89,22 @@ def instances(project: str) -> Dict[str, str]:
return {_["description"]: _["name"] for _ in data}


def activated_services() -> Set[str]:
"""Return a list of activated services."""
check_credentials()
output = subprocess.check_output(
[
"gcloud",
"services",
"list",
"--enabled",
"--format=json(config.title)",
]
)
data = json.loads(output)
return {service["config"]["title"] for service in data}


def cluster_exists(cluster_name: str, project_id: str, region: str) -> bool:
"""Check if a GKE cluster exists."""
try:
Expand Down Expand Up @@ -250,16 +266,36 @@ def gcp_cleanup(config: schema.Main):
delete_service_account(service_account_name, project_id)


def check_missing_service() -> None:
"""Check if all required services are activated."""
required = {
"Compute Engine API",
"Kubernetes Engine API",
"Cloud Monitoring API",
"Cloud Autoscaling API",
"Identity and Access Management (IAM) API",
"Cloud Resource Manager API",
}
activated = activated_services()
common = required.intersection(activated)
missing = required.difference(common)
if missing:
raise ValueError(
f"""Missing required services: {missing}\n
Please see the documentation for more information: {constants.GCP_ENV_DOCS}"""
)


# Getting pricing data could come from here
# https://cloudpricingcalculator.appspot.com/static/data/pricelist.json


### PYDANTIC VALIDATORS ###


def validate_region(project_id: str, region: str) -> str:
def validate_region(region: str) -> str:
"""Validate the GCP region is valid."""
available_regions = regions(project_id)
available_regions = regions()
if region not in available_regions:
raise ValueError(
f"Region {region} is not one of available regions {available_regions}"
Expand Down
Loading

0 comments on commit 4b0a718

Please sign in to comment.