This is an automated email from the ASF dual-hosted git repository. sciabarracom pushed a commit to branch 0.9.0 in repository https://gitbox.apache.org/repos/asf/openserverless-patches.git
commit cff1409104fd670015ee2fd8dea089405d1ca059 Author: Michele Sciabarra <[email protected]> AuthorDate: Sat Sep 12 14:09:31 2026 +0200 initial commit --- .gitmodules | 45 +++++++++ README.md | 50 +++++++++ _sh.hash | 1 + _wsk.hash | 1 + awk | 1 + builtin_extra.go | 84 ++++++++++++++++ envsubst | 1 + i18n_resources.go | 232 ++++++++++++++++++++++++++++++++++++++++++ jq | 1 + opsfile.yml | 22 ++++ patch-sh.sh | 51 ++++++++++ patch-task.sh | 98 ++++++++++++++++++ patch-wsk.sh | 51 ++++++++++ patch-wskdeploy.sh | 45 +++++++++ runtimes.go | 291 +++++++++++++++++++++++++++++++++++++++++++++++++++++ runtimes_extra.go | 110 ++++++++++++++++++++ sh | 1 + task | 1 + update-gomod.sh | 40 ++++++++ wsk | 1 + wskdeploy | 1 + 21 files changed, 1128 insertions(+) diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d6f5e83 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,45 @@ +# 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. + +[submodule "sh"] + path = sh + url = https://github.com/sciabarracom/sh + branch = openserverless +[submodule "task"] + path = task + url = https://github.com/sciabarracom/task + branch = openserverless +[submodule "wskdeploy"] + path = wskdeploy + url = https://github.com/sciabarracom/openwhisk-wskdeploy + branch = openserverless +[submodule "wsk"] + path = wsk + url = https://github.com/sciabarracom/openwhisk-cli + branch = openserverless +[submodule "modules/jq"] + path = jq + url = https://github.com/nuvolaris/gojq + branch = openserverless +[submodule "modules/awk"] + path = awk + url = https://github.com/nuvolaris/goawk + branch = openserverless +[submodule "modules/envsubst"] + path = envsubst + url = https://github.com/nuvolaris/envsubst + branch = openserverless diff --git a/README.md b/README.md new file mode 100644 index 0000000..465772d --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# Patches to the tools + +- changes to mvdan/sh: + - rename to sciabarracom/sh + - use coreutils as builtins + - use ops tools as builtin +- changes to taskfile: + - rename to sciabarracom/task + - default taskfile is opsfile.yml + - use the patched mvdan shell +- changes to openwhisk-wskdeploy: + - rename to sciabarracom/openwhisk-wskdeploy + - use a different path for retrieving the configuration (api/info instead of the root of the APIHOST) + - wire a different default runtimesjson +- changes to openwhisk-wsk + - rename to sciabarracom/openwhisk-wskdeploy + - generate and add to the sources the translation resources to build as a library + - use the patched openwhisk-wskdeploy + +# Procedure + +This is the procedure we followed to build the patched versions of: + +1. fork mvdan.cc/sh in github.com/sciabarracom/sh + fork github.com/go-task/task in github.com/sciabarracom/task + fork github.com/apache/openwhisk-cli in github.com/sciabarracom/openwhisk-cli + fork github.com/apache/openwhisk-wskdeploy in github.com/sciabarracom/openwhisk-wskdeploy + +3. git submodule update --init, + then add remote orig-auth with an url with an authentication token so you can push it back + then add remote upstream to the original repos to fetch tags + then git fetch --all + +3. execute the patch scripts in order (if you change them remember to increase version numbers) + + bash patch-sh.sh + bash patch-task.sh + bash patch-wskdeploy.sh + bash patch-wsk.sh + +4. regenerate the go.mod/go.sum in top level (using the latest versions if you changed them!) + +cd .. +rm go.mod go.sum +go mod init github.com/apache/openserverless-cli +go get github.com/sciabarracom/[email protected] +go get github.com/sciabarracom/task/v3/cmd/[email protected] +go mod tidy +go build + diff --git a/_sh.hash b/_sh.hash new file mode 100644 index 0000000..c0d81e7 --- /dev/null +++ b/_sh.hash @@ -0,0 +1 @@ +8b997d445efad982d2b023d3d62d891ef80ba1d5 diff --git a/_wsk.hash b/_wsk.hash new file mode 100644 index 0000000..c0d81e7 --- /dev/null +++ b/_wsk.hash @@ -0,0 +1 @@ +8b997d445efad982d2b023d3d62d891ef80ba1d5 diff --git a/awk b/awk new file mode 160000 index 0000000..d0931fd --- /dev/null +++ b/awk @@ -0,0 +1 @@ +Subproject commit d0931fd55c2c3eadaacbea1ba3684dde951d2159 diff --git a/builtin_extra.go b/builtin_extra.go new file mode 100644 index 0000000..43fa5b8 --- /dev/null +++ b/builtin_extra.go @@ -0,0 +1,84 @@ +// 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. + +// Copyright (c) 2024, Michele Sciabarra <[email protected]> +// See LICENSE for licensing information + +package interp + +import ( + "context" + "fmt" + "os" + "strings" + + "github.com/sciabarracom/sh/v3/syntax" +) + +func isCoreutil(name string) bool { + coreUtils := os.Getenv("OPS_COREUTILS") + if coreUtils == "" { + return false + } + coreUtils = " coreutils " + coreUtils + " " + return strings.Contains(coreUtils, " "+name+" ") +} + +func isTools(name string) bool { + tools := os.Getenv("OPS_TOOLS") + if tools == "" { + return false + } + tools = " " + tools + " " + return strings.Contains(tools, " "+name+" ") +} + +func isBuiltin(name string) bool { + if isCoreutil(name) { + return true + } + if isTools(name) { + return true + } + return isBuiltin_orig(name) +} + +func (r *Runner) builtinCode(ctx context.Context, pos syntax.Pos, name string, args []string) int { + + if isCoreutil(name) { + cmd := []string{"coreutils"} + if name != "coreutils" { + cmd = append(cmd, name) + } + args = append(cmd, args...) + if os.Getenv("TRACE") != "" { + fmt.Printf("%v\n", args) + } + r.exec(ctx, args) + return r.exit + } + + if isTools(name) { + args = append([]string{os.Getenv("OPS_CMD"), "-" + name}, args...) + if os.Getenv("TRACE") != "" { + fmt.Printf("%v\n", args) + } + r.exec(ctx, args) + return r.exit + } + return r.builtinCode_orig(ctx, pos, name, args) +} diff --git a/envsubst b/envsubst new file mode 160000 index 0000000..10ca029 --- /dev/null +++ b/envsubst @@ -0,0 +1 @@ +Subproject commit 10ca029cdb58695b98d525e833ba6dced90b5dcf diff --git a/i18n_resources.go b/i18n_resources.go new file mode 100644 index 0000000..ed427d1 --- /dev/null +++ b/i18n_resources.go @@ -0,0 +1,232 @@ +// 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 wski18n + +import ( + "bytes" + "compress/gzip" + "fmt" + "io" + "strings" +) + +func bindata_read(data []byte, name string) ([]byte, error) { + gz, err := gzip.NewReader(bytes.NewBuffer(data)) + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + + var buf bytes.Buffer + _, err = io.Copy(&buf, gz) + gz.Close() + + if err != nil { + return nil, fmt.Errorf("Read %q: %v", name, err) + } + + return buf.Bytes(), nil +} + +var _wski18n_resources_de_de_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") + +func wski18n_resources_de_de_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_de_de_all_json, + "wski18n/resources/de_DE.all.json", + ) +} + +var _wski18n_resources_en_us_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xd4\x7d\x5f\x73\x1b\x37\xb2\xef\x7b\x3e\x45\x97\x6b\xab\xe4\xdc\x22\xe5\xdd\xfb\x72\xeb\x3a\x27\xa7\x4a\x91\x98\x58\x89\x2d\xa9\x24\x39\xbb\xae\xd5\x96\x09\x72\x40\x11\xd1\x10\x98\x00\x18\xd1\xb4\x57\xdf\xfd\x14\xfe\xcc\x70\x86\xc4\xbf\x99\xa1\xec\x3d\x4f\x96\x87\xdd\xbf\x6e\x00\x0d\xa0\xd1\x68\x00\xff\xfc\x0e\xe0\xcb\x77\x00\x00\x2f\x48\xf6\xe2\x35\xbc\x38\x29\x8a\x9c\xcc\x91\x24\x8c\x02\xfe\x44\x24 [...] + +func wski18n_resources_en_us_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_en_us_all_json, + "wski18n/resources/en_US.all.json", + ) +} + +var _wski18n_resources_es_es_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") + +func wski18n_resources_es_es_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_es_es_all_json, + "wski18n/resources/es_ES.all.json", + ) +} + +var _wski18n_resources_fr_fr_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8a\xe6\x52\x50\xa8\xe6\x52\x50\x50\x50\x50\xca\x4c\x51\xb2\x52\x50\x4a\xaa\x2c\x48\x2c\x2e\x56\x48\x4e\x2d\x2a\xc9\x4c\xcb\x4c\x4e\x2c\x49\x55\x48\xce\x48\x4d\xce\xce\xcc\x4b\x57\xd2\x81\x28\x2c\x29\x4a\xcc\x2b\xce\x49\x2c\xc9\xcc\xcf\x03\xe9\x08\xce\xcf\x4d\x55\x40\x12\x53\xc8\xcc\x53\x70\x2b\x4a\xcd\x4b\xce\x50\xe2\x52\x50\xa8\xe5\x8a\xe5\x02\x04\x00\x00\xff\xff\x45\xa4\xe9\x62\x65\x00\x00\x00") + +func wski18n_resources_fr_fr_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_fr_fr_all_json, + "wski18n/resources/fr_FR.all.json", + ) +} + +var _wski18n_resources_it_it_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") + +func wski18n_resources_it_it_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_it_it_all_json, + "wski18n/resources/it_IT.all.json", + ) +} + +var _wski18n_resources_ja_ja_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") + +func wski18n_resources_ja_ja_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_ja_ja_all_json, + "wski18n/resources/ja_JA.all.json", + ) +} + +var _wski18n_resources_ko_kr_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") + +func wski18n_resources_ko_kr_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_ko_kr_all_json, + "wski18n/resources/ko_KR.all.json", + ) +} + +var _wski18n_resources_pt_br_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") + +func wski18n_resources_pt_br_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_pt_br_all_json, + "wski18n/resources/pt_BR.all.json", + ) +} + +var _wski18n_resources_zh_hans_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") + +func wski18n_resources_zh_hans_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_zh_hans_all_json, + "wski18n/resources/zh_Hans.all.json", + ) +} + +var _wski18n_resources_zh_hant_all_json = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00") + +func wski18n_resources_zh_hant_all_json() ([]byte, error) { + return bindata_read( + _wski18n_resources_zh_hant_all_json, + "wski18n/resources/zh_Hant.all.json", + ) +} + +// Asset loads and returns the asset for the given name. +// It returns an error if the asset could not be found or +// could not be loaded. +func Asset(name string) ([]byte, error) { + cannonicalName := strings.Replace(name, "\\", "/", -1) + if f, ok := _bindata[cannonicalName]; ok { + return f() + } + return nil, fmt.Errorf("Asset %s not found", name) +} + +// AssetNames returns the names of the assets. +func AssetNames() []string { + names := make([]string, 0, len(_bindata)) + for name := range _bindata { + names = append(names, name) + } + return names +} + +// _bindata is a table, holding each asset generator, mapped to its name. +var _bindata = map[string]func() ([]byte, error){ + "wski18n/resources/de_DE.all.json": wski18n_resources_de_de_all_json, + "wski18n/resources/en_US.all.json": wski18n_resources_en_us_all_json, + "wski18n/resources/es_ES.all.json": wski18n_resources_es_es_all_json, + "wski18n/resources/fr_FR.all.json": wski18n_resources_fr_fr_all_json, + "wski18n/resources/it_IT.all.json": wski18n_resources_it_it_all_json, + "wski18n/resources/ja_JA.all.json": wski18n_resources_ja_ja_all_json, + "wski18n/resources/ko_KR.all.json": wski18n_resources_ko_kr_all_json, + "wski18n/resources/pt_BR.all.json": wski18n_resources_pt_br_all_json, + "wski18n/resources/zh_Hans.all.json": wski18n_resources_zh_hans_all_json, + "wski18n/resources/zh_Hant.all.json": wski18n_resources_zh_hant_all_json, +} +// AssetDir returns the file names below a certain +// directory embedded in the file by go-bindata. +// For example if you run go-bindata on data/... and data contains the +// following hierarchy: +// data/ +// foo.txt +// img/ +// a.png +// b.png +// then AssetDir("data") would return []string{"foo.txt", "img"} +// AssetDir("data/img") would return []string{"a.png", "b.png"} +// AssetDir("foo.txt") and AssetDir("notexist") would return an error +// AssetDir("") will return []string{"data"}. +func AssetDir(name string) ([]string, error) { + node := _bintree + if len(name) != 0 { + cannonicalName := strings.Replace(name, "\\", "/", -1) + pathList := strings.Split(cannonicalName, "/") + for _, p := range pathList { + node = node.Children[p] + if node == nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + } + } + if node.Func != nil { + return nil, fmt.Errorf("Asset %s not found", name) + } + rv := make([]string, 0, len(node.Children)) + for name := range node.Children { + rv = append(rv, name) + } + return rv, nil +} + +type _bintree_t struct { + Func func() ([]byte, error) + Children map[string]*_bintree_t +} +var _bintree = &_bintree_t{nil, map[string]*_bintree_t{ + "wski18n": &_bintree_t{nil, map[string]*_bintree_t{ + "resources": &_bintree_t{nil, map[string]*_bintree_t{ + "de_DE.all.json": &_bintree_t{wski18n_resources_de_de_all_json, map[string]*_bintree_t{ + }}, + "en_US.all.json": &_bintree_t{wski18n_resources_en_us_all_json, map[string]*_bintree_t{ + }}, + "es_ES.all.json": &_bintree_t{wski18n_resources_es_es_all_json, map[string]*_bintree_t{ + }}, + "fr_FR.all.json": &_bintree_t{wski18n_resources_fr_fr_all_json, map[string]*_bintree_t{ + }}, + "it_IT.all.json": &_bintree_t{wski18n_resources_it_it_all_json, map[string]*_bintree_t{ + }}, + "ja_JA.all.json": &_bintree_t{wski18n_resources_ja_ja_all_json, map[string]*_bintree_t{ + }}, + "ko_KR.all.json": &_bintree_t{wski18n_resources_ko_kr_all_json, map[string]*_bintree_t{ + }}, + "pt_BR.all.json": &_bintree_t{wski18n_resources_pt_br_all_json, map[string]*_bintree_t{ + }}, + "zh_Hans.all.json": &_bintree_t{wski18n_resources_zh_hans_all_json, map[string]*_bintree_t{ + }}, + "zh_Hant.all.json": &_bintree_t{wski18n_resources_zh_hant_all_json, map[string]*_bintree_t{ + }}, + }}, + }}, +}} diff --git a/jq b/jq new file mode 160000 index 0000000..54b7644 --- /dev/null +++ b/jq @@ -0,0 +1 @@ +Subproject commit 54b764416b6984bf36b79c42d8ccafa1ed1638df diff --git a/opsfile.yml b/opsfile.yml new file mode 100644 index 0000000..95a62c7 --- /dev/null +++ b/opsfile.yml @@ -0,0 +1,22 @@ +# 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. + +version: 3 + +tasks: + + default: arch diff --git a/patch-sh.sh b/patch-sh.sh new file mode 100644 index 0000000..dc065bc --- /dev/null +++ b/patch-sh.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# 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. + +cd "$(dirname $0)" +# any suggestion how to avoid this rename and use just replaces in go.mod is welcome +go clean -cache -modcache -testcache +HERE=$PWD +STAG="v3.8.0" +DTAG="v3.8.3" +cd sh +git reset --hard +git checkout "$STAG" -B openserverless +cp $HERE/builtin_extra.go interp/builtin_extra.go +git add interp/builtin_extra.go +sed -i -e 's!) builtinCode(!) builtinCode_orig(!' -e 's!func isBuiltin!func isBuiltin_orig!' interp/builtin.go +find . \( -name \*.go -o -name go.mod \) | while read file +do echo $file + sed -i 's!mvdan.cc/sh!github.com/sciabarracom/sh!' $file +done +go clean -modcache -cache -testcache -fuzzcache +go mod tidy + +#echo >>go.mod "replace github.com/sciabarracom/sh/v3/interp => ./interp" +#echo >>go.mod "replace github.com/sciabarracom/sh/v3/syntax => ./syntax" +#go build ./cmd/gosh +# +#exit + +git commit -m "patching sh for ops" -a +git tag $DTAG +git push -f origin-auth openserverless --tags +VER=$(git rev-parse --short HEAD) +cd .. +mkdir -p bin +GOBIN=$HERE/bin go install github.com/sciabarracom/sh/v3/cmd/gosh@$VER +OPS_CMD=$(which ops) OPS_TOOLS="jq awk" OPS_COREUTILS="ls cp mv" TRACE=1 ./gosh diff --git a/patch-task.sh b/patch-task.sh new file mode 100644 index 0000000..ef435b6 --- /dev/null +++ b/patch-task.sh @@ -0,0 +1,98 @@ +#!/bin/sh +# 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. + +cd "$(dirname $0)" +# any suggestion how to avoid this rename and use just replaces in go.mod is welcome +HERE=$PWD +SHVER=$(git ls-remote https://github.com/sciabarracom/sh | awk '/refs\/heads\/openserverless/{print $1}') +STAG="v3.38.0" +DTAG="v3.38.12" +cd task +git reset --hard +git clean -f -d +go clean -cache -modcache +git checkout "$STAG" -B openserverless +mkdir -p cmd/taskmain + +echo "*.bak" >>.gitignore + +sed -i.bak -e 's/func init/func FlagInit/' internal/flags/flags.go +sed -i.bak -e 's/func init/func FlagInit/' internal/experiments/experiments.go +sed -i.bak -e "s/version = .*/version = \"$DTAG\"/" internal/version/version.go + +cat cmd/task/task.go \ +| sed -e 's/package main/package taskmain/' \ +| sed -e 's/func main()/func _main()/' \ +| tee cmd/taskmain/task.go + +cat <<EOF >>cmd/taskmain/task.go + +var todoFlagInit = true + +func Task(_args []string) (int, error) { + os.Args = _args + if todoFlagInit { + flags.FlagInit() + experiments.FlagInit() + todoFlagInit = false + } + if err := run(); err != nil { + l := &logger.Logger{ + Stdout: os.Stdout, + Stderr: os.Stderr, + Verbose: flags.Verbose, + Color: flags.Color, + } + if err, ok := err.(*errors.TaskRunError); ok && flags.ExitCode { + l.Errf(logger.Red, "%v\n", err) + return err.TaskExitCode(), err + } + if err, ok := err.(errors.TaskError); ok { + l.Errf(logger.Red, "%v\n", err) + return err.Code(), err + } + l.Errf(logger.Red, "%v\n", err) + return errors.CodeUnknown, err + } + return errors.CodeOk, nil +} +EOF +#cp $HERE/task.go cmd/taskmain/task.go +git add cmd/taskmain/task.go +find . -name \*.go | while read file +do echo $file + sed -i.bak "s!go-task/task!sciabarracom/task!" $file + sed -i.bak 's!mvdan.cc/sh!github.com/sciabarracom/sh!' $file + sed -i.bak 's!"Taskfile.!"opsfile.!' $file + sed -i.bak 's!task: !ops: !' $file +done +sed -i.bak -e 's/go-task\/task/sciabarracom\/task/' go.mod +sed -i.bak -e '/mvdan.cc/g' go.mod + +go get github.com/sciabarracom/sh/v3@$SHVER +go mod tidy +go build + +git commit -m "patching sh for ops" -a +git tag $DTAG +git push origin openserverless -f --tags +VER=$(git rev-parse HEAD) +cd .. +mkdir -p bin +GOBIN=$HERE/bin go install github.com/sciabarracom/task/v3/cmd/task@$VER + diff --git a/patch-wsk.sh b/patch-wsk.sh new file mode 100644 index 0000000..dbee25d --- /dev/null +++ b/patch-wsk.sh @@ -0,0 +1,51 @@ +#!/bin/sh +# 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. + +cd "$(dirname $0)" +# any suggestion how to avoid this rename and use just replaces in go.mod is welcome +HERE=$PWD +STAG="1.2.0" +DTAG="v1.2.1" +cd wsk +#git reset --hard +git checkout "$STAG" -B openserverless +cp $HERE/i18n_resources.go wski18n/i18n_resources.go +sed -i '/wski18n\/i18n_resources.go/d' .gitignore +git add wski18n/i18n_resources.go +sed -i -e 's/"wsk"/"ops -wsk"/' commands/wsk.go +find . \( -name \*.go -o -name go.mod \) | while read file +do echo $file + sed -i 's!apache/openwhisk-cli/!sciabarracom/openwhisk-cli/!' $file + sed -i 's!apache/openwhisk-cli"!sciabarracom/openwhisk-cli"!' $file + sed -i 's!apache/openwhisk-cli !sciabarracom/openwhisk-cli !' $file + sed -i 's!apache/openwhisk-cli$!sciabarracom/openwhisk-cli!' $file + sed -i 's!apache/openwhisk-wskdeploy!sciabarracom/openwhisk-wskdeploy!' $file +done +sed -i '/openwhisk-wskdeploy/d' go.mod +DEPLOYVER=$(git ls-remote https://github.com/sciabarracom/openwhisk-wskdeploy | awk '/refs\/heads\/openserverless/{print $1}') +go get github.com/sciabarracom/openwhisk-wskdeploy@$DEPLOYVER +go mod tidy +git commit -m "patching sh for ops" -a +git tag $DTAG +git push origin-auth openserverless -f --tags +go clean -modcache -cache -testcache -fuzzcache +VER=$(git rev-parse HEAD) +cd .. +mkdir -p bin +GOBIN=$HERE/bin go install github.com/sciabarracom/openwhisk-cli@$VER + diff --git a/patch-wskdeploy.sh b/patch-wskdeploy.sh new file mode 100644 index 0000000..15a9033 --- /dev/null +++ b/patch-wskdeploy.sh @@ -0,0 +1,45 @@ +#!/bin/sh +# 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. + +cd "$(dirname $0)" +# any suggestion how to avoid this rename and use just replaces in go.mod is welcome +HERE=$PWD +STAG="1.2.0" +DTAG="v1.2.2" +cd wskdeploy +git checkout "$STAG" -B openserverless +cp $HERE/runtimes_extra.go runtimes/runtimes_extra.go +git add runtimes/runtimes_extra.go +sed -i -e 's/func ParseOpenWhisk/func _ParseOpenWhisk/' runtimes/runtimes.go +sed -i -e 's/"unset"/"openserverless"/g' main.go +find . \( -name \*.go -o -name go.mod \) | while read file +do echo $file + sed -i 's!apache/openwhisk-wskdeploy!sciabarracom/openwhisk-wskdeploy!' $file +done +# patch a misterious bug +sed -i -e 's/res\["config"\]/res.\(map\[string\]interface\{\}\)\["config"\]/' cmd/export.go +go clean -modcache -cache -testcache -fuzzcache +go mod tidy +git commit -m "patching sh for ops" -a +git tag $DTAG +git push origin-auth openserverless -f --tags +VER=$(git rev-parse HEAD) +cd .. +mkdir -p bin +GOBIN=$HERE/bin go install github.com/sciabarracom/openwhisk-wskdeploy@$VER + diff --git a/runtimes.go b/runtimes.go new file mode 100644 index 0000000..63088a4 --- /dev/null +++ b/runtimes.go @@ -0,0 +1,291 @@ +/* + * 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 runtimes + +import ( + "crypto/tls" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "os" + "strings" + "time" + + "github.com/sciabarracom/openwhisk-client-go/whisk" + "github.com/sciabarracom/openwhisk-wskdeploy/utils" + "github.com/sciabarracom/openwhisk-wskdeploy/wskderrors" + "github.com/sciabarracom/openwhisk-wskdeploy/wski18n" + "github.com/sciabarracom/openwhisk-wskdeploy/wskprint" +) + +const ( + NODEJS_FILE_EXTENSION = "js" + SWIFT_FILE_EXTENSION = "swift" + PYTHON_FILE_EXTENSION = "py" + JAVA_FILE_EXTENSION = "java" + JAR_FILE_EXTENSION = "jar" + CSHARP_FILE_EXTENSION = "cs" + PHP_FILE_EXTENSION = "php" + ZIP_FILE_EXTENSION = "zip" + RUBY_FILE_EXTENSION = "rb" + GO_FILE_EXTENSION = "go" + RUST_FILE_EXTENSION = "rs" + NODEJS_RUNTIME = "nodejs" + SWIFT_RUNTIME = SWIFT_FILE_EXTENSION + PYTHON_RUNTIME = "python" + JAVA_RUNTIME = JAVA_FILE_EXTENSION + DOTNET_RUNTIME = ZIP_FILE_EXTENSION + PHP_RUNTIME = PHP_FILE_EXTENSION + RUBY_RUNTIME = "ruby" + GO_RUNTIME = GO_FILE_EXTENSION + RUST_RUNTIME = "rust" + HTTP_CONTENT_TYPE_KEY = "Content-Type" + HTTP_CONTENT_TYPE_VALUE = "application/json; charset=UTF-8" + RUNTIME_NOT_SPECIFIED = "NOT SPECIFIED" + BLACKBOX = "blackbox" + HTTPS = "https://" +) + +// Structs used to denote the OpenWhisk Runtime information +type Limit struct { + Apm uint `json:"actions_per_minute"` + Tpm uint `json:"triggers_per_minute"` + ConAction uint `json:"concurrent_actions"` +} + +type Runtime struct { + Deprecated bool `json:"deprecated"` + Default bool `json:"default"` + Kind string `json:"kind"` +} + +type SupportInfo struct { + Github string `json:"github"` + Slack string `json:"slack"` +} + +type OpenWhiskInfo struct { + Support SupportInfo `json:"support"` + Desc string `json:"description"` + ApiPath []string `json:"api_paths"` + Runtimes map[string][]Runtime `json:"runtimes"` + Limits Limit `json:"limits"` +} + +var FileExtensionRuntimeKindMap map[string]string +var SupportedRunTimes map[string][]string +var DefaultRunTimes map[string]string +var FileRuntimeExtensionsMap map[string]string + +func GetRuntimesByUrl(opURL string, pop *OpenWhiskInfo) error { + + // configure transport + tlsConfig := &tls.Config{ + InsecureSkipVerify: true, + } + var netTransport = &http.Transport{ + TLSClientConfig: tlsConfig, + } + + var netClient = &http.Client{ + Timeout: time.Second * utils.DEFAULT_HTTP_TIMEOUT, + Transport: netTransport, + } + + req, _ := http.NewRequest("GET", opURL, nil) + req.Header.Set(HTTP_CONTENT_TYPE_KEY, HTTP_CONTENT_TYPE_VALUE) + whisk.Debug(whisk.DbgInfo, "trying "+req.URL.String()) + res, err := netClient.Do(req) + if err != nil { + // TODO() create an error + errString := wski18n.T(wski18n.ID_ERR_RUNTIMES_GET_X_err_X, + map[string]interface{}{"err": err.Error()}) + whisk.Debug(whisk.DbgWarn, errString) + if utils.Flags.Strict { + errMessage := wski18n.T(wski18n.ID_ERR_RUNTIME_PARSER_ERROR, + map[string]interface{}{wski18n.KEY_ERR: err.Error()}) + err = wskderrors.NewRuntimeParserError(errMessage) + } + return err + } else { + if res != nil { + defer res.Body.Close() + } + b, _ := ioutil.ReadAll(res.Body) + if b != nil && len(b) > 0 { + stdout := wski18n.T(wski18n.ID_MSG_UNMARSHAL_NETWORK_X_url_X, + map[string]interface{}{"url": opURL}) + wskprint.PrintOpenWhiskVerbose(utils.Flags.Verbose, stdout) + return json.Unmarshal(b, pop) + } + return fmt.Errorf("cannot get runtimes") + } +} + +// We could get the openwhisk info from bluemix through running the command +// `curl -k https://openwhisk.ng.bluemix.net` +// hard coding it here in case of network unavailable or failure. +func ParseOpenWhisk(apiHost string) (op OpenWhiskInfo, err error) { + opURL := apiHost + _, err = url.ParseRequestURI(opURL) + if err != nil { + opURL = HTTPS + opURL + } + + // trying to download info + err = GetRuntimesByUrl(opURL+"/api/info", &op) + if err != nil { + err = GetRuntimesByUrl(opURL, &op) + } + if err != nil { + stdout := wski18n.T(wski18n.ID_MSG_UNMARSHAL_LOCAL) + wskprint.PrintOpenWhiskVerbose(utils.Flags.Verbose, stdout) + runtimes := []byte(os.Getenv("WSK_RUNTIMES_JSON")) + err = json.Unmarshal(runtimes, &op) + if err != nil { + fmt.Printf("cannot parse this json: ===\n%s\n===\n", runtimes) + return + } + } + return +} + +func ConvertToMap(op OpenWhiskInfo) (rt map[string][]string) { + rt = make(map[string][]string) + for k, v := range op.Runtimes { + rt[k] = make([]string, 0, len(v)) + for i := range v { + if !v[i].Deprecated { + rt[k] = append(rt[k], v[i].Kind) + } + if v[i].Default { + rt[k] = append(rt[k], strings.Split(v[i].Kind, ":")[0]+":default") + } + } + } + return +} + +func DefaultRuntimes(op OpenWhiskInfo) (rt map[string]string) { + rt = make(map[string]string) + for k, v := range op.Runtimes { + for i := range v { + if !v[i].Deprecated { + if v[i].Default { + rt[k] = v[i].Kind + } + } + } + } + return +} + +func FileExtensionRuntimes(op OpenWhiskInfo) (ext map[string]string) { + ext = make(map[string]string) + for k := range op.Runtimes { + if strings.Contains(k, NODEJS_RUNTIME) { + ext[NODEJS_FILE_EXTENSION] = k + } else if strings.Contains(k, PYTHON_RUNTIME) { + ext[PYTHON_FILE_EXTENSION] = k + } else if strings.Contains(k, SWIFT_RUNTIME) { + ext[SWIFT_FILE_EXTENSION] = k + } else if strings.Contains(k, PHP_RUNTIME) { + ext[PHP_FILE_EXTENSION] = k + } else if strings.Contains(k, JAVA_RUNTIME) { + ext[JAVA_FILE_EXTENSION] = k + ext[JAR_FILE_EXTENSION] = k + } else if strings.Contains(k, RUBY_RUNTIME) { + ext[RUBY_FILE_EXTENSION] = k + } else if strings.Contains(k, RUST_RUNTIME) { + ext[RUST_FILE_EXTENSION] = k + } else if strings.Contains(k, GO_RUNTIME) { + ext[GO_FILE_EXTENSION] = k + } else if strings.Contains(k, DOTNET_RUNTIME) { + ext[CSHARP_FILE_EXTENSION] = k + ext[ZIP_FILE_EXTENSION] = k + } else if strings.Contains(k, RUST_RUNTIME) { + ext[RUST_FILE_EXTENSION] = k + } + } + return +} + +func FileRuntimeExtensions(op OpenWhiskInfo) (rte map[string]string) { + rte = make(map[string]string) + + for k, v := range op.Runtimes { + for i := range v { + if !v[i].Deprecated { + if strings.Contains(k, NODEJS_RUNTIME) { + rte[v[i].Kind] = NODEJS_FILE_EXTENSION + } else if strings.Contains(k, PYTHON_RUNTIME) { + rte[v[i].Kind] = PYTHON_FILE_EXTENSION + } else if strings.Contains(k, SWIFT_RUNTIME) { + rte[v[i].Kind] = SWIFT_FILE_EXTENSION + } else if strings.Contains(k, PHP_RUNTIME) { + rte[v[i].Kind] = PHP_FILE_EXTENSION + } else if strings.Contains(k, JAVA_RUNTIME) { + rte[v[i].Kind] = JAVA_FILE_EXTENSION + } else if strings.Contains(k, RUBY_RUNTIME) { + rte[v[i].Kind] = RUBY_FILE_EXTENSION + } else if strings.Contains(k, RUST_RUNTIME) { + rte[v[i].Kind] = RUST_FILE_EXTENSION + } else if strings.Contains(k, GO_RUNTIME) { + rte[v[i].Kind] = GO_FILE_EXTENSION + } else if strings.Contains(k, DOTNET_RUNTIME) { + rte[v[i].Kind] = CSHARP_FILE_EXTENSION + } else if strings.Contains(k, RUST_RUNTIME) { + rte[v[i].Kind] = RUST_FILE_EXTENSION + } + } + } + } + return +} + +func CheckRuntimeConsistencyWithFileExtension(ext string, runtime string) bool { + rt := FileExtensionRuntimeKindMap[ext] + for _, v := range SupportedRunTimes[rt] { + if runtime == v { + return true + } + } + return false +} + +func CheckExistRuntime(rtname string, runtimes map[string][]string) bool { + for _, v := range runtimes { + for i := range v { + if rtname == v[i] { + return true + } + } + } + return false +} + +func ListOfSupportedRuntimes(runtimes map[string][]string) (rt []string) { + for _, v := range runtimes { + for _, t := range v { + rt = append(rt, t) + } + } + return +} diff --git a/runtimes_extra.go b/runtimes_extra.go new file mode 100644 index 0000000..c08a5ea --- /dev/null +++ b/runtimes_extra.go @@ -0,0 +1,110 @@ +/* + * 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 runtimes + +import ( + "crypto/tls" + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "net/url" + "os" + "time" + + "github.com/sciabarracom/openwhisk-client-go/whisk" + "github.com/sciabarracom/openwhisk-wskdeploy/utils" + "github.com/sciabarracom/openwhisk-wskdeploy/wskderrors" + "github.com/sciabarracom/openwhisk-wskdeploy/wski18n" + "github.com/sciabarracom/openwhisk-wskdeploy/wskprint" +) + +var Version = "openserverless" + +func GetRuntimesByUrl(opURL string, pop *OpenWhiskInfo) error { + + // configure transport + tlsConfig := &tls.Config{ + InsecureSkipVerify: true, + } + var netTransport = &http.Transport{ + TLSClientConfig: tlsConfig, + } + + var netClient = &http.Client{ + Timeout: time.Second * utils.DEFAULT_HTTP_TIMEOUT, + Transport: netTransport, + } + + req, _ := http.NewRequest("GET", opURL, nil) + req.Header.Set(HTTP_CONTENT_TYPE_KEY, HTTP_CONTENT_TYPE_VALUE) + whisk.Debug(whisk.DbgInfo, "trying "+req.URL.String()) + res, err := netClient.Do(req) + if err != nil { + // TODO() create an error + errString := wski18n.T(wski18n.ID_ERR_RUNTIMES_GET_X_err_X, + map[string]interface{}{"err": err.Error()}) + whisk.Debug(whisk.DbgWarn, errString) + if utils.Flags.Strict { + errMessage := wski18n.T(wski18n.ID_ERR_RUNTIME_PARSER_ERROR, + map[string]interface{}{wski18n.KEY_ERR: err.Error()}) + err = wskderrors.NewRuntimeParserError(errMessage) + } + return err + } else { + if res != nil { + defer res.Body.Close() + } + b, _ := ioutil.ReadAll(res.Body) + if b != nil && len(b) > 0 { + stdout := wski18n.T(wski18n.ID_MSG_UNMARSHAL_NETWORK_X_url_X, + map[string]interface{}{"url": opURL}) + wskprint.PrintOpenWhiskVerbose(utils.Flags.Verbose, stdout) + return json.Unmarshal(b, pop) + } + return fmt.Errorf("cannot get runtimes") + } +} + +// We could get the openwhisk info from bluemix through running the command +// `curl -k https://openwhisk.ng.bluemix.net` +// hard coding it here in case of network unavailable or failure. +func ParseOpenWhisk(apiHost string) (op OpenWhiskInfo, err error) { + opURL := apiHost + _, err = url.ParseRequestURI(opURL) + if err != nil { + opURL = HTTPS + opURL + } + + // trying to download info + err = GetRuntimesByUrl(opURL+"/api/info", &op) + if err != nil { + err = GetRuntimesByUrl(opURL, &op) + } + if err != nil { + stdout := wski18n.T(wski18n.ID_MSG_UNMARSHAL_LOCAL) + wskprint.PrintOpenWhiskVerbose(utils.Flags.Verbose, stdout) + runtimes := []byte(os.Getenv("OPS_RUNTIMES_JSON")) + err = json.Unmarshal(runtimes, &op) + if err != nil { + fmt.Printf("cannot parse this json: ===\n%s\n===\n", runtimes) + return + } + } + return +} diff --git a/sh b/sh new file mode 160000 index 0000000..f3da214 --- /dev/null +++ b/sh @@ -0,0 +1 @@ +Subproject commit f3da214dce8792e875c56f647f3d4900100def11 diff --git a/task b/task new file mode 160000 index 0000000..9a87dbc --- /dev/null +++ b/task @@ -0,0 +1 @@ +Subproject commit 9a87dbc20cebee2647aaafeb3fc6b29dbf6e6ff7 diff --git a/update-gomod.sh b/update-gomod.sh new file mode 100644 index 0000000..d2f08c4 --- /dev/null +++ b/update-gomod.sh @@ -0,0 +1,40 @@ +# 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. + +cd "$(dirname $0)"/.. +#git ls-remote https://github.com/sciabarracom/task | awk '/refs\/heads\/openserverless/{print $1}' >_task.hash +#git ls-remote https://github.com/sciabarracom/openwhisk-cli | awk '/refs\/heads\/openserverless/{print $1}' >_wsk.hash +#go get github.com/sciabarracom/task/v3@$(cat _task.hash) +#go get github.com/sciabarracom/openwhisk-cli@$(cat _wsk.hash) +#go mod tidy + + +go clean -cache -modcache +git ls-remote https://github.com/sciabarracom/sh | awk '/refs\/heads\/openserverless/{print $1}' | tee _sh.hash +go get github.com/sciabarracom/sh/v3@$(cat _sh.hash) + +git ls-remote https://github.com/sciabarracom/task | awk '/refs\/heads\/openserverless/{print $1}' | tee _task.hash +go get github.com/sciabarracom/task/v3@$(cat _task.hash) + +git ls-remote https://github.com/sciabarracom/openwhisk-wskdeploy | awk '/refs\/heads\/openserverless/{print $1}' | tee _wskdeploy.hash +go get github.com/sciabarracom/openwhisk-wskdeploy@$(cat _wskdeploy.hash) + +git ls-remote https://github.com/sciabarracom/openwhisk-cli | awk '/refs\/heads\/openserverless/{print $1}' | tee _wsk.hash + +go get github.com/sciabarracom/openwhisk-cli@$(cat _wsk.hash) + +go mod tidy diff --git a/wsk b/wsk new file mode 160000 index 0000000..39db77e --- /dev/null +++ b/wsk @@ -0,0 +1 @@ +Subproject commit 39db77e21ff61258d72baa48e4ccbb66005cf44b diff --git a/wskdeploy b/wskdeploy new file mode 160000 index 0000000..67c642d --- /dev/null +++ b/wskdeploy @@ -0,0 +1 @@ +Subproject commit 67c642d0ac144727e9cd80efdea1d73cea04dce2
