From de19a42b8b704f081bdaaba5dca914bb09d2e585 Mon Sep 17 00:00:00 2001 From: Soam Vasani Date: Thu, 9 Nov 2017 08:11:02 -0800 Subject: [PATCH] multifile example --- examples/python/multifile/README | 62 +++++++++++++++++++++++++++ examples/python/multifile/__init__.py | 0 examples/python/multifile/main.py | 11 +++++ examples/python/multifile/message.txt | 1 + examples/python/multifile/readfile.py | 3 ++ 5 files changed, 77 insertions(+) create mode 100644 examples/python/multifile/README create mode 100644 examples/python/multifile/__init__.py create mode 100644 examples/python/multifile/main.py create mode 100644 examples/python/multifile/message.txt create mode 100644 examples/python/multifile/readfile.py diff --git a/examples/python/multifile/README b/examples/python/multifile/README new file mode 100644 index 00000000..f822b5fc --- /dev/null +++ b/examples/python/multifile/README @@ -0,0 +1,62 @@ +This is an example of creating a deployment package with multiple +files including some static data in text file. + +### Create an environment + +``` +fission env create --name python --image fission/python-env:0.4.0rc --version 2 +``` + +### Create a zip file with all your files + +``` +zip -jr multifile.zip *.py *.txt +``` + +### Create a function + +Since there are multiple files, you have to specify an _entrypoint_ to +for the function. Its format is `.`. In our +example, that's `main.main`, to run function `main` in `main.py`. + +``` +fission function create --name multifile --env python --code multifile.zip --entrypoint main.main +``` + +### Test it + +``` +fission function test --name multifile +``` + +You should see the "Hello, world" message. + + +## Updating the function + +### Edit a file + +``` +echo "I said hellooooo!" > message.txt +``` + +### Update the deployment package + +``` +zip -jr multifile.zip *.py *.txt +``` + +### Update the function + +``` +fission function update --name multifile --code multifile.zip +``` + +### Test it + +``` +fission function test --name multifile +``` + +You should now see your new, edited message. + diff --git a/examples/python/multifile/__init__.py b/examples/python/multifile/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/python/multifile/main.py b/examples/python/multifile/main.py new file mode 100644 index 00000000..bffcf997 --- /dev/null +++ b/examples/python/multifile/main.py @@ -0,0 +1,11 @@ +from flask import current_app +import sys +import readfile +import os + +def main(): + current_app.logger.info("Hi") + + current_dir = os.path.dirname(__file__) + + return readfile.readFile(os.path.join(current_dir, "message.txt")) diff --git a/examples/python/multifile/message.txt b/examples/python/multifile/message.txt new file mode 100644 index 00000000..af5626b4 --- /dev/null +++ b/examples/python/multifile/message.txt @@ -0,0 +1 @@ +Hello, world! diff --git a/examples/python/multifile/readfile.py b/examples/python/multifile/readfile.py new file mode 100644 index 00000000..02e892bf --- /dev/null +++ b/examples/python/multifile/readfile.py @@ -0,0 +1,3 @@ +def readFile(name): + with open(name) as f: + return f.read()