{"id":211,"date":"2021-03-10T21:08:38","date_gmt":"2021-03-10T21:08:38","guid":{"rendered":"https:\/\/andrejacobs.org\/?p=211"},"modified":"2022-04-11T20:24:24","modified_gmt":"2022-04-11T20:24:24","slug":"100-days-of-learning-day-2-deploying-my-first-python-based-function","status":"publish","type":"post","link":"https:\/\/andrejacobs.org\/100-days-challenge\/100-days-of-learning-day-2-deploying-my-first-python-based-function\/","title":{"rendered":"100 Days of Learning: Day 2 \u2013 Deploying my first Python based function"},"content":{"rendered":"\n

Photo by James Harrison<\/a> on Unsplash<\/a><\/p>\n\n\n\n

Here is my\u00a0Log book<\/a><\/p>\n\n\n\n

faas-cli warmup<\/h2>\n

For a warm up today in learning more about OpenFaaS and faasd<\/code> I will first deploy the NodeInfo function using faas-cli<\/code>.<\/p>\n

To get the list of available functions from the store<\/p>\n

$ faas-cli store list\n\nFUNCTION                                 DESCRIPTION\nNodeInfo                                 Get info about the machine that you'r...\nalpine                                   An Alpine Linux shell, set the "fproc...\nenv                                      Print the environment variables prese...\nsleep                                    Simulate a 2s duration or pass an X-S...\nshasum                                   Generate a shasum for the given input\nFiglet                                   Generate ASCII logos with the figlet CLI\ncurl                                     Use curl for network diagnostics, pas...\n<\/code><\/pre>\n

Learning action point:<\/strong> **How do I add more functions to the store? Can I host my own private functions and have the listed in the store? EDIT: There is a --url<\/code> parameter and this is the way to private stores or other hosted stores.<\/p>\n

How do I install a new FaaS?<\/p>\n

$ faas-cli store help\n...\nAvailable Commands:\n  deploy      Deploy OpenFaaS functions from a store\n  describe    Show details of OpenFaaS function from a store\n  list        List available OpenFaaS functions in a store\n...\n<\/code><\/pre>\n

Lets try deploy<\/p>\n

$ faas-cli store deploy NodeInfo\n\nIs OpenFaaS deployed? Do you need to specify the --gateway flag?\nPut "http:\/\/127.0.0.1:8080\/system\/functions": dial tcp 127.0.0.1:8080: connect: connection refused\n\nFunction 'nodeinfo' failed to deploy with status code: 500\n<\/code><\/pre>\n

Aah! I bet it is because the OPENFAAS_URL is not set since I closed yesterday’s terminal session. Guess it is time I add this environment variable to my .zshrc. In my case it is actually "~\/.ajzsh\/extras\/zshrc.ajzsh" because I have my own zsh setup called ajzsh<\/a><\/p>\n

Relaunch the terminal and verify<\/p>\n

$ echo $OPENFAAS_URL\nhttp:\/\/192.168.64.4:8080\n<\/code><\/pre>\n

Profit!<\/p>\n

$ faas-cli store deploy NodeInfo\nWARNING! You are not using an encrypted connection to the gateway, consider using HTTPS.\n\nDeployed. 200 OK.\nURL: http:\/\/192.168.64.4:8080\/function\/nodeinfo\n\n$ echo "" | faas-cli invoke nodeinfo\nHostname: localhost\n\nArch: x64\nCPUs: 2\nTotal mem: 1988MB\nPlatform: linux\nUptime: 16999\n<\/code><\/pre>\n

Learning action point:<\/strong> How do I setup TLS on the faasd<\/code> gateway?<\/p>\n

Helpful faas-cli commands<\/h2>\n