Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code example to add local packages to fission functions. #88

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions python/local-packages/README.md
Original file line number Diff line number Diff line change
@@ -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
```
Empty file.
3 changes: 3 additions & 0 deletions python/local-packages/function1/build.sh
Original file line number Diff line number Diff line change
@@ -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}
Empty file.
Binary file not shown.
7 changes: 7 additions & 0 deletions python/local-packages/function1/main.py
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions python/local-packages/function1/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyyaml
42 changes: 42 additions & 0 deletions python/local-packages/specs/README
Original file line number Diff line number Diff line change
@@ -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.

22 changes: 22 additions & 0 deletions python/local-packages/specs/env-my-env.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions python/local-packages/specs/fission-deployment-config.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions python/local-packages/specs/function-function1.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
25 changes: 25 additions & 0 deletions python/local-packages/specs/package-function1-pkg.yaml
Original file line number Diff line number Diff line change
@@ -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"