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

multi-user: provide example #1

Open
wants to merge 2 commits into
base: main
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
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,16 @@ to configure your IDE to select the correct Python interpreter.
## Docker
### Build the image

without conda and mantid:

```bash
docker build -f dockerfiles/Dockerfile -t app .
```

with conda and mantid

```bash
docker build --build-arg BUILD_ENV=conda -f dockerfiles/Dockerfile -t app .
docker build -f dockerfiles/Dockerfile --no-cache --progress=plain -t app .
```

### Run the container

```
docker run -p 8081:8081 -it -e EP_PATH=/app app bash -c "/prepare_nginx.sh && python -m template_app.app --host 0.0.0.0 --server"
docker run -p 8080:80 -it -e EP_PATH=/app -e TRAME_URL_PREFIX=/app app
```

then open your browser at http://localhost:8081/app/
31 changes: 4 additions & 27 deletions dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,9 @@ COPY pyproject.toml poetry.lock /src/
WORKDIR /src
RUN poetry build --format=wheel

FROM --platform=amd64 kitware/trame:py3.10-conda-glvnd-2024-01 as build_no_conda
ONBUILD RUN echo "skipping conda"
ONBUILD ENTRYPOINT []

FROM --platform=amd64 kitware/trame:py3.10-conda-glvnd-2024-01 as build_conda
ONBUILD RUN conda config --add channels mantid
ONBUILD RUN conda config --add channels conda-forge
ONBUILD RUN conda create -n trame python=3.10
ONBUILD RUN conda install -n trame mantid
ONBUILD SHELL ["conda", "run", "-n", "trame", "/bin/bash", "-c"]
ONBUILD ENTRYPOINT ["conda", "run", "--no-capture-output", "-n", "trame"]

FROM build_${BUILD_ENV}
FROM --platform=amd64 kitware/trame:py3.10-conda-glvnd-2024-06

COPY --from=build /src/dist /dist
RUN pip install /dist/*

RUN apt update && apt install -y nginx
RUN chmod og+rwX -R /var/lib/nginx
RUN chmod og+rwX -R /var/log/nginx
RUN chmod og+rwX -R /etc/nginx

COPY dockerfiles/nginx.conf.template /etc/nginx/nginx.conf.template
COPY dockerfiles/prepare_nginx.sh /

RUN python -m trame.tools.www --client-type vue3 --output /app/www-content


USER trame-user
COPY --chown=trame-user:trame-user dockerfiles/setup /deploy/setup
ENV TRAME_CLIENT_TYPE=vue3
RUN /opt/trame/entrypoint.sh build
47 changes: 0 additions & 47 deletions dockerfiles/nginx.conf.template

This file was deleted.

2 changes: 0 additions & 2 deletions dockerfiles/prepare_nginx.sh

This file was deleted.

14 changes: 14 additions & 0 deletions dockerfiles/setup/apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
trame:
cmd:
- python
- -m
- template_app.app
- --host
- ${host}
- --port
- ${port}
- --authKey
- ${secret}
- --server
- --session
- ${id}
4 changes: 4 additions & 0 deletions dockerfiles/setup/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
conda config --add channels mantid
conda config --add channels conda-forge
conda install mantid -y
pip install /dist/*
26 changes: 16 additions & 10 deletions template_app/app/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@

@TrameApp()
class App:
def _parse_args(self):
parser = argparse.ArgumentParser()
parser.add_argument("--galaxy-url", help="URL of the Galaxy server")
parser.add_argument("--galaxy-key", help="API key for accessing the Galaxy server")
parser.add_argument("--galaxy-history-id", help="Default Galaxy history ID to use")
parser.add_argument("--config", help="Path to configuration file")
args, unknown = parser.parse_known_args()
return args

def _sync_histories(self):
try:
self.state.items_galaxyHistory = galaxy.get_histories(self.state)
Expand Down Expand Up @@ -65,10 +56,25 @@ def _connect_to_galaxy(self, args):

def __init__(self, server=None, data=None):
self.server = get_server(server, client_type="vue3")

# CLI
self.server.cli.add_argument("--galaxy-url", help="URL of the Galaxy server")
self.server.cli.add_argument("--galaxy-key", help="API key for accessing the Galaxy server")
self.server.cli.add_argument("--galaxy-history-id", help="Default Galaxy history ID to use")
self.server.cli.add_argument("--config", help="Path to configuration file")
self.server.cli.add_argument("--session", help="Session identifier")
args, _ = self.server.cli.parse_known_args()

# TODO use it in auth
root_path = os.environ.get("EP_PATH", "")
# I don't think you need it in the state
self.state.base_url = f"{root_path}/api/{args.session}/"
print(f"Base URL to use: {self.state.base_url}")

# todo: can we put config as state variable so that a change to a nested field would trigger state change
self.state.model = Model()
self.state.config_file = None
args = self._parse_args()

self._connect_to_galaxy(args)
if args.config:
self.state.model.loadConfig(open(args.config).read())
Expand Down