-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cannot finish lab4 function chaining. See openfaas/workshop#191
- Loading branch information
Showing
31 changed files
with
209 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,2 @@ | ||
template | ||
build |
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 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://127.0.0.1:8080 | ||
functions: | ||
astronaut-finder: | ||
lang: python3 | ||
handler: ./astronaut-finder | ||
image: ${DOCKER_USER:-dev}/astronaut-finder:latest | ||
environment: | ||
write_debug: true | ||
|
Empty file.
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,10 @@ | ||
import requests | ||
import random | ||
|
||
def handle(req): | ||
r = requests.get("http://api.open-notify.org/astros.json") | ||
result = r.json() | ||
index = random.randint(0, len(result["people"])-1) | ||
name = result["people"][index]["name"] | ||
|
||
return "%s is in space" % (name) |
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 @@ | ||
requests |
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,15 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://127.0.0.1:8080 | ||
functions: | ||
first: | ||
lang: python3 | ||
handler: ./first | ||
image: cheimu/first:latest | ||
|
||
second: | ||
lang: python3 | ||
handler: ./second | ||
image: cheimu/second:latest | ||
|
Empty file.
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,7 @@ | ||
def handle(req): | ||
"""handle a request to the function | ||
Args: | ||
req (str): request body | ||
""" | ||
|
||
return req |
Empty file.
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 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://127.0.0.1:8080 | ||
functions: | ||
hello-openfaas: | ||
lang: python3 | ||
handler: ./hello-openfaas | ||
image: cheimu/hello-openfaas:latest | ||
environment: | ||
combine_output: false | ||
|
Empty file.
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,7 @@ | ||
import sys | ||
import json | ||
|
||
def handle(req): | ||
|
||
sys.stderr.write("This should be an error message.\n") | ||
return json.dumps({"Hello": "OpenFaaS"}) |
Empty file.
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,13 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://127.0.0.1:8080 | ||
functions: | ||
ingest-file: | ||
lang: python3 | ||
handler: ./ingest-file | ||
image: cheimu/ingest-file:latest | ||
readonly_root_filesystem: true | ||
environment: | ||
save_path: "/tmp/" | ||
|
Empty file.
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,17 @@ | ||
import os | ||
import time | ||
|
||
def handle(req): | ||
# Read the path or a default from environment variable | ||
path = os.getenv("save_path", "/home/app/") | ||
|
||
# generate a name using the current timestamp | ||
t = time.time() | ||
file_name = path + str(t) | ||
|
||
# write a file | ||
with open(file_name, "w") as f: | ||
f.write(req) | ||
f.close() | ||
|
||
return file_name |
Empty file.
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 @@ | ||
Hello function |
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,10 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://127.0.0.1:8080 | ||
functions: | ||
request-markdown: | ||
lang: python3 | ||
handler: ./request-markdown | ||
image: cheimu/request-markdown:latest | ||
|
Empty file.
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,22 @@ | ||
import os | ||
import requests | ||
import sys | ||
|
||
def handle(req): | ||
"""handle a request to the function | ||
Args: | ||
req (str): request body | ||
""" | ||
|
||
gateway_hostname = os.getenv("gateway_hostname", "gateway") # uses a default of "gateway" for when "gateway_hostname" is not set | ||
|
||
test_sentence = req | ||
|
||
r = requests.get("http://" + "127.0.0.1" + ":8080/function/markdown", data= test_sentence) | ||
|
||
if r.status_code != 200: | ||
sys.exit("Error with markdown, expected: %d, got: %d\n" % (200, r.status_code)) | ||
|
||
result = r.json() | ||
|
||
return result |
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 @@ | ||
requests |
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,10 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://127.0.0.1:8080 | ||
functions: | ||
request-sentiment-analysis: | ||
lang: python3 | ||
handler: ./request-sentiment-analysis | ||
image: cheimu/request-sentiment-analysis:latest | ||
|
Empty file.
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,24 @@ | ||
import os | ||
import requests | ||
import sys | ||
|
||
def handle(req): | ||
"""handle a request to the function | ||
Args: | ||
req (str): request body | ||
""" | ||
|
||
#gateway_hostname = os.getenv("gateway_hostname", "gateway") # uses a default of "gateway" for when "gateway_hostname" is not set | ||
|
||
test_sentence = req | ||
|
||
r = requests.get("http://127.0.0.1:8080/function/sentimentanalysis", data= test_sentence) | ||
|
||
if r.status_code != 200: | ||
sys.exit("Error with sentimentanalysis, expected: %d, got: %d\n" % (200, r.status_code)) | ||
|
||
result = r.json() | ||
if result["polarity"] > 0.45: | ||
return "That was probably positive" | ||
else: | ||
return "That was neutral or negative" |
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 @@ | ||
requests |
Empty file.
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,7 @@ | ||
def handle(req): | ||
"""handle a request to the function | ||
Args: | ||
req (str): request body | ||
""" | ||
|
||
return req |
Empty file.
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,10 @@ | ||
version: 1.0 | ||
provider: | ||
name: openfaas | ||
gateway: http://127.0.0.1:8080 | ||
functions: | ||
sorter: | ||
lang: dockerfile | ||
handler: ./sorter | ||
image: cheimu/sorter:latest | ||
|
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,27 @@ | ||
FROM ghcr.io/openfaas/classic-watchdog:0.1.5 as watchdog | ||
|
||
FROM alpine:3.12 | ||
|
||
RUN mkdir -p /home/app | ||
|
||
COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog | ||
RUN chmod +x /usr/bin/fwatchdog | ||
|
||
# Add non root user | ||
RUN addgroup -S app && adduser app -S -G app | ||
RUN chown app /home/app | ||
|
||
WORKDIR /home/app | ||
|
||
USER app | ||
|
||
# Populate example here - i.e. "cat", "sha512sum" or "node index.js" | ||
ENV fprocess="sort" | ||
# Set to true to see request in function logs | ||
ENV write_debug="false" | ||
|
||
EXPOSE 8080 | ||
|
||
HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1 | ||
|
||
CMD ["fwatchdog"] |