This is an automated email from the ASF dual-hosted git repository.

csantanapr pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/incubator-openwhisk-runtime-go.git


The following commit(s) were added to refs/heads/master by this push:
     new fb85997  Cleaned the vendor folder (#55)
fb85997 is described below

commit fb8599773d9536463645c75b6de3935b31599687
Author: Sciabarra.com ltd <30654959+sciabarra...@users.noreply.github.com>
AuthorDate: Wed Oct 24 04:07:32 2018 +0200

    Cleaned the vendor folder (#55)
    
    * cleanup
    
    * fixed vendor folders with more examples and documentation
---
 common/gobuild.py                                  |  4 +++
 docs/DEPLOY.md                                     |  4 ++-
 examples/EXAMPLES.md                               |  1 +
 examples/Makefile                                  | 32 +++++++++---------
 examples/bash-hello/Makefile                       |  2 +-
 examples/golang-hello-single/Makefile              |  4 +--
 examples/golang-hello-vendor/Makefile              |  8 ++---
 examples/golang-main-package/Makefile              |  4 +--
 examples/golang-main-single/Makefile               |  4 +--
 examples/golang-main-standalone/Makefile           |  4 +--
 .../Makefile                                       | 14 ++++----
 examples/golang-main-vendor/src/main/Gopkg.lock    | 25 ++++++++++++++
 examples/golang-main-vendor/src/main/Gopkg.toml    | 34 +++++++++++++++++++
 examples/golang-main-vendor/src/main/main.go       | 38 ++++++++++++++++++++++
 openwhisk/initHandler.go                           |  3 +-
 15 files changed, 144 insertions(+), 37 deletions(-)

diff --git a/common/gobuild.py b/common/gobuild.py
index 053ed69..8cd3cf0 100755
--- a/common/gobuild.py
+++ b/common/gobuild.py
@@ -43,6 +43,8 @@ def sources(launcher, source_dir, main):
     # copy the launcher fixing the main
     if not has_main:
         dst = "%s/main__.go" % source_dir
+        if os.path.isdir("%s/main" % source_dir):
+            dst = "%s/main/main__.go" % source_dir
         with codecs.open(dst, 'w', 'utf-8') as d:
             with codecs.open(launcher, 'r', 'utf-8') as e:
                 code = e.read()
@@ -55,6 +57,8 @@ def build(parent, source_dir, target):
       "PATH": os.environ["PATH"],
       "GOPATH": os.path.abspath(parent)
     }
+    if os.path.isdir("%s/main" % source_dir):
+        source_dir += "/main"
     p = subprocess.Popen(
         ["go", "build", "-i", "-ldflags=-s -w",  "-o", target],
         stdout=subprocess.PIPE,
diff --git a/docs/DEPLOY.md b/docs/DEPLOY.md
index 583fae2..c059fac 100644
--- a/docs/DEPLOY.md
+++ b/docs/DEPLOY.md
@@ -100,7 +100,7 @@ To create a vendor folder, you need to
 
 - install the [dep](https://github.com/golang/dep) tool
 - cd to the `src/hello` folder (*not* the `src` folder)
-- run `dep init` the first time (it will create 2 manifest files `Gopkg.lock` 
and `Gopkg.toml`) or `dep ensure` if you already have the manifest files.
+- run `GOPATH=$PWD/../.. dep init` the first time (it will create 2 manifest 
files `Gopkg.lock` and `Gopkg.toml`) or `dep ensure` if you already have the 
manifest files.
 
 The layout will be something like this:
 
@@ -123,6 +123,8 @@ Check the example `golang-hello-vendor`.
 
 Note you do not need to store the `vendor` folder in the version control 
system as it can be regenerated (only the manifest files), but you need to 
include the entire vendor folder when you deploy the action.
 
+If you need to use vendor folder in the main package, you need to create a 
directory `main` and place all the source code that would normally go in the 
top level, in the `main` folder instead.  A vendor folder in the top level 
*does not work*.
+
 <a name="vscode">
 
 ### Using VsCode
diff --git a/examples/EXAMPLES.md b/examples/EXAMPLES.md
index a59d25e..2515dac 100644
--- a/examples/EXAMPLES.md
+++ b/examples/EXAMPLES.md
@@ -31,6 +31,7 @@ Available examples:
 - [Simple Golang action](golang-main-single) main is `main.Main`
 - [Simple Golang action](golang-hello-single) main is `main.Hello`
 - [Golang action with a subpackage](golang-main-package) main is `main.Main` 
invoking a `hello.Hello`
+- [Golang action with a vendor folder](golang-main-vendor) main is `main.Main` 
using a dependency `github.com/rs/zerolog`
 - [Golang action with a subpackage and vendor folder](golang-hello-vendor) 
main is `main.Hello` invoking a `hello.Hello` using a dependency 
`github.com/sirupsen/logrus`
 - [Standalone Golang Action](golang-main-standalone) main is `main.main`, 
implements the ActionLoop directly
 - [Simple Bash action](bash-hello) a simple bash script action implementing 
the ActionLoop directly
diff --git a/examples/Makefile b/examples/Makefile
index 3b65bbb..8774e4d 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,32 +1,34 @@
 # prefix
-
-USER=msciab            # devel
-#USER=openwhisk                # deploy
+IMAGES?=openwhisk      
 
 all: .PHONY
-.PHONY: bash-hello golang-hello-single golang-main-single 
golang-main-standalone golang-main-package golang-hello-vendor 
 
 bash-hello:
-       OW_USER=$(USER) make deploy test -C bash-hello
+       cd $@ && OW_USER=$(IMAGES) make clean deploy test
 
 golang-main-single:
-       OW_USER=$(USER) make deploy test -C $@
-       OW_USER=$(USER) make deploy test -C $@
+       cd $@ && OW_USER=$(IMAGES) make clean devel test
+       cd $@ && OW_USER=$(IMAGES) make clean deploy test
 
 golang-hello-single:
-       OW_USER=$(USER) make deploy test -C $@
-       OW_USER=$(USER) make deploy test -C $@
+       cd $@ && OW_USER=$(IMAGES) make clean devel test
+       cd $@ && OW_USER=$(IMAGES) make clean deploy test
 
 golang-main-standalone:
-       OW_USER=$(USER) make deploy test -C $@
-       OW_USER=$(USER) make deploy test -C $@
+       cd $@ && OW_USER=$(IMAGES) make clean devel test
+       cd $@ && OW_USER=$(IMAGES) make clean deploy test
 
 golang-main-package:
-       OW_USER=$(USER) make deploy test -C $@
-       OW_USER=$(USER) make deploy test -C $@
+       cd $@ && OW_USER=$(IMAGES) make clean devel test
+       cd $@ && OW_USER=$(IMAGES) make clean deploy test
+
+golang-main-vendor:
+       cd $@ && OW_USER=$(IMAGES) make clean devel test
+       cd $@ && OW_USER=$(IMAGES) make clean deploy test
 
 golang-hello-vendor:
-       OW_USER=$(USER) make deploy test -C $@
-       OW_USER=$(USER) make deploy test -C $@
+       cd $@ && OW_USER=$(IMAGES) make clean devel test
+       cd $@ && OW_USER=$(IMAGES) make clean deploy test
 
+.PHONY: bash-hello golang-hello-single golang-main-single 
golang-main-standalone golang-main-package golang-main-vendor 
golang-hello-vendor 
 
diff --git a/examples/bash-hello/Makefile b/examples/bash-hello/Makefile
index da69f47..8fa3945 100644
--- a/examples/bash-hello/Makefile
+++ b/examples/bash-hello/Makefile
@@ -15,7 +15,7 @@ test: test.json
        $(WSK) action invoke $(PACKAGE)/$(NAME) -P test.json -r
 
 clean:
-       $(WSK) action delete $(PACKAGE)/$(NAME)
+       -$(WSK) action delete $(PACKAGE)/$(NAME)
 
 package.done:
        $(WSK) package update $(PACKAGE)
diff --git a/examples/golang-hello-single/Makefile 
b/examples/golang-hello-single/Makefile
index d16f0e1..e02f3dd 100644
--- a/examples/golang-hello-single/Makefile
+++ b/examples/golang-hello-single/Makefile
@@ -18,8 +18,8 @@ $(ZIP): $(SRC)
        docker run -i $(OW_COMPILER) -compile $(MAIN) <$(SRC) >$(ZIP)
 
 clean:
-       wsk action delete $(PACKAGE)/$(NAME)
-       rm $(ZIP) package.done
+       -$(WSK) action delete $(PACKAGE)/$(NAME)
+       -rm $(ZIP) package.done
 
 test: test.json
        $(WSK) action invoke test/$(NAME) -r
diff --git a/examples/golang-hello-vendor/Makefile 
b/examples/golang-hello-vendor/Makefile
index 8efada7..8d76f26 100644
--- a/examples/golang-hello-vendor/Makefile
+++ b/examples/golang-hello-vendor/Makefile
@@ -14,10 +14,10 @@ deploy: package.done $(BINZIP)
        $(WSK) action update $(PACKAGE)/$(NAME) $(BINZIP) --main $(MAIN) 
--docker $(OW_RUNTIME)
 
 devel: package.done $(SRCZIP)
-       $(WSK) action update $(PACKAGE)/$(NAME) $(SRCZIP) --main $(MAIN) 
--docker $(OW_RUNTIME)
+       $(WSK) action update $(PACKAGE)/$(NAME) $(SRCZIP) --main $(MAIN) 
--docker $(OW_COMPILER)
 
 src/%/vendor:
-       cd $(@D) ; dep ensure
+       cd $(@D) ; GOPATH=$$PWD/../.. dep ensure
 
 $(BINZIP): $(SRCS) $(VENDORS)
        cd src ; zip - -r * | docker run -i $(OW_COMPILER) -compile $(MAIN) 
>../$(BINZIP)
@@ -26,8 +26,8 @@ $(SRCZIP): $(SRCS) $(VENDORS)
        cd src ; zip ../$(SRCZIP) -r *
 
 clean:
-       wsk action delete $(PACKAGE)/$(NAME)
-       rm  $(BINZIP) $(SRCZIP) package.done
+       -$(WSK)action delete $(PACKAGE)/$(NAME)
+       -rm $(BINZIP) $(SRCZIP) package.done
 
 test: test.json
        $(WSK) action invoke test/$(NAME) -r
diff --git a/examples/golang-main-package/Makefile 
b/examples/golang-main-package/Makefile
index cb266fd..7677d2e 100644
--- a/examples/golang-main-package/Makefile
+++ b/examples/golang-main-package/Makefile
@@ -22,8 +22,8 @@ $(SRCZIP): $(SRCS)
        cd src ; zip ../$(SRCZIP) -r *
 
 clean:
-       wsk action delete $(PACKAGE)/$(NAME)
-       rm  $(BINZIP) $(SRCZIP) package.done
+       -$(WSK) action delete $(PACKAGE)/$(NAME)
+       -rm  $(BINZIP) $(SRCZIP) package.done
 
 test: test.json
        $(WSK) action invoke test/$(NAME) -r
diff --git a/examples/golang-main-single/Makefile 
b/examples/golang-main-single/Makefile
index 1c16fcc..8d49674 100644
--- a/examples/golang-main-single/Makefile
+++ b/examples/golang-main-single/Makefile
@@ -18,8 +18,8 @@ $(ZIP): $(SRC)
        docker run -i $(OW_COMPILER) -compile $(MAIN) <$(SRC) >$(ZIP)
 
 clean:
-       wsk action delete $(PACKAGE)/$(NAME)
-       rm $(ZIP) package.done
+       -$(WSK) action delete $(PACKAGE)/$(NAME)
+       -rm $(ZIP) package.done
 
 test: test.json
        $(WSK) action invoke test/$(NAME) -r
diff --git a/examples/golang-main-standalone/Makefile 
b/examples/golang-main-standalone/Makefile
index 208ca99..42f41fa 100644
--- a/examples/golang-main-standalone/Makefile
+++ b/examples/golang-main-standalone/Makefile
@@ -18,8 +18,8 @@ $(ZIP): $(SRC)
        docker run -i $(OW_COMPILER) -compile $(MAIN) <$(SRC) >$(ZIP)
 
 clean:
-       wsk action delete $(PACKAGE)/$(NAME)
-       rm $(ZIP) package.done
+       -$(WSK) action delete $(PACKAGE)/$(NAME)
+       -rm $(ZIP) package.done
 
 test: test.json
        $(WSK) action invoke test/$(NAME) -r
diff --git a/examples/golang-hello-vendor/Makefile 
b/examples/golang-main-vendor/Makefile
similarity index 80%
copy from examples/golang-hello-vendor/Makefile
copy to examples/golang-main-vendor/Makefile
index 8efada7..98a0931 100644
--- a/examples/golang-hello-vendor/Makefile
+++ b/examples/golang-main-vendor/Makefile
@@ -2,10 +2,10 @@ OW_USER?=openwhisk
 OW_RUNTIME?=$(OW_USER)/actionloop
 OW_COMPILER?=$(OW_USER)/actionloop-golang-v1.11
 WSK?=wsk
-MAIN=hello
+MAIN=main
 PACKAGE=test
-SRCS=src/$(MAIN).go src/hello/hello.go
-VENDORS=src/hello/vendor
+SRCS=src/main/main.go 
+VENDORS=src/main/vendor
 NAME=golang-$(MAIN)-vendor
 BINZIP=$(MAIN)-bin.zip
 SRCZIP=$(MAIN)-src.zip
@@ -14,10 +14,10 @@ deploy: package.done $(BINZIP)
        $(WSK) action update $(PACKAGE)/$(NAME) $(BINZIP) --main $(MAIN) 
--docker $(OW_RUNTIME)
 
 devel: package.done $(SRCZIP)
-       $(WSK) action update $(PACKAGE)/$(NAME) $(SRCZIP) --main $(MAIN) 
--docker $(OW_RUNTIME)
+       $(WSK) action update $(PACKAGE)/$(NAME) $(SRCZIP) --main $(MAIN) 
--docker $(OW_COMPILER)
 
 src/%/vendor:
-       cd $(@D) ; dep ensure
+       cd $(@D) ; GOPATH=$$PWD/../.. dep ensure
 
 $(BINZIP): $(SRCS) $(VENDORS)
        cd src ; zip - -r * | docker run -i $(OW_COMPILER) -compile $(MAIN) 
>../$(BINZIP)
@@ -26,8 +26,8 @@ $(SRCZIP): $(SRCS) $(VENDORS)
        cd src ; zip ../$(SRCZIP) -r *
 
 clean:
-       wsk action delete $(PACKAGE)/$(NAME)
-       rm  $(BINZIP) $(SRCZIP) package.done
+       -$(WSK) action delete $(PACKAGE)/$(NAME)
+       -rm $(BINZIP) $(SRCZIP) package.done
 
 test: test.json
        $(WSK) action invoke test/$(NAME) -r
diff --git a/examples/golang-main-vendor/src/main/Gopkg.lock 
b/examples/golang-main-vendor/src/main/Gopkg.lock
new file mode 100644
index 0000000..4e31c6b
--- /dev/null
+++ b/examples/golang-main-vendor/src/main/Gopkg.lock
@@ -0,0 +1,25 @@
+# This file is autogenerated, do not edit; changes may be undone by the next 
'dep ensure'.
+
+
+[[projects]]
+  digest = "1:6342a41a66687c0d0eb1f4d946447bfb808c5136adeb92903ed07972071e19ac"
+  name = "github.com/rs/zerolog"
+  packages = [
+    ".",
+    "internal/cbor",
+    "internal/json",
+    "log",
+  ]
+  pruneopts = "UT"
+  revision = "338f9bc14084d22cb8eeacd6492861f8449d715c"
+  version = "v1.9.1"
+
+[solve-meta]
+  analyzer-name = "dep"
+  analyzer-version = 1
+  input-imports = [
+    "github.com/rs/zerolog",
+    "github.com/rs/zerolog/log",
+  ]
+  solver-name = "gps-cdcl"
+  solver-version = 1
diff --git a/examples/golang-main-vendor/src/main/Gopkg.toml 
b/examples/golang-main-vendor/src/main/Gopkg.toml
new file mode 100644
index 0000000..d080275
--- /dev/null
+++ b/examples/golang-main-vendor/src/main/Gopkg.toml
@@ -0,0 +1,34 @@
+# Gopkg.toml example
+#
+# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
+# for detailed Gopkg.toml documentation.
+#
+# required = ["github.com/user/thing/cmd/thing"]
+# ignored = ["github.com/user/project/pkgX", 
"bitbucket.org/user/project/pkgA/pkgY"]
+#
+# [[constraint]]
+#   name = "github.com/user/project"
+#   version = "1.0.0"
+#
+# [[constraint]]
+#   name = "github.com/user/project2"
+#   branch = "dev"
+#   source = "github.com/myfork/project2"
+#
+# [[override]]
+#   name = "github.com/x/y"
+#   version = "2.4.0"
+#
+# [prune]
+#   non-go = false
+#   go-tests = true
+#   unused-packages = true
+
+
+[[constraint]]
+  name = "github.com/rs/zerolog"
+  version = "1.9.1"
+
+[prune]
+  go-tests = true
+  unused-packages = true
diff --git a/examples/golang-main-vendor/src/main/main.go 
b/examples/golang-main-vendor/src/main/main.go
new file mode 100644
index 0000000..b687858
--- /dev/null
+++ b/examples/golang-main-vendor/src/main/main.go
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package main
+
+import (
+       "github.com/rs/zerolog"
+       "github.com/rs/zerolog/log"
+)
+
+func init() {
+       zerolog.TimeFieldFormat = ""
+}
+
+// Main function for the action
+func Main(obj map[string]interface{}) map[string]interface{} {
+       name, ok := obj["name"].(string)
+       if !ok {
+               name = "world"
+       }
+       log.Debug().Str("name", name).Msg("Hello")
+       msg := make(map[string]interface{})
+       msg["golang-main-vendor"] = "Hello, " + name + "!"
+       return msg
+}
diff --git a/openwhisk/initHandler.go b/openwhisk/initHandler.go
index 94454ae..73b5ffd 100644
--- a/openwhisk/initHandler.go
+++ b/openwhisk/initHandler.go
@@ -168,7 +168,8 @@ func (ap *ActionProxy) ExtractAndCompile(buf *[]byte, main 
string) (string, erro
        if err != nil {
                return "", err
        }
-       if !isCompiled(binFile) {
+       // check only if the file exist
+       if _, err := os.Stat(binFile); os.IsNotExist(err) {
                return "", fmt.Errorf("cannot compile")
        }
        return binFile, nil

Reply via email to