|
1 | 1 | # Workbench API server rewritten in Python |
2 | | -This project utilizes a Swagger spec compatible work Workbench V1. |
| 2 | +This project utilizes a Swagger spec compatible with Workbench V1. |
3 | 3 |
|
4 | 4 | ## Prerequisites |
5 | | -* A running MongoDB (by default) |
6 | | -* Or a running etcd (legacy) |
| 5 | +* A running MongoDB |
| 6 | +* A running Kubernetes cluster |
7 | 7 |
|
8 | 8 | ## Usage |
9 | 9 | This project offers a fairly standard Docker image that can be built and run using common patterns. |
10 | 10 | With Docker, there is no need to clone the source in order to run the full application. |
11 | 11 |
|
12 | 12 | To run the pre-built Docker image: |
13 | 13 | ```bash |
14 | | -docker run -itd -e JWT_SECRET="SetThisToSomeSecureRandomString" |
15 | | - -e MONGO_HOST="host.docker.internal" |
16 | | - -e MONGO_PORT="27017" |
17 | | - -p 5000:5000 |
18 | | - ndslabs/apiserver:python |
| 14 | +$ docker run -itd -e KEYCLOAK_HOST="https://gateway.docker.internal/auth" \ |
| 15 | + -e MONGO_URI="mongodb://gateway.docker.internal:27017/ndslabs?authSource=admin" \ |
| 16 | + -v $(pwd)/backend.json:/app/env/backend.json \ |
| 17 | + -p 5000:5000 \ |
| 18 | + ndslabs/apiserver:develop |
19 | 19 | ``` |
20 | 20 |
|
21 | 21 | ### Configuration |
22 | | -Configuration is handled through use of environments variables, which tend to translate well between local Python |
23 | | -development and within Docker containers. |
24 | | - |
25 | | -| Name | Description | Default | |
26 | | -| ------------- | ------------- | ------------- | |
27 | | -| `JWT_SECRET` | Secret to use for creating/decoding JWTs | `thisisnotverysecret` | |
28 | | -| `JWT_ALGORITHM` | Algorithm to use for creating/decoding JWTs | `HS256` | |
29 | | -| `JWT_EXP_DELTA_MINS` | Expiration time to use for creating/decoding JWTs (in minutes) | `300` | |
30 | | -| `KUBE_HOST` | Hostname of the Kubernetes API server | `localhost` | |
31 | | -| `KUBE_PORT` | Port of the Kubernetes API server | `6443` | |
32 | | -| `KUBE_TOKENPATH` | Path within containers where the ServiceAccount token will be mounted (in-cluster only) | `/run/secrets/kubernetes.io/serviceaccount/token` | |
33 | | -| `KUBE_QPS` | QPS to use for connection to the Kubernetes API server | `50` | |
34 | | -| `KUBE_BURST` | Burst to use for the connection Kubernetes API server | `100` | |
35 | | -| `MONGO_HOST` | Hostname of the Kubernetes API server | `host.docker.internal` | |
36 | | -| `MONGO_PORT` | Port of the Kubernetes API server | `27017` | |
37 | | -| `MONGO_DATABASE` | Port of the Kubernetes API server | `ndslabs` | |
38 | | -| `ETCD_HOST` | Hostname of the Kubernetes API server | `host.docker.internal` | |
39 | | -| `ETCD_PORT` | Port of the Kubernetes API server | `4001` | |
40 | | -| `ETCD_BASE_PATH` | Port of the Kubernetes API server | `ndslabs` | |
| 22 | +These options can be changed by adjusting either `env/backend.json` or using environment variables. |
41 | 23 |
|
| 24 | +If no environment variables are provided, then the values in `backend.json` will be used. |
| 25 | +If environment variables are provided, then those will be used directly. |
| 26 | + |
| 27 | +Below are the configuration options offered by the application: |
| 28 | + |
| 29 | +| EnvVar | JSON Path | Description | Default | |
| 30 | +|----------------------------|--------------------------------|-----------------------------------------------------------------------------------|--------------------------------------------------------------------| |
| 31 | +| `BACKEND_CFG_PATH` | -- | Set the location of `backend.json` | `./env/backend.json` | |
| 32 | +| `FRONTEND_CFG_PATH` | -- | Set the location of `frontend.json` | `./env/frontend.json` | |
| 33 | +| `DEBUG` | `debug` | If true, enable Debug mode (verbose output + live reload) | `false` | |
| 34 | +| `DOMAIN` | `domain` | Domain suffix to use for creating ingress rules | `kubernetes.docker.internal` | |
| 35 | +| `KUBE_WORKBENCH_SINGLEPOD` | `singlepod` | If true, run each workbench app as a single pod | `false` | |
| 36 | +| `KUBE_PVC_STORAGECLASS` | `storage_class` | StorageClass for created userapp volumes | `ndslabs` | |
| 37 | +| `KUBE_WORKBENCH_NAMESPACE` | `namespace` | The namespace to use for created resources (if empty, create per-user namespaces) | `default` | |
| 38 | +| `KUBE_RESOURCE_PREFIX` | `resource_prefix` | If given, prepend this prefix to all resource names created by the server | `""` | |
| 39 | +| `SWAGGER_URL` | `swagger_url` | Path to the Swagger spec to use to run the application | `openapi/swagger-v1.yml` | |
| 40 | +| `INSECURE_SSL_VERIFY` | `insecure_ssl_verify` | If false, skip verification of insecure SSL requests | `true` | |
| 41 | +| `KEYCLOAK_HOST` | `keycloak.hostname` | Hostname of the Keycloak instance to use | `https://kubernetes.docker.internal/auth` | |
| 42 | +| `KEYCLOAK_REALM` | `keycloak.realmName` | Realm name to use for OIDC discovery | `workbench-dev` | |
| 43 | +| `KEYCLOAK_CLIENT_ID` | `keycloak.clientId` | Client ID (name) of the Client in keycloak | `workbench-local` | |
| 44 | +| `KEYCLOAK_CLIENT_SECRET` | `keycloak.clientSecret` | Client Secret for the client above (not needed for "public" clients) | `""` | |
| 45 | +| `MONGO_URI` | `mongo.uri` | URI of the MongoDB cluster to use | `mongodb://gateway.docker.internal:27017/ndslabs?authSource=admin` | |
| 46 | +| `MONGO_DB` | `mongo.db` | Database name to use | `ndslabs` | |
| 47 | +| `OAUTH_USERINFO_URL` | `oauth.userinfoUrl` | URL to the auth userinfo endpoint | `openapi/swagger-v1.yml` | |
| 48 | + |
| 49 | +#### Experimental |
| 50 | +TODOs and/or proposed or currently unused config items. |
| 51 | + |
| 52 | + |
| 53 | +| EnvVar | JSON Path | Description | Default | |
| 54 | +|----------------------------|--------------------------------|----------------------------------------------------------------------------|----------------| |
| 55 | +| -- | `timeout` | Default startup timeout for userapps | `30` | |
| 56 | +| -- | `inactivity_timeout` | Default inactivity timeout for userapps | `30` | |
| 57 | +| -- | `storage.home.claim_suffix` | Suffix to append to the names of user "home" PVCs | `-home` | |
| 58 | +| -- | `storage.home.storage_class` | Removed: Replaced by `storage_class` | `nfs` | |
| 59 | +| -- | `storage.shared.enabled` | If true, mount shared storage to each user pod | `false` | |
| 60 | +| -- | `storage.shared.read_only` | If true, mount shared storage as ReadOnly | `true` | |
| 61 | +| -- | `storage.shared.storage_class` | StorageClass to use when creating shared storage volume | `nfs` | |
| 62 | +| -- | `storage.shared.volume_path` | Path within each container to mount the shared storage volume | `/tmp/shared` | |
| 63 | +| -- | `userapps.ingress.annotations` | Add additional annotations to add to the created ingress rules (e.g. auth) | `{}` | |
42 | 64 |
|
43 | 65 | ## Development |
44 | 66 | Clone this repo: |
45 | 67 | ```bash |
46 | | -git clone https://github.com/nds-org/workbench-apiserver-python |
| 68 | +$ git clone https://github.com/nds-org/workbench-apiserver-python |
47 | 69 | ``` |
48 | 70 |
|
49 | | -Install Python dependencies: |
| 71 | +### With Docker |
| 72 | +To rebuild the Docker image from source: |
50 | 73 | ```bash |
51 | | -pip install -r requirements.txt |
| 74 | +$ docker build -t ndslabs/apiserver:develop . |
52 | 75 | ``` |
53 | 76 |
|
54 | | -Run the application locally (for testing): |
| 77 | +### Without Docker |
| 78 | +Install Python dependencies: |
55 | 79 | ```bash |
56 | | -python server.py |
| 80 | +$ pip install -r requirements.txt |
57 | 81 | ``` |
58 | 82 |
|
59 | | -To rebuild the Docker image from source: |
| 83 | +Run the application locally (for testing): |
60 | 84 | ```bash |
61 | | -docker build -t ndslabs/apiserver:python . |
| 85 | +$ python server.py |
62 | 86 | ``` |
63 | 87 |
|
64 | 88 | ## Generating CRDs |
65 | 89 | Side note: the Swagger spec provided in this project generates experimental CRDs for use in Kubernetes. These CRDs are not currently utilized by the application itself, and offered for experimentation only. CAUTION: These CRDs and the patterns surrounding them may change in the near future as we work to support them within the Python application. |
66 | 90 |
|
67 | | -See https://github.com/bodom0015/swagger-k8s-crd-codegen for details |
| 91 | +See https://github.com/bodom0015/swagger-k8s-crd-codegen for details |
| 92 | + |
| 93 | +## Importing Specs |
| 94 | +In the `jobs/` folder is a small script/image that can be used to populate the database using a folder of spec JSONs. |
| 95 | + |
| 96 | +To see a full list of available applications, see https://github.com/nds-org/ndslabs-specs |
| 97 | + |
| 98 | +If you modify the script locally, you can rebuild the image: |
| 99 | +```bash |
| 100 | +$ docker build -t YOUR_USERNAME/specloader . |
| 101 | +``` |
| 102 | + |
| 103 | +NOTE: You **must** push the image to a public location to use it within your cluster |
| 104 | +```bash |
| 105 | +$ docker push YOUR_USERNAME/specloader |
| 106 | +``` |
0 commit comments