Skip to content

Commit 8dab7e4

Browse files
committed
fix: merge conflict
2 parents f1af898 + 3d81e36 commit 8dab7e4

32 files changed

Lines changed: 1358 additions & 3180 deletions

.dockerignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
README.md
2+
.git/
3+
.github/
4+
.gitignore
5+
.dockerignore
6+
.idea/
7+
Dockerfile
8+
cookies
9+
venv/

.github/workflows/docker.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ on:
2828

2929
# Certain actions will only run when this is the master repo.
3030
env:
31-
MASTER_REPO: nds-org/ndslabs
31+
MASTER_REPO: nds-org/workbench-apiserver-python
3232
DOCKERHUB_ORG: ndslabs
3333

3434
jobs:
@@ -42,10 +42,10 @@ jobs:
4242
include:
4343
- name: api
4444
FOLDER: .
45-
IMAGE: pyapiserver
45+
IMAGE: apiserver
4646

4747
steps:
48-
- uses: actions/checkout@v2
48+
- uses: actions/checkout@v3
4949

5050
# calculate some variables that are used later
5151
- name: github branch
@@ -59,7 +59,7 @@ jobs:
5959
6060
# Commit was for main/release branch, build a new version
6161
if [ "$BRANCH" == "master" -o "$BRANCH" == "main" ]; then
62-
version="$(cat /root/swagger.yml | grep "^ version:" | awk '{print $2}')"
62+
version="$(cat openapi/swagger-v1.yml | grep "^ version:" | awk '{print $2}')"
6363
echo "VERSION=$(version)" >> $GITHUB_ENV
6464
tags="latest"
6565
oldversion=""

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ RUN pip install -r requirements.txt
77
COPY . .
88
CMD ["python", "server.py"]
99

10+
# Read version metadata from build-args
11+
ARG VERSION=unknown
12+
ARG BRANCH=unknown
13+
ARG GITSHA1=unknown
14+
ARG BUILDNUMBER=unknown
15+
ENV VERSION=${VERSION}
16+
ENV BRANCH=${BRANCH}
17+
ENV GITSHA1=${GITSHA1}
18+
ENV BUILDNUMBER=${BUILDNUMBER}
19+

README.md

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,106 @@
11
# 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.
33

44
## Prerequisites
5-
* A running MongoDB (by default)
6-
* Or a running etcd (legacy)
5+
* A running MongoDB
6+
* A running Kubernetes cluster
77

88
## Usage
99
This project offers a fairly standard Docker image that can be built and run using common patterns.
1010
With Docker, there is no need to clone the source in order to run the full application.
1111

1212
To run the pre-built Docker image:
1313
```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
1919
```
2020

2121
### 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.
4123

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) | `{}` |
4264

4365
## Development
4466
Clone this repo:
4567
```bash
46-
git clone https://github.com/nds-org/workbench-apiserver-python
68+
$ git clone https://github.com/nds-org/workbench-apiserver-python
4769
```
4870

49-
Install Python dependencies:
71+
### With Docker
72+
To rebuild the Docker image from source:
5073
```bash
51-
pip install -r requirements.txt
74+
$ docker build -t ndslabs/apiserver:develop .
5275
```
5376

54-
Run the application locally (for testing):
77+
### Without Docker
78+
Install Python dependencies:
5579
```bash
56-
python server.py
80+
$ pip install -r requirements.txt
5781
```
5882

59-
To rebuild the Docker image from source:
83+
Run the application locally (for testing):
6084
```bash
61-
docker build -t ndslabs/apiserver:python .
85+
$ python server.py
6286
```
6387

6488
## Generating CRDs
6589
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.
6690

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

Comments
 (0)