diff --git a/python/local-packages/README.md b/python/local-packages/README.md new file mode 100644 index 0000000..6ac819f --- /dev/null +++ b/python/local-packages/README.md @@ -0,0 +1,26 @@ +This is an example of creating a deployment package with dependencies not available on pypi (build .tar.gz file given) + +### Procedure + +```commandline +./package.sh + +fission env create --name my-env --image fission/python-env-3.10:latest --builder fission/python-builder-3.10:latest --spec +``` + +#### Then for every function created + +```commandline + +fission package create --sourcearchive function1.zip --env my-env --buildcmd "./build.sh" --name function1-pkg --spec + +fission fn create --name function1 --pkg function1-pkg --entrypoint "main.main" --env=my-env --spec + +fission route create --name function1-route --method GET --url /func1 --function function1 --spec +``` + +#### Destroy is only required if the env is messed up and it needs to be cleaned. +```commandline +fission spec destroy +fission spec apply --delete +``` diff --git a/python/local-packages/function1/__init__.py b/python/local-packages/function1/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python/local-packages/function1/build.sh b/python/local-packages/function1/build.sh new file mode 100755 index 0000000..8be354c --- /dev/null +++ b/python/local-packages/function1/build.sh @@ -0,0 +1,3 @@ +#!/bin/sh +pip3 install ${SRC_PKG}/libloguru-0.7.2.tar.gz -t ${SRC_PKG} +pip3 install -r ${SRC_PKG}/requirements.txt -t ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG} \ No newline at end of file diff --git a/python/local-packages/function1/lib/__init__.py b/python/local-packages/function1/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/python/local-packages/function1/lib/loguru-0.7.2.tar.gz b/python/local-packages/function1/lib/loguru-0.7.2.tar.gz new file mode 100644 index 0000000..8bf0d8e Binary files /dev/null and b/python/local-packages/function1/lib/loguru-0.7.2.tar.gz differ diff --git a/python/local-packages/function1/main.py b/python/local-packages/function1/main.py new file mode 100644 index 0000000..8808686 --- /dev/null +++ b/python/local-packages/function1/main.py @@ -0,0 +1,7 @@ +from loguru import logger + + + +def main(): + logger.debug("That's it, beautiful and simple logging!") + return "Your dependencies are working properly! They were installed from the lib folder. Check the command in build.sh" diff --git a/python/local-packages/function1/requirements.txt b/python/local-packages/function1/requirements.txt new file mode 100644 index 0000000..4818cc5 --- /dev/null +++ b/python/local-packages/function1/requirements.txt @@ -0,0 +1 @@ +pyyaml \ No newline at end of file diff --git a/python/local-packages/specs/README b/python/local-packages/specs/README new file mode 100644 index 0000000..1db3f9a --- /dev/null +++ b/python/local-packages/specs/README @@ -0,0 +1,42 @@ + +Fission Specs +============= + +This is a set of specifications for a Fission app. This includes functions, +environments, and triggers; we collectively call these things "resources". + +How to use these specs +---------------------- + +These specs are handled with the 'fission spec' command. See 'fission spec --help'. + +'fission spec apply' will "apply" all resources specified in this directory to your +cluster. That means it checks what resources exist on your cluster, what resources are +specified in the specs directory, and reconciles the difference by creating, updating or +deleting resources on the cluster. + +'fission spec apply' will also package up your source code (or compiled binaries) and +upload the archives to the cluster if needed. It uses 'ArchiveUploadSpec' resources in +this directory to figure out which files to archive. + +You can use 'fission spec apply --watch' to watch for file changes and continuously keep +the cluster updated. + +You can add YAMLs to this directory by writing them manually, but it's easier to generate +them. Use 'fission function create --spec' to generate a function spec, +'fission environment create --spec' to generate an environment spec, and so on. + +You can edit any of the files in this directory, except 'fission-deployment-config.yaml', +which contains a UID that you should never change. To apply your changes simply use +'fission spec apply'. + +fission-deployment-config.yaml +------------------------------ + +fission-deployment-config.yaml contains a UID. This UID is what fission uses to correlate +resources on the cluster to resources in this directory. + +All resources created by 'fission spec apply' are annotated with this UID. Resources on +the cluster that are _not_ annotated with this UID are never modified or deleted by +fission. + diff --git a/python/local-packages/specs/env-my-env.yaml b/python/local-packages/specs/env-my-env.yaml new file mode 100644 index 0000000..0cf1fa9 --- /dev/null +++ b/python/local-packages/specs/env-my-env.yaml @@ -0,0 +1,22 @@ +apiVersion: fission.io/v1 +kind: Environment +metadata: + creationTimestamp: null + name: my-env +spec: + builder: + command: build + container: + name: "" + resources: {} + image: fission/python-builder-3.10:latest + imagepullsecret: "" + keeparchive: false + poolsize: 3 + resources: {} + runtime: + container: + name: "" + resources: {} + image: fission/python-env-3.10:latest + version: 2 diff --git a/python/local-packages/specs/fission-deployment-config.yaml b/python/local-packages/specs/fission-deployment-config.yaml new file mode 100644 index 0000000..305e226 --- /dev/null +++ b/python/local-packages/specs/fission-deployment-config.yaml @@ -0,0 +1,7 @@ +# This file is generated by the 'fission spec init' command. +# See the README in this directory for background and usage information. +# Do not edit the UID below: that will break 'fission spec apply' +apiVersion: fission.io/v1 +kind: DeploymentConfig +name: mycode +uid: 5d2705e5-574a-464c-9317-4bcda041100c diff --git a/python/local-packages/specs/function-function1.yaml b/python/local-packages/specs/function-function1.yaml new file mode 100644 index 0000000..900d989 --- /dev/null +++ b/python/local-packages/specs/function-function1.yaml @@ -0,0 +1,27 @@ +apiVersion: fission.io/v1 +kind: Function +metadata: + creationTimestamp: null + name: function1 +spec: + InvokeStrategy: + ExecutionStrategy: + ExecutorType: poolmgr + MaxScale: 0 + MinScale: 0 + SpecializationTimeout: 120 + TargetCPUPercent: 0 + StrategyType: execution + concurrency: 500 + environment: + name: my-env + namespace: "" + functionTimeout: 60 + idletimeout: 120 + package: + functionName: main.main + packageref: + name: function1-pkg + namespace: "" + requestsPerPod: 1 + resources: {} diff --git a/python/local-packages/specs/package-function1-pkg.yaml b/python/local-packages/specs/package-function1-pkg.yaml new file mode 100644 index 0000000..7859c26 --- /dev/null +++ b/python/local-packages/specs/package-function1-pkg.yaml @@ -0,0 +1,25 @@ +include: +- function1.zip +kind: ArchiveUploadSpec +name: function1-zip-kXR3 + +--- +apiVersion: fission.io/v1 +kind: Package +metadata: + creationTimestamp: null + name: function1-pkg +spec: + buildcmd: ./build.sh + deployment: + checksum: {} + environment: + name: my-env + namespace: "" + source: + checksum: {} + type: url + url: archive://function1-zip-kXR3 +status: + buildstatus: pending + lastUpdateTimestamp: "2024-02-25T14:03:08Z"