-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: realanna <[email protected]>
- Loading branch information
Showing
5 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM python:3.9 AS production | ||
|
||
LABEL org.opencontainers.image.source="https://github.com/keptn/lifecycle-toolkit" \ | ||
org.opencontainers.image.url="https://keptn.sh" \ | ||
org.opencontainers.image.title="Keptn Python Runtime" \ | ||
org.opencontainers.image.vendor="Keptn" \ | ||
org.opencontainers.image.licenses="Apache-2.0" | ||
|
||
RUN pip install -q --disable-pip-version-check pyyaml GitPython requests | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
USER 1000:1000 | ||
|
||
ENV CMD_ARGS="" | ||
ENV SCRIPT="" | ||
|
||
ENTRYPOINT /entrypoint.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Keptn Lifecycle Controller - Function Runtime | ||
|
||
## Build | ||
|
||
```shell | ||
docker build -t lifecycle-toolkit/python-runtime:${VERSION} . | ||
``` | ||
|
||
## Usage | ||
|
||
The Keptn python runtime uses python3, and enables the follwing packages: requests, json, git, yaml | ||
|
||
The Keptn Lifecycle Toolkit uses this runtime to run [KeptnTask](https://lifecycle.keptn.sh/docs/tasks/write-tasks/) | ||
for pre- and post-checks. | ||
|
||
`KeptnTask`s can be tested locally with the runtime using the following commands. | ||
Replace `${VERSION}` with the KLT version of your choice. | ||
`SCRIPT` should refer to either a python file mounted locally in the container or to a url containing the file. | ||
|
||
### mounting a python file | ||
|
||
```shell | ||
docker run -v $(pwd)/samples/hellopy.py:/hellopy.py -e "SCRIPT=hellopy.py" -it lifecycle-toolkit/python-runtime:${VERSION} | ||
``` | ||
|
||
Where the file in sample/hellopy.py contains python3 code: | ||
|
||
```python3 | ||
import os | ||
|
||
print("Hello, World!") | ||
print(os.environ) | ||
``` | ||
|
||
This should print in your shell, something like: | ||
|
||
```shell | ||
Hello, World! | ||
environ({'HOSTNAME': 'myhost', 'PYTHON_VERSION': '3.9.16', 'PWD': '/', 'CMD_ARGS': '','SCRIPT': 'hellopy.py', ...}) | ||
``` | ||
|
||
### Pass command line arguments to the python command | ||
|
||
You can pass python command line arguments by specifying `CMD_ARGS`. | ||
The following example will print the help of python3: | ||
|
||
```shell | ||
docker run -e "CMD_ARGS= -help" -it lifecycle-toolkit/python-runtime:${VERSION} | ||
``` | ||
|
||
### Pass arguments to your python script | ||
|
||
In this example we pass one argument (-i test.txt) to the script | ||
|
||
```shell | ||
docker run -v $(pwd)/samples/args.py:/args.py -e "SCRIPT=args.py -i test.txt" -it lifecycle-toolkit/python-runtime:${VERSION} | ||
``` | ||
|
||
### Use a script from url | ||
|
||
We can call the hellopy.py script downloading it directly from github | ||
|
||
```shell | ||
docker run -e "SCRIPT=https://raw.githubusercontent.com/keptn/lifecycle-toolkit/main/python-runtime/samples/hellopy.py" -it lifecycle-toolkit/python-runtime:${VERSION} | ||
``` | ||
|
||
<!-- markdownlint-disable-next-line MD033 MD013 --> | ||
<img referrerpolicy="no-referrer-when-downgrade" src="https://static.scarf.sh/a.png?x-pxid=858843d8-8da2-4ce5-a325-e5321c770a78" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
set -eu | ||
|
||
regex='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]' | ||
|
||
if [[ $SCRIPT =~ $regex ]] | ||
then | ||
curl -s $SCRIPT | python3 $CMD_ARGS - | ||
else | ||
python3 $CMD_ARGS $SCRIPT | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import sys, getopt | ||
|
||
def main(argv): | ||
inputfile = '' | ||
opts, _ = getopt.getopt(argv,"i:",["ifile="]) | ||
for opt, arg in opts: | ||
if opt in ("-i", "--ifile"): | ||
inputfile = arg | ||
print ('Input file is ', inputfile) | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import os | ||
|
||
print("Hello, World!") | ||
print(os.environ) |