Skip to content
Merged
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
13 changes: 6 additions & 7 deletions .github/workflows/conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ jobs:
init-shell: bash powershell
micromamba-version: 1.5.6-0
post-cleanup: all
- run: |-
echo "Testing package import"
python -c 'import fractopo'
echo "Testing module entrypoint"
python -m fractopo --help
echo "Running unittests with pytest"
pytest -v
- name: Test package import
run: python -c 'import fractopo'
- name: Test module entrypoint
run: python -m fractopo --help
- name: Run unittests with pytest
run: pytest -v
strategy:
fail-fast: false
matrix:
Expand Down
15 changes: 15 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ jobs:
name: nialov
- name: Load image to docker
run: nix run .#load-fractopo-image
- name: Test run of loaded fractopo-app container
run: nix run .#run-fractopo-image -- -d --name fractopo-test -p 2718:2718
- name: Wait for API to be ready
run: |-
for i in {1..60}; do
if curl -s http://localhost:2718/; then
echo "API is up!"
exit 0
fi
sleep 1
done
echo "API did not start in time" >&2
exit 1
- name: Test API root endpoint
run: curl -f http://localhost:2718/
- env:
PUSHER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name == 'push'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ trace_validator.egg-info
venv/
paper/allrefs.bib
.null-ls_*
__marimo__

# We do not want to include requirements.txt
# It is merely for backwards compatible pip installs
Expand Down
28 changes: 12 additions & 16 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,29 @@ supported:
container
~~~~~~~~~

Two `marimo <https://github.com/marimo-team/marimo>`__ apps exist in
``./marimos``, ``validation.py`` and ``network.py``. These are both
included in the ``ghcr.io/nialov/fractopo-app:latest`` image. By
default, when the image is run, the network analysis app is run. To run
the validation app, add an environment variable ``RUN_MODE`` to the
container with a value of ``validation``.
A `marimo <https://github.com/marimo-team/marimo>`__ +
`FastAPI <https://github.com/fastapi/fastapi>`__ app exists in
``./marimos``, ``api.py``. This is included in the
``ghcr.io/nialov/fractopo-app:latest`` image. By default, when the image
is run, the network analysis app is run accessible at root (``/``). To
access validation functinality, use path ``/validation``. Network
analysis is also available at ``/network``.

The app host and port can be chosen with ``HOST`` (default is
``0.0.0.0``) and ``PORT`` (default is ``2718``) environment variables.
With ``docker`` you can, of course, expose in whichever port you choose.

Example ``docker`` invocations are below.

To run network analysis:
To run app:

.. code:: bash

# RUN_MODE=network specified explicitly even if it is the default
docker run --rm --interactive --tty --publish 2718:2718 --env RUN_MODE=network ghcr.io/nialov/fractopo-app:latest
docker run --rm --interactive --tty --publish 2718:2718 ghcr.io/nialov/fractopo-app:latest

To run validation:

.. code:: bash

docker run --rm --interactive --tty --publish 2718:2718 --env RUN_MODE=validation ghcr.io/nialov/fractopo-app:latest

The app should be available at http://localhost:2718
The network analysis functionality should be available at
http://localhost:2718/network and validation functionality at
http://localhost:2718/validation.

Usage
-----
Expand Down
30 changes: 13 additions & 17 deletions docs_src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,33 +98,29 @@ supported:
container
~~~~~~~~~

Two `marimo <https://github.com/marimo-team/marimo>`__ apps exist in
``./marimos``, ``validation.py`` and ``network.py``. These are both
included in the ``ghcr.io/nialov/fractopo-app:latest`` image. By
default, when the image is run, the network analysis app is run. To run
the validation app, add an environment variable ``RUN_MODE`` to the
container with a value of ``validation``.
A `marimo <https://github.com/marimo-team/marimo>`__ +
`FastAPI <https://github.com/fastapi/fastapi>`__ app exists in
``./marimos``, ``api.py``. This is included in the
``ghcr.io/nialov/fractopo-app:latest`` image. By default, when the image
is run, the network analysis app is run accessible at root (``/``). To
access validation functinality, use path ``/validation``. Network
analysis is also available at ``/network``.

The app host and port can be chosen with ``HOST`` (default is
``0.0.0.0``) and ``PORT`` (default is ``2718``) environment variables.
With ``docker`` you can, of course, expose in whichever port you choose.

Example ``docker`` invocations are below.

To run network analysis:
To run app:

.. code:: bash

# RUN_MODE=network specified explicitly even if it is the default
docker run --rm --interactive --tty --publish 2718:2718 --env RUN_MODE=network ghcr.io/nialov/fractopo-app:latest
docker run --rm --interactive --tty --publish 2718:2718 ghcr.io/nialov/fractopo-app:latest

To run validation:

.. code:: bash

docker run --rm --interactive --tty --publish 2718:2718 --env RUN_MODE=validation ghcr.io/nialov/fractopo-app:latest

The app should be available at http://localhost:2718
The network analysis functionality should be available at
http://localhost:2718/network and validation functionality at
http://localhost:2718/validation.

Usage
-----
Expand Down Expand Up @@ -437,7 +433,7 @@ Copyright © 2020-2026, Nikolas Ovaskainen.
:target: https://mybinder.org/v2/gh/nialov/fractopo/HEAD?filepath=docs_src%2Fnotebooks%2Ffractopo_network_1.ipynb
.. |Zenodo| image:: https://zenodo.org/badge/297451015.svg
:target: https://zenodo.org/badge/latestdoi/297451015
.. [[[end]]] (checksum: 03b8bc905d987b2f0346263e2055bca2)
.. [[[end]]] (checksum: 0fed91a430072b847114ba600a6aec78)

.. toctree::
:hidden:
Expand Down
23 changes: 23 additions & 0 deletions marimos/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import marimo
from fastapi import FastAPI

# Create a marimo asgi app
server = (
marimo.create_asgi_app()
.with_app(path="/", root="./marimos/network.py")
.with_app(path="/network", root="./marimos/network.py")
.with_app(path="/validation", root="./marimos/validation.py")
)

# Create a FastAPI app
app = FastAPI()

app.mount("/", server.build())

# Run the server using command-line:
# uvicorn marimos.api:app --host localhost --port 56000
# Run the file as script:
if __name__ == "__main__":
import uvicorn

uvicorn.run(app, host="localhost", port=8000)
39 changes: 36 additions & 3 deletions nix/ci.nix
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ in
};
};

dockerPort = builtins.toString 2718;

in
baseNixSteps
++ [
Expand All @@ -165,6 +167,28 @@ in
run = "nix run .#load-fractopo-image";

}
{
name = "Test run of loaded fractopo-app container";
run = "nix run .#run-fractopo-image -- -d --name fractopo-test -p ${dockerPort}:${dockerPort}";
}
{
name = "Wait for API to be ready";
run = ''
for i in {1..60}; do
if curl -s http://localhost:${dockerPort}/; then
echo "API is up!"
exit 0
fi
sleep 1
done
echo "API did not start in time" >&2
exit 1
'';
}
{
name = "Test API root endpoint";
run = "curl -f http://localhost:${dockerPort}/";
}
(mkPushStep {
rev = "$(git rev-parse --short HEAD)";
name = "Push to ghcr.io from all branches";
Expand Down Expand Up @@ -200,6 +224,7 @@ in
strategy = {
fail-fast = false;
matrix = {
# Test same Python versions as for poetry job
inherit (config.workflows.".github/workflows/main.yaml".jobs.poetry.strategy.matrix)
python-version
;
Expand Down Expand Up @@ -228,12 +253,20 @@ in
};
}
{
name = "Test package import";
run = ''
echo "Testing package import"
python -c 'import fractopo'
echo "Testing module entrypoint"
'';
}
{
name = "Test module entrypoint";
run = ''
python -m fractopo --help
echo "Running unittests with pytest"
'';
}
{
name = "Run unittests with pytest";
run = ''
pytest -v
'';
}
Expand Down
59 changes: 25 additions & 34 deletions nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
cp ${../marimos/utils.py} ./app/marimos/utils.py
cp ${../marimos/validation.py} ./app/marimos/validation.py
cp ${../marimos/network.py} ./app/marimos/network.py
cp ${../marimos/api.py} ./app/marimos/api.py
chmod -R 777 ./app
'';
# Add for debugging
Expand All @@ -35,43 +36,21 @@
"/bin/bash"
"-c"
(lib.concatStringsSep " " [
"${final.fractopoEnv}/bin/marimo"
"run"
"${final.fractopo-api-run}/bin/fractopo-api-run"
"--host"
"$HOST"
"--port"
"$PORT"
"--redirect-console-to-browser"
"/app/marimos/$RUN_MODE.py"
])
];
WorkingDir = "/app";
Env = [
"HOME=/app"
"HOST=0.0.0.0"
"PORT=2718"
"RUN_MODE=network"
];
};
};
mkMarimoRun =
{
name,
script,
marimosDir ? ../marimos,
}:
prev.writeShellApplication {
inherit name;
runtimeInputs = [ final.fractopoEnv ];
text =
let
scriptPath = "${marimosDir}/${script}";
in
''
marimo run ${scriptPath} "$@"
'';

};

in
{
Expand All @@ -95,20 +74,22 @@
in
prev.buildFHSEnv (lib.recursiveUpdate base config);

pythonEnv = final.python3.withPackages (p: p.fractopo.passthru.optional-dependencies.dev);
fractopoEnv = final.python3.withPackages (
pythonEnv = final.python3.withPackages (
p:
# TODO: Should check.
[ p.fractopo.passthru.no-check ] ++ p.fractopo.passthru.optional-dependencies.dev
[ p.fractopo.passthru.no-check ]
++ p.fractopo.optional-dependencies.dev
++ p.fractopo.optional-dependencies.api
);
fractopo-validation-run = mkMarimoRun {
name = "fractopo-validation-run";
script = "validation.py";
};

fractopo-network-run = mkMarimoRun {
name = "fractopo-network-run";
script = "network.py";
fractopo-api-env = final.python3.withPackages (
p: [ p.fractopo.passthru.no-check ] ++ p.fractopo.passthru.optional-dependencies.api
);

fractopo-api-run = prev.writeShellApplication {
name = "fractopo-api-run";
text = ''
${final.fractopo-api-env}/bin/uvicorn marimos.api:app "$@"
'';
};

fractopo-app-image = prev.dockerTools.buildLayeredImage fractopoImageConfig;
Expand All @@ -124,6 +105,16 @@
docker image list
'';
};
run-fractopo-image = prev.writeShellApplication {
name = "run-fractopo-image";
text =
let
inherit (final.fractopo-app-image-stream) imageName imageTag;
in
''
docker run "$@" ${imageName}:${imageTag}
'';
};
push-fractopo-image = prev.writeShellApplication {
name = "push-fractopo-image";
text =
Expand Down
Loading