Experimenting with Fn project

The first AppDev Made Easy (previously known as DX Workshop) for this tour started in Perth. We are continually trialing a few different things as such as we incorporated Fn project https://fnproject.io.

The whole demonstration of Functions was to articulate that there are different ways to execute and understanding the problem to solve as well as the values that the organisation holds (including both business and IT departments including developers) which will determine the technology.

For the demo we start from the very beginning.

Getting Fn Installed

The documentation on github is easy to follow – https://github.com/fnproject/fn. The first thing to do is to install docker. I refer back to this previous document to install docker on Oracle Compute Cloud Service – This is How Easy it is to setup Docker on Oracle Compute Cloud Service. Or if you are comfortable with the docker install, then that’s good too.

We use the simple curl script from the README to install fn.

Here’s the basic steps that we took get fn up and running.

1/ Run curl to download the CLI installer and install using shell. The URL is https://raw.githubusercontent.com/fnproject/cli/master/install.

curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh

fn-01

2/ Run the fn version command

fn version

fn-02

3/ Run the fn server command to start the server.

fn start

fn-03

4/ In a different window, create a new file called func.go with the implementation.

vi func.go

You can type in the code (as below)

package main

func main() {
 fmt.Println("Hello from Fn - From PER!")
}

fn-04

5/ Run the fn init command. This creates a yaml file that is introspected from the function. The main information that is collected is the runtime ie in this case it’s go.

fn init

Since the original (version) you can also autogenerate the hello example with the init command. This will create the code, the yaml file and a test file.

fn init --runtime go hello

fn-05

6/ Run the fn run command. This compiles and creates the function runtime and executes the function.

fn run

fn-06

7/ Run the fn deploy command to deploy this to the local fn server. There is an option to also deploy it to an associated docker hub registry.

fn deploy --app myapp --local

fn-07

8/ Let’s test it out and here is the browser result.

fn-08

For the session today, I also demonstrated Apiary. From the API created by Carlos and Dave for the API Made Easy workshop, I copied the sample nodejs code from the Apiary tool.

9/ I created a new file func.js in a new directory called sms.

vi func.js

fn-09

10/ I created a new file package.json to describe the dependencies that the function had.

vi package.json

fn-10

11/ From here, it is the same process. Run fn init command to generate the yaml file and then run the fn run command to test output the code.

fn init
fn run

fn-11

12/ Run fn deploy command to deploy the newly created function.

fn deploy --app myapp --local

fn-12

13/ Test out the function from the browser and see the output from the function.

fn-13

The whole experience was pretty simple. There was not much that needed to be done. The combination of the simplicity of the solution as well as the documentation and examples to support developers was really well done.

Give it a try and see what you think.

Advertisement

Author: Jason Lowe

I am passionate about how organisations adopt IT quickly and sustainably to achieve a specific and measurable outcome. This thinking is supported through lean IT practices in operational support and project delivery, and adopting these practices with Oracle technologies by creating sustainable platforms. I'm also interested different perspectives and drivers - from enterprise to start-ups, academia to commercial to public sector, cost-sensitive (risk) to value-driven (reward) - all of which influences decisions that organisations make. I have a passion for community and have been called "a connector" - meeting new people that are trying to solve valuable and hard problems and connecting them with others that can validate and help realise their full potential. I've supported different organisations like TADHack and Hacking Health as a global organiser. I'm is a persistent blogger on medium.com and redthunder.blog and on LinkedIn - https://www.linkedin.com/in/lowe-jason #CommunityMatters #ItTakesAVillage

3 thoughts on “Experimenting with Fn project”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: