Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose #23

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.docker.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
COMPOSE_PROJECT_NAME=jlp
# Port forward or run Grader API locally on port 8000
GRADER_API_URL=http://host.docker.internal:8000
USER_NAME=myuser
# Decoded password from namespaced credential secret for user
USER_AUTOGEN_PASSWORD="mypass"
# Port forward Gitea SSH from port 2222 to 2222.
GITEA_SSH_URL=ssh://[email protected]:2222
4 changes: 2 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ JWT_REFRESH_LEEWAY_SECONDS=60
LONG_POLLING_TIMEOUT_SECONDS=60
# For polling that depends on unobservable data, how long to sleep in between data fetches.
LONG_POLLING_SLEEP_INTERVAL_SECONDS=5
# If running locally (outside of HeLx), aliases Gitea host to localhost and changes ssh port to 2222 in Git.
LOCAL=false
# When running locally, you will likely need to override the SSH url for Gitea.
GITEA_SSH_URL="ssh://git@localhost:2222"
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.test.json',
tsconfigRootDir: __dirname,
sourceType: 'module'
},
plugins: ['@typescript-eslint'],
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ node_modules/
eduhelx_jupyterlab_prof/labextension
# Version file is handled by hatchling
eduhelx_jupyterlab_prof/_version.py
eduhelx-mount

# Integration tests
ui-tests/test-results/
Expand All @@ -29,6 +30,7 @@ __pycache__/

# Environments
.env
.env.docker
.venv
env/
venv/
Expand Down
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM containers.renci.org/helxplatform/jupyter/minimal-poetry-notebook:latest

USER root

RUN curl -sSL https://deb.nodesource.com/setup_22.x | bash -
RUN apt-get install nodejs
RUN npm i -g [email protected]

COPY . /home/$NB_USER/eduhelx-jupyterlab-prof-ext

WORKDIR /home/$NB_USER/eduhelx-jupyterlab-prof-ext
RUN pip install -e .
RUN jupyter labextension develop . --overwrite
RUN jupyter server extension enable eduhelx_jupyterlab_prof
RUN jlpm install

WORKDIR /home/$NB_USER
USER $NB_USER
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ To install the extension, execute:

```bash
pip install eduhelx_jupyterlab_prof
jupyter server extension enable eduhelx_jupyterlab_prof
```

## Uninstall
Expand Down Expand Up @@ -47,6 +48,45 @@ jupyter labextension list

### Development install

You can either run via Docker or install the extension into your local Jupyter installation in development mode.

#### Local Docker environment
Run the extension locally in Docker via `docker-compose`:

1. Configure your environment for running inside Docker. Also see: `.env.docker.sample`.
```
export COMPOSE_PROJECT_NAME=jlp
export GRADER_API_URL=http://host.docker.internal:8000
export USER_NAME="username"
export USER_AUTOGEN_PASSWORD="password"
export GITEA_SSH_URL=ssh://[email protected]:2222
```
In this scenario, you'd either be port-forwarding or running the [Grader API](https://github.com/helxplatform/eduhelx-grader-api)
on port 8000, and port-forwarding your Gitea SSH service to port 2222. You can find the password for a user by decoding their credential secret.

You can also define a separate environment file specifically for working in Docker:
```bash
cp .env.docker.sample .env.docker
vim .env.docker
set -a && source .env.docker
```

2. Start the Docker containers:
```bash
docker-compose up
```

3. Open the authenticated Jupyter URL.

Jupyterlab will run on `localhost:8888`, but it requires an authentication token to access the UI.
The jupyter container will log the authenticated URL for accessing the UI at startup,
but you can also run the following to recover the token:
```bash
docker exec jlp_jupyter_1 jupyter server list
```

#### Local install

Note: You will need NodeJS to build the extension package.

The `jlpm` command is JupyterLab's pinned version of
Expand Down
6 changes: 0 additions & 6 deletions Untitled.ipynb

This file was deleted.

25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3"
services:
jupyter:
build:
context: .
dockerfile: Dockerfile
command: bash -c "jupyter lab"
ports:
- "8888:8888"
environment:
- GRADER_API_URL
- USER_NAME
- USER_AUTOGEN_PASSWORD
- GITEA_SSH_URL
volumes:
- .:/home/jovyan/eduhelx-jupyterlab-prof-ext
- ./eduhelx-mount:/home/jovyan/eduhelx
watch:
build:
context: .
dockerfile: Dockerfile
working_dir: /home/jovyan/eduhelx-jupyterlab-prof-ext
command: bash -c "jlpm watch"
volumes:
- .:/home/jovyan/eduhelx-jupyterlab-prof-ext
2 changes: 1 addition & 1 deletion eduhelx_jupyterlab_prof/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Config:
USER_NAME: str
ACCESS_TOKEN: str = ""
USER_AUTOGEN_PASSWORD: str = ""
LOCAL: bool = False
GITEA_SSH_URL: str = ""
UPSTREAM_SYNC_INTERVAL: int = 60
# Which credential helper to use in Git
CREDENTIAL_HELPER: str = "store"
Expand Down
2 changes: 1 addition & 1 deletion eduhelx_jupyterlab_prof/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ async def create_ssh_config_if_not_exists(context: AppContext, course) -> None:
if not urlparse(ssh_public_url).scheme:
ssh_public_url = "ssh://" + ssh_public_url

ssh_private_url = settings["gitea_ssh_url"] if not context.config.LOCAL else "ssh://git@localhost:2222"
ssh_private_url = settings["gitea_ssh_url"] if not context.config.GITEA_SSH_URL else context.config.GITEA_SSH_URL
if not urlparse(ssh_private_url).scheme:
ssh_private_url = "ssh://" + ssh_private_url

Expand Down
Loading