diff --git a/RELEASES.md b/RELEASES.md index f5c3ba43..392d81da 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,6 +1,11 @@ # Releases +## v 0.6.26 + +* Enabling support for node18, node16, go1.19, go1.18, ruby3.1. +* Removing support for node11, go1.15, python3.6, python3.7 + ## v 0.6.25 * Support for multiple shapes(architectures) functions images: diff --git a/langs/base.go b/langs/base.go index de2430f3..07e95c90 100644 --- a/langs/base.go +++ b/langs/base.go @@ -33,23 +33,23 @@ var fallBackOlderVersions = map[string]LangHelper{} func init() { registerHelper(&DotnetLangHelper{Version: "6.0"}) registerHelper(&DotnetLangHelper{Version: "3.1"}) - registerHelper(&GoLangHelper{Version: "1.15"}) + registerHelper(&GoLangHelper{Version: "1.19"}) + registerHelper(&GoLangHelper{Version: "1.18"}) // order matter, 'java' will pick up the first JavaLangHelper registerHelper(&JavaLangHelper{version: "17"}) registerHelper(&JavaLangHelper{version: "11"}) registerHelper(&JavaLangHelper{version: "8"}) + registerHelper(&NodeLangHelper{Version: "18"}) + registerHelper(&NodeLangHelper{Version: "16"}) registerHelper(&NodeLangHelper{Version: "14"}) - registerHelper(&NodeLangHelper{Version: "11"}) // order matter, 'python' will pick up the first PythonLangHelper registerHelper(&PythonLangHelper{Version: "3.9"}) registerHelper(&PythonLangHelper{Version: "3.8"}) registerHelper(&PythonLangHelper{Version: "3.8.5"}) - registerHelper(&PythonLangHelper{Version: "3.7"}) - registerHelper(&PythonLangHelper{Version: "3.7.1"}) - registerHelper(&PythonLangHelper{Version: "3.6"}) - //New runtime support for Ruby 2.7 + //New runtime support for Ruby 3.1 // order matter, 'ruby' will pick up the first RubyLangHelper + registerHelper(&RubyLangHelper{Version: "3.1"}) registerHelper(&RubyLangHelper{Version: "2.7"}) registerHelper(&KotlinLangHelper{}) diff --git a/langs/go.go b/langs/go.go index cee80ea0..f4bbf2f8 100644 --- a/langs/go.go +++ b/langs/go.go @@ -78,11 +78,12 @@ func (h *GoLangHelper) DockerfileBuildCmds() []string { r = append(r, "ENV GOFLAGS=\"-mod=vendor\"") } r = append(r, "COPY . .") + r = append(r, "RUN go mod tidy") } else { r = append(r, "ADD . /go/src/func/") } - r = append(r, "RUN cd /go/src/func/ && go build -o func") + r = append(r, "RUN go build -o func -v") return r } diff --git a/langs/node.go b/langs/node.go index 335fc989..1d973182 100644 --- a/langs/node.go +++ b/langs/node.go @@ -121,7 +121,7 @@ func (h *NodeLangHelper) DockerfileBuildCmds() []string { r = append(r, "ADD package.json /function/", - "RUN npm install", + "RUN npm install && chown -R $(id -u):$(id -g) node_modules", ) } return r diff --git a/test/README.md b/test/README.md index a52c5b62..6edd43d0 100644 --- a/test/README.md +++ b/test/README.md @@ -20,7 +20,7 @@ func TestPythonCall(t *testing.T) { h.MkDir(funcName) h.Cd(funcName) - h.Fn("init", "--name", funcName, "--runtime", "python3.6").AssertSuccess() + h.Fn("init", "--name", funcName, "--runtime", "python3.9").AssertSuccess() appName := h.NewAppName() h.Fn("deploy", "--local", appName).AssertSuccess() h.Fn("invoke", appName, funcName).AssertSuccess() diff --git a/test/cli_docker_runtime_test.go b/test/cli_docker_runtime_test.go index 75f72b6c..0357dcb1 100644 --- a/test/cli_docker_runtime_test.go +++ b/test/cli_docker_runtime_test.go @@ -24,8 +24,10 @@ import ( const dockerFile = `FROM golang:latest FROM fnproject/go:dev as build-stage WORKDIR /function -ADD . /go/src/func/ -RUN cd /go/src/func/ && go build -o func +WORKDIR /go/src/func/ +ENV GO111MODULE=on +COPY . . +RUN go build -o func -v FROM fnproject/go WORKDIR /function COPY --from=build-stage /go/src/func/func /function/ diff --git a/test/cli_init_test.go b/test/cli_init_test.go index 232b7153..bfcfc446 100644 --- a/test/cli_init_test.go +++ b/test/cli_init_test.go @@ -24,15 +24,22 @@ import ( var runtimes = []string{ "go", + "go1.19", + "go1.18", "java", "java8", "java11", + "java17", "kotlin", "ruby", + "ruby3.1", + "ruby2.7", "node", + "node18", + "node16", + "node14", "python", - "python3.6", - "python3.7", + "python3.9", "python3.8", } diff --git a/test/cli_lang_boilerplate_test.go b/test/cli_lang_boilerplate_test.go index f87e02e1..26f9ea1e 100644 --- a/test/cli_lang_boilerplate_test.go +++ b/test/cli_lang_boilerplate_test.go @@ -28,19 +28,26 @@ var Runtimes = []struct { callInput string }{ {"go", ""}, + {"go1.19", ""}, + {"go1.18", ""}, {"dotnet", ""}, {"dotnet3.1", ""}, {"dotnet6.0", ""}, {"java", ""}, {"java8", ""}, {"java11", ""}, + {"java17", ""}, {"kotlin", ""}, {"node", ""}, + {"node18", ""}, + {"node16", ""}, + {"node14", ""}, {"ruby", ""}, + {"ruby3.1", ""}, + {"ruby2.7", ""}, {"python", ""}, - {"python3.6", ""}, - {"python3.7", ""}, {"python3.8", ""}, + {"python3.9", ""}, } func TestFnInitWithBoilerplateBuildsRuns(t *testing.T) { diff --git a/test/simplefunc/go.mod b/test/simplefunc/go.mod index 8c437b2d..63f21124 100644 --- a/test/simplefunc/go.mod +++ b/test/simplefunc/go.mod @@ -1,5 +1,5 @@ module github.com/fnproject/cli/test/simplefunc -go 1.12 +go 1.19 -require github.com/fnproject/fdk-go v0.0.0-20181025170718-26ed643bea68 +require github.com/fnproject/fdk-go v0.0.33 diff --git a/test/simplefunc/go.sum b/test/simplefunc/go.sum index 379edb2b..643ed8da 100644 --- a/test/simplefunc/go.sum +++ b/test/simplefunc/go.sum @@ -1,2 +1,2 @@ -github.com/fnproject/fdk-go v0.0.0-20181025170718-26ed643bea68 h1:T1Lm0ByviRKOUocQfjkVJ8EtinhJYwGVaoTQa2XVET0= -github.com/fnproject/fdk-go v0.0.0-20181025170718-26ed643bea68/go.mod h1:hzkP3qqXx+1pRBh2QVKr1I+jJ+5xrHIlh5z59XKZ/k0= +github.com/fnproject/fdk-go v0.0.33 h1:WwshAxOJ4pRauQKgaVkEADJEu4gNPqVfaY2AVW5KMqg= +github.com/fnproject/fdk-go v0.0.33/go.mod h1:hCpiyW8oIJpRdegoLf8PxKf9k+8mZZGeYgwSKOVG+K0= diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/.gitignore b/test/simplefunc/vendor/github.com/fnproject/fdk-go/.gitignore new file mode 100644 index 00000000..5687ba45 --- /dev/null +++ b/test/simplefunc/vendor/github.com/fnproject/fdk-go/.gitignore @@ -0,0 +1,3 @@ +/.idea/ +.DS_Store +fdk-go.iml diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/LICENSE b/test/simplefunc/vendor/github.com/fnproject/fdk-go/LICENSE index 97ee2c36..151b7eab 100644 --- a/test/simplefunc/vendor/github.com/fnproject/fdk-go/LICENSE +++ b/test/simplefunc/vendor/github.com/fnproject/fdk-go/LICENSE @@ -187,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2017 Oracle Corporation + Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/NOTICE.txt b/test/simplefunc/vendor/github.com/fnproject/fdk-go/NOTICE.txt new file mode 100644 index 00000000..4b371e6c --- /dev/null +++ b/test/simplefunc/vendor/github.com/fnproject/fdk-go/NOTICE.txt @@ -0,0 +1,23 @@ + Fn Project + ============ + +Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. + +Licensed 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. + +========================================================================== +Third Party Dependencies +========================================================================== + +This project includes or depends on code from third party projects. +Attributions are contained in THIRD_PARTY_LICENSES.txt \ No newline at end of file diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/README.md b/test/simplefunc/vendor/github.com/fnproject/fdk-go/README.md index e00b4460..a6f37a1d 100644 --- a/test/simplefunc/vendor/github.com/fnproject/fdk-go/README.md +++ b/test/simplefunc/vendor/github.com/fnproject/fdk-go/README.md @@ -1,98 +1,20 @@ -# Go Fn Development Kit (FDK) - [![GoDoc](https://godoc.org/github.com/fnproject/fdk-go?status.svg)](https://godoc.org/github.com/fnproject/fdk-go) -fdk-go provides convenience functions for writing Go fn code - -For getting started with fn, please refer to https://github.com/fnproject/fn/blob/master/README.md - -# Installing fdk-go - -```sh -go get github.com/fnproject/fdk-go -``` - -or your favorite vendoring solution :) - -# Examples - -For a simple getting started, see the [examples](/examples/hello) and follow -the [README](/examples/README.md). If you already have `fn` set up it -will take 2 minutes! - -# Advanced example - -TODO going to move to [examples](examples/) too :) -TODO make these `_example.go` instead of in markdown ;) - -```go -package main - -import ( - "context" - "fmt" - "io" - "encoding/json" - - fdk "github.com/fnproject/fdk-go" - "net/http" -) - -func main() { - fdk.Handle(fdk.HandlerFunc(myHandler)) -} - -// TODO make http.Handler example - -func myHandler(ctx context.Context, in io.Reader, out io.Writer) { - fnctx, ok := fdk.GetContext(ctx).(fdk.HTTPContext) - if !ok { - // optionally, this may be a good idea - fdk.WriteStatus(out, 400) - fdk.SetHeader(out, "Content-Type", "application/json") - io.WriteString(out, `{"error":"function not invoked via http trigger"}`) - return - } +# Go FDK Documentation +This is documentation for the Go function development kit (FDK) which provides convenience functions for writing Go Fn code. - contentType := fnctx.Header().Get("Content-Type") - if contentType != "application/json" { - // can assert content type for your api this way - fdk.WriteStatus(out, 400) - fdk.SetHeader(out, "Content-Type", "application/json") - io.WriteString(out, `{"error":"invalid content type"}`) - return - } +For getting started using the Go FDK , see the tutorial [here.](https://github.com/fnproject/tutorials/tree/master/Introduction) - if fnctx.RequestMethod() != "PUT" { - // can assert certain request methods for certain endpoints - fdk.WriteStatus(out, 404) - fdk.SetHeader(out, "Content-Type", "application/json") - io.WriteString(out, `{"error":"route not found, method not supported"}`) - return - } +To get the Go FDK simply import it in your program `github.com/fnproject/fdk-go`, and use `go get` to get it. - var person struct { - Name string `json:"name"` - } - json.NewDecoder(in).Decode(&person) +## User Information +* See the Fn [Quickstart](https://github.com/fnproject/fn/blob/master/README.md) for sample commands. +* [Detailed installation instructions](http://fnproject.io/tutorials/install/). +* [Configure your CLI Context](http://fnproject.io/tutorials/install/#ConfigureyourContext). +* For a list of commands see [Fn CLI Command Guide and Reference](https://github.com/fnproject/docs/blob/master/cli/README.md). +* For general information see Fn [docs](https://github.com/fnproject/docs) and [tutorials](https://fnproject.io/tutorials/). - // this is where you might insert person into a database or do something else +## Go FDK Development +See [CONTRIBUTING](https://github.com/fnproject/fn/blob/master/CONTRIBUTING.md) for information on contributing to the project. - all := struct { - Name string `json:"name"` - URL string `json:"url"` - Header http.Header `json:"header"` - Config map[string]string `json:"config"` - }{ - Name: person.Name, - URL: fnctx.RequestURL(), - Header: fnctx.Header(), - Config: fnctx.Config(), - } - // you can write your own headers & status, if you'd like to - fdk.SetHeader(out, "Content-Type", "application/json") - fdk.WriteStatus(out, 201) - json.NewEncoder(out).Encode(&all) -} -``` diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/THIRD_PARTY_LICENSES.txt b/test/simplefunc/vendor/github.com/fnproject/fdk-go/THIRD_PARTY_LICENSES.txt new file mode 100644 index 00000000..2c95a0c3 --- /dev/null +++ b/test/simplefunc/vendor/github.com/fnproject/fdk-go/THIRD_PARTY_LICENSES.txt @@ -0,0 +1,327 @@ +Third Party Attributions + +The following software (or subsets of the software) are dependencies +of this product. They are identified by the Fn Project Go FDK module(s) that use +them. + +The first section ("Third Party Runtime Dependencies") contains dependencies +that might be used at runtime by an Fn Project Go FDK application. + +The second section ("Third Party Attributions for Examples, Tests, Builds, etc") +contains dependencies that are used in examples and to test and build Fn Project Go FDK. +They are likely not needed at runtime by an Fn Project Go FDK application. + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Third Party Runtime Dependencies +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +fdk-go is licensed under the Apache License, Version 2.0. +License: A copy of the Apache License V2 is included at the end of this file. + +-------------------------------------------------------------------------------- + +Packages imported from the Go Standard Library: + +bytes +context +fmt +io +io/ioutil +log +net +net/http +net/url +os +path/filepath +runtime +strconv +strings +sync +time + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +License: BSD 3-Clause License + +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +Third Party Attributions for Examples, Tests, Builds, etc + +The following software (or subsets of the software) is used when building the +Fn Project Go FDK, or in the examples and tests. They are generally not required by +users of the Fn Project Go FDK and not required during runtime. +=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + +Packages imported from the Go Standard Library: + +context +encoding/json +io +io/ioutil +net +net/http +net/http/httptest +os +path/filepath +strings +testing +time + +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +License: BSD 3-Clause License +================================================================================ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed 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. + + diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/circle.yml b/test/simplefunc/vendor/github.com/fnproject/fdk-go/circle.yml deleted file mode 100644 index c0bfbce3..00000000 --- a/test/simplefunc/vendor/github.com/fnproject/fdk-go/circle.yml +++ /dev/null @@ -1,42 +0,0 @@ -version: 2 -jobs: - build: - docker: - - image: circleci/golang:1.11.0 - working_directory: ~/fdk-go - steps: - - checkout - - setup_remote_docker: - docker_layer_caching: true - - run: docker version - - run: docker pull fnproject/fnserver - # installing Fn CLI and starting the Fn server - - run: - command: | - curl -LSs https://raw.githubusercontent.com/fnproject/cli/master/install | sh - - run: - command: fn build - working_directory: examples/hello - - run: - command: docker build -t fnproject/fdk-go-init . - working_directory: images/init - - run: - command: docker build -t fnproject/fdk-go-build . - working_directory: images/build - - run: - command: docker build -t fnproject/fdk-go-runtime . - working_directory: images/runtime - - deploy: - command: | - if [[ "${CIRCLE_BRANCH}" == "master" && -z "${CIRCLE_PR_REPONAME}" ]]; then - func_version=$(awk '/^version:/ { print $2; }' func.yaml) - printenv DOCKER_PASS | docker login -u ${DOCKER_USER} --password-stdin - git config --global user.email "ci@fnproject.com" - git config --global user.name "CI" - git branch --set-upstream-to=origin/${CIRCLE_BRANCH} ${CIRCLE_BRANCH} - docker tag "hello:${func_version}" "fnproject/fdk-go-hello:${func_version}" - docker tag "hello:${func_version}" "fnproject/fdk-go-hello:latest" - docker push "fnproject/fdk-go-hello:${func_version}" - docker push "fnproject/fdk-go-hello:latest" - fi - working_directory: examples/hello diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/fdk.go b/test/simplefunc/vendor/github.com/fnproject/fdk-go/fdk.go index 6f6cd36a..856e4efc 100644 --- a/test/simplefunc/vendor/github.com/fnproject/fdk-go/fdk.go +++ b/test/simplefunc/vendor/github.com/fnproject/fdk-go/fdk.go @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. + * + * Licensed 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 fdk import ( @@ -98,6 +114,15 @@ type Context interface { // FnID is Config()["FN_FN_ID"] FnID() string + + // AppName is Config()["FN_APP_ID"] + AppName() string + + // FnName is Config()["FN_FN_Name"] + FnName() string + + // Tracing Context Data if available + TracingContextData() TracingContext } // HTTPContext contains all configuration for a function invocation sourced @@ -113,10 +138,66 @@ type HTTPContext interface { RequestMethod() string } +// TracingContext contains all configuration for a function invocated to +// get the tracing context data. +type TracingContext interface { + /** + * Returns true if tracing is enabled for this function invocation + * @return whether tracing is enabled + */ + IsTracingEnabled() bool + + /** + * Returns the URL to be used in tracing libraries as the destination for + * the tracing data + * @return a string containing the trace collector URL + */ + TraceCollectorURL() string + + /** + * Returns the current trace ID as extracted from Zipkin B3 headers if they + * are present on the request + * @return the trace ID as a string + */ + TraceId() string + + /** + * Returns the current span ID as extracted from Zipkin B3 headers if they + * are present on the request + * @return the span ID as a string + */ + SpanId() string + + /** + * Returns the parent span ID as extracted from Zipkin B3 headers if they + * are present on the request + * @return the parent span ID as a string + */ + ParentSpanId() string + + /** + * Returns the value of the Sampled header of the Zipkin B3 headers if they + * are present on the request + * @return true if sampling is enabled for the request + */ + IsSampled() bool + + /** + * Returns the value of the Flags header of the Zipkin B3 headers if they + * are present on the request + * @return the verbatim value of the X-B3-Flags header + */ + Flags() string + + // ServiceName is Config()["FN_APP_ID"] + Config()["FN_FN_Name"] + ServiceName() string +} + type baseCtx struct { - header http.Header - config map[string]string - callID string + header http.Header + config map[string]string + callID string + tracingContext tracingCtx } type httpCtx struct { @@ -127,16 +208,43 @@ type httpCtx struct { requestMethod string } +type tracingCtx struct { + traceCollectorURL string + traceId string + spanId string + parentSpanId string + sampled bool + flags string + tracingEnabled bool + serviceName string +} + func (c baseCtx) Config() map[string]string { return c.config } func (c baseCtx) Header() http.Header { return c.header } func (c baseCtx) ContentType() string { return c.header.Get("Content-Type") } func (c baseCtx) CallID() string { return c.callID } func (c baseCtx) AppID() string { return c.config["FN_APP_ID"] } func (c baseCtx) FnID() string { return c.config["FN_FN_ID"] } +func (c baseCtx) TracingContextData() TracingContext { + return c.tracingContext +} func (c httpCtx) RequestURL() string { return c.requestURL } func (c httpCtx) RequestMethod() string { return c.requestMethod } +func (c baseCtx) AppName() string { return c.config["FN_APP_NAME"] } +func (c baseCtx) FnName() string { return c.config["FN_FN_NAME"] } +func (c tracingCtx) ServiceName() string { + return c.serviceName +} +func (c tracingCtx) IsTracingEnabled() bool { return c.tracingEnabled } +func (c tracingCtx) TraceCollectorURL() string { return c.traceCollectorURL } +func (c tracingCtx) TraceId() string { return c.traceId } +func (c tracingCtx) SpanId() string { return c.spanId } +func (c tracingCtx) ParentSpanId() string { return c.parentSpanId } +func (c tracingCtx) IsSampled() bool { return c.sampled } +func (c tracingCtx) Flags() string { return c.flags } + func ctxWithDeadline(ctx context.Context, fnDeadline string) (context.Context, context.CancelFunc) { t, err := time.Parse(time.RFC3339, fnDeadline) if err == nil { diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/handler.go b/test/simplefunc/vendor/github.com/fnproject/fdk-go/handler.go index 7f44d7aa..1584eea1 100644 --- a/test/simplefunc/vendor/github.com/fnproject/fdk-go/handler.go +++ b/test/simplefunc/vendor/github.com/fnproject/fdk-go/handler.go @@ -1,9 +1,27 @@ +/* + * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. + * + * Licensed 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 fdk import ( "bytes" "context" + "fmt" "io" + "io/ioutil" "log" "net" "net/http" @@ -36,8 +54,13 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx, cancel := buildCtx(r.Context(), r) defer cancel() + logFrameHeader(r) + h.handler.Serve(ctx, r.Body, &resp) + io.Copy(ioutil.Discard, r.Body) // Ignoring error since r.Body may already be closed + r.Body.Close() + if _, ok := GetContext(ctx).(HTTPContext); ok { // XXX(reed): could put this in a response writer to clean up? not as easy as it looks (ordering wrt WriteHeader()) encapHeaders(w.Header()) @@ -46,6 +69,10 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // NOTE: FDKs don't set call status directly on the response at the moment... + // send back our version + w.Header().Set("Fn-Fdk-Version", versionHeader) + w.Header().Set("Fn-Fdk-Runtime", runtimeHeader) + // XXX(reed): 504 if ctx is past due / handle errors with 5xx? just 200 for now // copy response from user back up now with headers in place... io.Copy(w, buf) @@ -136,11 +163,46 @@ func withHTTPContext(ctx context.Context) context.Context { return WithContext(ctx, hctx) } +func setTracingContext(config map[string]string, header http.Header) tracingCtx { + if config["OCI_TRACING_ENABLED"] == "0" { + // When tracing is not enabled then we + // assign empty tracing context to + // the context + return tracingCtx{} + } + tctx := tracingCtx{ + traceCollectorURL: config["OCI_TRACE_COLLECTOR_URL"], + traceId: header.Get("x-b3-traceid"), + spanId: header.Get("x-b3-spanid"), + parentSpanId: header.Get("x-b3-parentspanid"), + flags: header.Get("x-b3-flags"), + sampled: true, + serviceName: strings.ToLower(config["FN_APP_NAME"] + "::" + config["FN_FN_NAME"]), + } + + if header.Get("x-b3-sampled") != "" { + isSampled, err := strconv.ParseBool(header.Get("x-b3-sampled")) + if err == nil { + tctx.sampled = isSampled + } + } + + isEnabled, err := strconv.ParseBool(config["OCI_TRACING_ENABLED"]) + tctx.tracingEnabled = false + if err == nil { + tctx.tracingEnabled = isEnabled + } + + return tctx +} + func withBaseContext(ctx context.Context, r *http.Request) (_ context.Context, cancel func()) { + configData := buildConfig() // from env vars (stinky, but effective...) rctx := baseCtx{ - config: buildConfig(), // from env vars (stinky, but effective...) - callID: r.Header.Get("Fn-Call-Id"), - header: r.Header, + config: configData, + callID: r.Header.Get("Fn-Call-Id"), + header: r.Header, + tracingContext: setTracingContext(configData, r.Header), } ctx = WithContext(ctx, rctx) @@ -217,3 +279,20 @@ func sockPerm(phonySock, realSock string) { log.Fatalln("error linking fake sock to real sock", err) } } + +// If enabled, print the log framing content. +func logFrameHeader(r *http.Request) { + framer := os.Getenv("FN_LOGFRAME_NAME") + if framer == "" { + return + } + valueSrc := os.Getenv("FN_LOGFRAME_HDR") + if valueSrc == "" { + return + } + id := r.Header.Get(valueSrc) + if id != "" { + fmt.Fprintf(os.Stderr, "\n%s=%s\n", framer, id) + fmt.Fprintf(os.Stdout, "\n%s=%s\n", framer, id) + } +} diff --git a/test/simplefunc/vendor/github.com/fnproject/fdk-go/version.go b/test/simplefunc/vendor/github.com/fnproject/fdk-go/version.go new file mode 100644 index 00000000..5d3e73e1 --- /dev/null +++ b/test/simplefunc/vendor/github.com/fnproject/fdk-go/version.go @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. + * + * Licensed 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 fdk + +import ( + "fmt" + "runtime" + "strings" +) + +// Version is the FDK version +const Version = "0.0.33" + +var versionHeader = fmt.Sprintf("fdk-go/%s", Version) +var runtimeHeader = fmt.Sprintf("go/%s", strings.TrimLeft(runtime.Version(), "go")) diff --git a/test/simplefunc/vendor/modules.txt b/test/simplefunc/vendor/modules.txt index ca4f816a..00c778e6 100644 --- a/test/simplefunc/vendor/modules.txt +++ b/test/simplefunc/vendor/modules.txt @@ -1,2 +1,3 @@ -# github.com/fnproject/fdk-go v0.0.0-20181025170718-26ed643bea68 +# github.com/fnproject/fdk-go v0.0.33 +## explicit; go 1.19 github.com/fnproject/fdk-go