For most applications we need to use files, and also share these files between functions. That's why Brane has a shared filesystem. This filesystem is available as/data
for container-based functions.
{% hint style="warning" %}
The /data
directory is only available when running a remote session as part of a instance.
{% endhint %}
{% hint style="info" %}
With brane test
, any directory can be be mounted as /data
using the--data
option.
{% endhint %}
Consider the container package below:
{% tabs %} {% tab title="run.py" %}
#!/usr/bin/env python3
import os
import sys
import yaml
from wordcloud import WordCloud
from typing import List
import matplotlib.pyplot as plt
def create(words: List[str], file: str) -> str:
wordcloud = WordCloud(max_font_size=40).generate(' '.join(words))
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.savefig(file)
return file
if __name__ == "__main__":
command = sys.argv[1]
argument_file = os.environ["FILE"]
argument_words = [
os.environ[f"WORDS_{i}"] for i in range(int(os.environ["WORDS"]))
]
functions = {
"create": create,
}
output = functions[command](argument_words, argument_file)
print(yaml.dump({"output": output}))
{% endtab %}
{% tab title="container.yml" %}
name: wordcloud
version: 1.0.0
kind: compute
dependencies:
- python3
- python3-pip
- python3-yaml
install:
- pip3 install wordcloud
files:
- run.py
entrypoint:
kind: task
exec: run.py
actions:
'create':
command:
args:
- create
input:
- type: string[]
name: words
- type: string
name: file
output:
- type: string
name: output
{% endtab %} {% endtabs %}
If we pass /data/wordcloud.png
as the file
paramters the word cloud image will be available for subsequent function calls, and from the JupyterLab IDE (Fig 1).
Instead of copy-pasting the source code files for packages, they can also be shared through GitHub:
$ brane import onnovalkering/brane --context ./examples/wordcount/wordcloud
{% hint style="warning" %} We still have to publish this package to the Brane instance seperatly. {% endhint %}