Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Feb 11, 2024
2 parents 2d09646 + 6935d8c commit 1cd8538
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 10 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install Node.js
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/action-setup@v2
node-version: 20.9.0
- uses: pnpm/action-setup@v3
name: Install pnpm
with:
version: 8
Expand All @@ -28,7 +28,7 @@ jobs:
id: pnpm
shell: bash
run: echo "STORE_PATH=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
- uses: actions/cache@v3
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ steps.pnpm.outputs.STORE_PATH }}
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Build website
run: pnpm build
- name: Upload pages artifact
uses: actions/upload-pages-artifact@v2
uses: actions/upload-pages-artifact@v3
with:
path: ./build

Expand All @@ -64,4 +64,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
4 changes: 2 additions & 2 deletions docs/internal/deployments/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ const deployments: DeploymentInfo[] = [
),
},
{
url: "https://fetalmri-hosting-of-medical-image-analysis-platform-dcb83b.apps.shift.nerc.mghpcc.org/api/v1/",
url: "https://fetalmri-cube.apps.shift.nerc.mghpcc.org/api/v1/",
description: "Fetal MRI dataset CUBE",
host: "NERC (OpenShift)",
src: {
Expand All @@ -160,7 +160,7 @@ const deployments: DeploymentInfo[] = [
),
},
{
url: "https://publictesting-hosting-of-medical-image-analysis-platform-dcb83b.apps.shift.nerc.mghpcc.org/api/v1/",
url: "https://cube-for-testing-chrisui.apps.shift.nerc.mghpcc.org/api/v1/",
description:
"Public CUBE for testing against the CUBE API in CI environments.",
host: "NERC (OpenShift)",
Expand Down
3 changes: 2 additions & 1 deletion docs/run/chrisui_openshift.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ oc new-app --name chrisui \
being able to generate the version string. See https://github.com/FNNDSC/ChRIS_ui/pull/508
- Increase memory limit for build to 4GB
- (optional) Set RunPolicy=SerialLatestOnly
- (optional) Set `successfulBuildsHistoryLimit` and `failedBuildsHistoryLimit`

```shell
oc patch bc/chrisui --patch '{"spec":{"resources":{"limits":{"memory":"3814Mi"}},"runPolicy":"SerialLatestOnly","source":{"git":{"ref":"refs/heads/master"}}}}'
oc patch bc/chrisui --patch '{"spec":{"resources":{"limits":{"memory":"3814Mi"}},"runPolicy":"SerialLatestOnly","source":{"git":{"ref":"refs/heads/master"}}",successfulBuildsHistoryLimit":2,"failedBuildsHistoryLimit":2}}'
```

### 4. Create a Route
Expand Down
109 changes: 109 additions & 0 deletions docs/tutorials/convert_python_app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
title: "HOW TO: Convert an existing Python app"
toc_min_heading_level: 2
toc_max_heading_level: 3
---

This guide will show you how to convert (almost) any existing Python program into a
[_ChRIS_ _ds_ plugin](../chris_plugins#ds-type-plugins)!
It's easier done than said.

:::tip

This guide assumes working knowledge of Python, Python packaging, and Docker.

:::

## 1. Install `chris_plugin`

```shell
pip install -U chris_plugin
```

## 2. Use `argparse`

Changes are, your Python program is already using
[argparse](https://docs.python.org/3/library/argparse.html).
If not, you'll need to add it:

```python
from argparse import ArgumentParser
parser = ArgumentParser()
```

## 3. Add a `main` function

You probably have this too, though here we need to do something special:

A ChRIS plugin processes data from an input directory and writes its results to an output directory.
Hence, these data directories should be parameters to your `main` function.

The `main` function should be **decorated** with the **`@chris_plugin`** decorator, which takes the
parser you created.

```python
from chris_plugin import chris_plugin

@chris_plugin(parser=parser)
def main(options, inputdir, outputdir):
...
```


## 4. Customize `setup.py`

Once again, your app should already have a `setup.py`!

As a command-line app, `setup.py` must specify
[entrypoints](https://setuptools.pypa.io/en/latest/userguide/entry_point.html).

It should look like this:

```python
from setuptools import setup

setup(
name = 'chris-plugin-example',
version = '1.0.0',
description = 'A ChRIS DS plugin that I made',
author = 'FNNDSC',
author_email = '[email protected]',
url = 'https://github.com/FNNDSC/chris-plugin-example',
# if your app is a single script file, use py_modules
# if your app is a folder containing Python packages, set packages=...
py_modules = ['app'],
install_requires = ['chris_plugin'],
license = 'MIT',
python_requires = '>=3.10',
entry_points = {
'console_scripts': [
# here you need to declare the name of your executable program
# and your main function
'my_command = app:main'
]
}
)
```

## 5. Create `Dockerfile`

`Dockerfile` are instructions for how to build a container image from your source code.

```Dockerfile
FROM python:3.10
WORKDIR /usr/local/src
COPY . .
RUN pip install .
CMD ["my_command", "--help"]
```

## 6. Done!

A JSON description of your ChRIS plugin can be created using the `chris_plugin_info` command:

```shell
chris_plugin_info --dock-image docker.io/fnndsc/pl-app:v1.0.0 > description.json
```

The file `description.json` is a representation of your plugin which can be uploaded to a _ChRIS backend_.
The instructions to do so are [here](./upload_plugin).
14 changes: 14 additions & 0 deletions docs/tutorials/upload_plugin/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ Use [chrisomatic](https://github.com/FNNDSC/chrisomatic) to upload a list of plu

_ChRIS_ plugin GitHub repositories can be configured to be automatically uploaded
using [GitHub Actions](../../chris_plugins/github_actions.md).

## Non-canonical methods

While not _officially_ supported, a python helper script, [plugin2cube](https://github.com/FNNDSC/plugin2cube), is available that can effect registration by directly speaking to the `CUBE` API.

In some cases this can be a quicker/simpler way to register a plugin. It does however require the `CUBE` *admin* username and password and knowledge of the compute environments on a `CUBE`, and assumes that the host executing the script has `docker` installed.

For example:

```shell
plugin2cube --CUBEurl http://rc-live.tch.harvard.edu:32222/api/v1/ \
--CUBEuser XXXXXX --CUBEpasswd XXXXXX \
--computenames galena-avx --dock_image ghcr.io/fnndsc/pl-dicom_repack:1.1.4
```

0 comments on commit 1cd8538

Please sign in to comment.