From 456e56342efaf5ce386ec7f1ee2f6829958947cf Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Tue, 24 Dec 2019 14:21:47 +0000 Subject: [PATCH] Use k3sup to determine client arch * Set image suffix for OpenFaaS Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- Gopkg.lock | 9 ++++++ Gopkg.toml | 3 ++ cmd/up.go | 25 ++++++++++++++-- vendor/github.com/alexellis/k3sup/LICENSE | 21 ++++++++++++++ .../github.com/alexellis/k3sup/pkg/env/env.go | 29 +++++++++++++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 vendor/github.com/alexellis/k3sup/LICENSE create mode 100644 vendor/github.com/alexellis/k3sup/pkg/env/env.go diff --git a/Gopkg.lock b/Gopkg.lock index 56af5cf1..5750a197 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -45,6 +45,14 @@ revision = "961405ea754427780f2151adff607fa740d377f7" version = "0.3.0" +[[projects]] + digest = "1:6076d857867a70e87dd1994407deb142f27436f1293b13e75cc053192d14eb0c" + name = "github.com/alexellis/k3sup" + packages = ["pkg/env"] + pruneopts = "UT" + revision = "f9a4adddc732742a9ee7962609408fb0999f2d7b" + version = "0.7.1" + [[projects]] digest = "1:386ca0ac781cc1b630b3ed21725759770174140164b3faf3810e6ed6366a970b" name = "github.com/containerd/containerd" @@ -449,6 +457,7 @@ analyzer-version = 1 input-imports = [ "github.com/alexellis/go-execute/pkg/v1", + "github.com/alexellis/k3sup/pkg/env", "github.com/containerd/containerd", "github.com/containerd/containerd/cio", "github.com/containerd/containerd/containers", diff --git a/Gopkg.toml b/Gopkg.toml index a37236b2..8e2cd109 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -10,6 +10,9 @@ name = "github.com/spf13/cobra" version = "0.0.5" +[[constraint]] + name = "github.com/alexellis/k3sup" + version = "0.7.1" [[constraint]] name = "github.com/alexellis/go-execute" diff --git a/cmd/up.go b/cmd/up.go index 576d28d3..8490aab2 100644 --- a/cmd/up.go +++ b/cmd/up.go @@ -11,6 +11,7 @@ import ( "time" "github.com/alexellis/faasd/pkg" + "github.com/alexellis/k3sup/pkg/env" "github.com/spf13/cobra" ) @@ -22,7 +23,25 @@ var upCmd = &cobra.Command{ func runUp(_ *cobra.Command, _ []string) error { - services := makeServiceDefinitions() + clientArch, clientOS := env.GetClientArch() + + if clientOS != "Linux" { + return fmt.Errorf("You can only use faasd on Linux") + } + clientSuffix := "" + switch clientArch { + case "x86_64": + clientSuffix = "" + break + case "armhf": + case "arm64": + clientSuffix = clientArch + break + case "aarch64": + clientSuffix = "arm64" + } + + services := makeServiceDefinitions(clientSuffix) start := time.Now() supervisor, err := pkg.NewSupervisor("/run/containerd/containerd.sock") @@ -69,7 +88,7 @@ func runUp(_ *cobra.Command, _ []string) error { return nil } -func makeServiceDefinitions() []pkg.Service { +func makeServiceDefinitions(archSuffix string) []pkg.Service { wd, _ := os.Getwd() return []pkg.Service{ @@ -104,7 +123,7 @@ func makeServiceDefinitions() []pkg.Service { "faas_nats_address=nats", "faas_nats_port=4222", }, - Image: "docker.io/openfaas/gateway:0.18.7", + Image: "docker.io/openfaas/gateway:0.18.7" + archSuffix, Mounts: []pkg.Mount{}, Caps: []string{"CAP_NET_RAW"}, }, diff --git a/vendor/github.com/alexellis/k3sup/LICENSE b/vendor/github.com/alexellis/k3sup/LICENSE new file mode 100644 index 00000000..96456b40 --- /dev/null +++ b/vendor/github.com/alexellis/k3sup/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Alex Ellis + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/vendor/github.com/alexellis/k3sup/pkg/env/env.go b/vendor/github.com/alexellis/k3sup/pkg/env/env.go new file mode 100644 index 00000000..8ae5ed79 --- /dev/null +++ b/vendor/github.com/alexellis/k3sup/pkg/env/env.go @@ -0,0 +1,29 @@ +package env + +import ( + "log" + "strings" + + execute "github.com/alexellis/go-execute/pkg/v1" +) + +// GetClientArch returns a pair of arch and os +func GetClientArch() (string, string) { + task := execute.ExecTask{Command: "uname", Args: []string{"-m"}} + res, err := task.Execute() + if err != nil { + log.Println(err) + } + + arch := strings.TrimSpace(res.Stdout) + + taskOS := execute.ExecTask{Command: "uname", Args: []string{"-s"}} + resOS, errOS := taskOS.Execute() + if errOS != nil { + log.Println(errOS) + } + + os := strings.TrimSpace(resOS.Stdout) + + return arch, os +}