openwhisk-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michele Sciabarra <mich...@sciabarra.com>
Subject Interpretation of "main" for GoLang and ActionLoop docker images
Date Sat, 29 Sep 2018 08:03:40 GMT
Hello all,

I need to discuss my plan for simplifying rules for interpreting "main" for Golang. 

The rules I have used for interpreting the "main" parameter in wsk turned out to be a bit
confusing, so I plan to make them simpler. This is what I plan to implement, please confirm
it is fine OR tell me if there is something I should change. The text below will go in documentation
if it is ok.

----

There are  4 cases to send input to the runtime:

1. Sending a precompiled binary, specifying  a main function
2. Sending a zip file including a binary
3. Sending a single source file
4. Sending a zip file with multiple sources.

Case 1: Sending a precompiled binary, specifying the main function
In this case, the main function will be ignored.

Case 2: sending zip file including a precompiled binary
In this case, the main function will be the name of the file in the zip

Case 3: sending a source action

In this case, the main function will point to the CAPITALIZED function in package main.
I need this capitalization because in Go I cannot use main.main because it is reserved and
I use it for the bootstrap code. 

Example: -main "main" => Main function is "main.Main", 
-main hello,  main function will be "main.Hello".
Also if I use -main Hello it will be "main.Hello".

Case4: sending a zip with source actions. Here is where the current rules turned out to be
very confusing. So I am going to simplify this way:

You can upload all the files you want in your zip file, they must all have .go extension and
they will be compiled. You must NOT have a main.main function as this will be provided by
the runtime. The name of the main function will be interpreted as in 3: -main main (or default)
=> main.Main , -main hello => main.Hello

Compiler:

The go runtime provides also a compiler to "precompile" the actions.  Using the compiler you
can run the actions with just the generic "actionloop" container, smaller since there is no
go compiler in it

The compiler must be fed either a source file as in Case 3 or  a zip file conforming the Case
4 and will always produce a ZIP file containing a binary according to case 2. 

So it will be somewhat like this:

To compile:

zip - -r * | docker -i openwhisk/actionloop-golang-v1.11 -compile main >main.zip

this will compile the sources expecting a main.Main function and will produce a zip file with
a  main.

This can be deployed with:

 wsk update action golang-action main.zip -docker opewhisk/actionloop

Example using a different name:

If you want to use "hello" you can use:

zip - -r * | docker -i openwhisk/actionloop-golang-v1.11 -compile hello >hello.zip

This will look for a function main.Hello in the sources, and will produce a zip file with
a hello file.

This will have to be deployed as:

wsk update action golang-action hello.zip  -main hello -docker opewhisk/actionloop

---

Thoughts?





-- 
  Michele Sciabarra
  michele@sciabarra.com

Mime
View raw message