Skip to content

Docker image template for Matlab tools in V-FOR-WaTer.

License

Notifications You must be signed in to change notification settings

VForWaTer/tool_template_matlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tool_template_matlab

This is the template for a generic containerized Matlab tool. This template can be used to generate new Github repositories from it.

How generic?

Tools using this template can be run by the toolbox-runner. That is only convenience, the tools implemented using this template are independent of any framework.

The main idea is to implement a common file structure inside container to load inputs and outputs of the tool. The template shares this structures with the Python template, NodeJS template, Octave template and R template, but can be mimiced in any container.

Each container needs at least the following structure:

/
|- in/
|  |- parameters.json
|- out/
|  |- ...
|- src/
|  |- tool.yml
|  |- getParameters.m
|  |- run.m
  • parameters.json are parameters. Whichever framework runs the container, this is how parameters are passed.
  • getParameters.m is a utility function to parse the parameters.json including pre-loading of data files and returns a struct.
  • tool.yml is the tool specification. It contains metadata about the scope of the tool, the number of endpoints (functions) and their parameters
  • run.m is the tool itself, or a Octave/Matlab script that handles the execution. It has to capture all outputs and either print them to console or create files in /out

Octave or Matlab?

Well, tools built from this image will run octave. The getParameters.m works for Matlab as well, but you need to install jsonlab to reuse the function in a real Matlab environment. Generally, the whole container should be moveable to a real Matlab base image, but you will need a Matlab license then.

How to build the image?

You can build the image from within the root of this repo by

docker build -t tbr_octave_tempate .

Use any tag you like. If you want to run and manage the container with toolbox-runner they should be prefixed by tbr_ to be recognized.

Alternatively, the contained .github/workflows/docker-image.yml will build the image for you on new releases on Github. You need to change the target repository in the aforementioned yaml and the repository needs a personal access token in the repository secrets in order to run properly.

MATLAB License

*From the mathworks:matlab:r2022b docs:

To run this container your license must be configured for cloud use. Individual and Campus-Wide licenses are already configured for cloud use. For other license types, contact your license administrator. You can identify your license type and administrator by viewing your MathWorks Account. Administrators can consult Administer Network Licenses. If you don't have a MATLAB license, you can get a trial license at MATLAB Trial for Docker.

How to run?

This template uses /src/getParameters.m to parse the parameters in the /in/parameters.json. This assumes that the files are not renamed and not moved and there is actually only one tool in the container. For any other case, the environment variables PARAM_FILE can be used to specify a new location for the parameters.json and TOOL_RUN can be used to specify the tool to be executed. The run.R has to take care of that.

To invoke the docker container directly run something similar to:

docker run --rm -it -v /path/to/local/in:/in -v /path/to/local/out:/out -e TOOL_RUN=foobar tbr_octave_template

Then, the output will be in your local out and based on your local input folder. Stdout and Stderr are also connected to the host.

With the toolbox-runner this is simplyfied. Note that this is a Python-only tool, to handle the execution of just any kind of tool from within a Python environment. Frameworks for other languages might be added.

from toolbox_runner import list_tools
tools = list_tools() # dict with tool names as keys

foobar = tools.get('foobar')  # it has to be present there...
foobar.run(result_path='./', foo_int=1337, foo_string="Please change me")

The example above will create a temporary file structure to be mounted into the container and then create a .tar.gz on termination of all inputs, outputs, specifications and some metadata, including the image sha256 used to create the output in the current working directory.

What about real tools, no foobar?

Yeah.

  1. change the tool.yml to describe your actual tool
  2. add any pkg install <package> or apt-get install needed to the Dockerfile
  3. add additional source code to /src
  4. change the run.m to consume parameters and data from /in and useful output in out
  5. build, run, rock!

About

Docker image template for Matlab tools in V-FOR-WaTer.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published