chore: remove dead appsody code

All of the code in `./appsody` is no longer used. This commit simply
removes it from the repo.
This commit is contained in:
Lance Ball 2020-09-16 11:09:55 -04:00
parent b7670a3f7b
commit 5b93955f8b
5 changed files with 0 additions and 290 deletions

View File

@ -1,77 +0,0 @@
package appsody
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
)
// Builder of images from Function source using appsody.
type Builder struct {
// Verbose logging flag.
Verbose bool
registry string // registry domain (docker.io, quay.io, etc.)
namespace string // namespace (username, org name, etc.)
}
// NewBuilder creates an instance of an appsody-backed image builder.
func NewBuilder(registry, namespace string) *Builder {
return &Builder{
registry: registry,
namespace: namespace}
}
// Build an image from the Function source at path.
func (n *Builder) Build(name, runtime, path string) (image string, err error) {
// Check for the appsody binary explicitly so that we can return
// an extra-friendly error message.
_, err = exec.LookPath("appsody")
if err != nil {
err = errors.New("please install 'appsody'")
return
}
// Fully qualified image name. Ex quay.io/user/www-example-com:20200102T1234
// timestamp := time.Now().Format("20060102T150405")
// image = fmt.Sprintf("%v/%v/%v:%v", n.registry, n.namespace, name, timestamp)
// Simple image name, which uses :latest
image = fmt.Sprintf("%v/%v/%v", n.registry, n.namespace, name)
// set up the command, specifying a sanitized project name and connecting
// standard output and error.
cmd := exec.Command("appsody", "build", "-t", image)
cmd.Dir = path
// If verbose logging is enabled, echo appsody's chatty stdout.
if n.Verbose {
fmt.Println(cmd)
cmd.Stdout = os.Stdout
}
// Capture stderr for echoing on failure.
var stderr bytes.Buffer
cmd.Stderr = &stderr
// Run the command, echoing captured stderr as well ass the cmd internal error.
err = cmd.Run()
if err != nil {
// TODO: sanitize stderr from appsody, or submit a PR to remove duplicates etc.
err = fmt.Errorf("%v. %v", stderr.String(), err.Error())
return
}
// remove the superfluous app-deploy.yaml
cfg := filepath.Join(path, "app-deploy.yaml")
if _, err = os.Stat(cfg); err == nil {
err = os.Remove(cfg)
if err != nil {
fmt.Fprintf(os.Stderr, "unable to remove superfluous appsody config: %v\n", err)
}
}
return
}

View File

@ -1,84 +0,0 @@
package appsody
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"strings"
"github.com/boson-project/faas/k8s"
)
// NameMappings are short-name to repository full name mappings,
// enabling shorthand `faas create go` rather than `faas create go-ce-functions`
var StackShortNames = map[string]string{
"go": "go-ce-functions",
"node": "node-ce-functions",
"quarkus": "quarkus-ce-functions",
}
// Initializer of Functions using the appsody binary.
type Initializer struct {
// Verbose logging flag.
Verbose bool
}
// NewInitializer creates an instance of an appsody-backed initializer.
func NewInitializer() *Initializer {
return &Initializer{}
}
// Initialize a new Function of the given name, of the given runtime, at the given path.
func (n *Initializer) Initialize(name, runtime, path string) error {
// Check for the appsody binary explicitly so that we can return
// an extra-friendly error message.
_, err := exec.LookPath("appsody")
if err != nil {
return errors.New("please install 'appsody'")
}
// Appsody does not support domain names as the project name
// (ex: www.example.com), and has extremely strict naming requirements
// (subdomains per rfc 1035). So let's just assume its name must be a valid domain, and
// encode it as a 1035 domain by doubling down on hyphens.
project, err := k8s.ToSubdomain(name)
if err != nil {
return err
}
// Dereference stack short name. ex. "go" -> "go-ce-functions"
stackName, ok := StackShortNames[runtime]
if !ok {
runtimes := []string{}
for k := range StackShortNames {
runtimes = append(runtimes, k)
}
return fmt.Errorf("Unrecognized runtime '%v'. Please choose one: %v.", runtime, strings.Join(runtimes, ", "))
}
// set up the command, specifying a sanitized project name and connecting
// standard output and error.
cmd := exec.Command("appsody", "init", "boson/"+stackName, "--project-name", project)
cmd.Dir = path
// If verbose logging is enabled, echo appsody's chatty stdout.
if n.Verbose {
fmt.Println(cmd)
cmd.Stdout = os.Stdout
}
// Capture stderr for echoing on failure.
var stderr bytes.Buffer
cmd.Stderr = &stderr
// Run the command, echoing captured stderr as well ass the cmd internal error.
err = cmd.Run()
if err != nil {
// TODO: sanitize stderr from appsody, or submit a PR to remove duplicates etc.
err = fmt.Errorf("%v. %v", stderr.String(), err.Error())
}
return err
}

View File

@ -1,53 +0,0 @@
package appsody_test
import (
"flag"
"fmt"
"os"
"testing"
"github.com/boson-project/faas/appsody"
)
// Enabling Appsody Binary Integration Tests
//
// The appsody package constitutes an integration between the core client logic
// and the concrete implementation of an Initializer using the appsody binary.
// These tests are therefore disabled by default for local development but are
// enabled during deploy for e2e tests etc.
//
// For development of this package in particualr, the flag will need to be
// either manually set, or ones IDE set to add the flag such that the tests run.
var enableTestAppsodyIntegration = flag.Bool("enable-test-appsody-integration", false, "Enable tests requiring local appsody binary.")
// TestInitialize ensures that the local appsody binary initializes a stack as expected.
func TestInitialize(t *testing.T) {
// Abort if not explicitly enabled.
if !*enableTestAppsodyIntegration {
fmt.Fprintln(os.Stdout, "Skipping tests which require 'appsody' binary. enable with --enable-test-appsody-integration")
t.Skip()
}
// Create the directory in which the Function will be initialized,
// removing it on test completion.
if err := os.Mkdir("testdata/example.com/www", 0700); err != nil {
t.Fatal(err)
}
defer os.RemoveAll("testdata/example.com/www")
// Instantiate a new appsody-based initializer
initializer := appsody.NewInitializer()
initializer.Verbose = true
if err := initializer.Initialize("testfunc", "go", "testdata/example.com/www"); err != nil {
t.Fatal(err)
}
// TODO: verify the stack appears as expected?
}
// TestInvalidInput ensures that invalid input to the
func TestInvalidInput(t *testing.T) {
// TODO: dots in names are converted
// missing input (empty strings)
// invalid paths
}

View File

@ -1,44 +0,0 @@
package appsody_test
import (
"fmt"
"os"
"testing"
)
// TestRun ensures that the local appsody binary runs a stack as expected.
func TestRun(t *testing.T) {
// Abort if not explicitly enabled.
if !*enableTestAppsodyIntegration {
fmt.Fprintln(os.Stdout, "Skipping tests which require 'appsody' binary. enable with --enable-test-appsody-initializer")
t.Skip()
}
// Testdata Function
//
// The directory has been pre-populated with a runnable base Function by running
// init and committing the result, such that this test is not dependent on a
// functioning creation step. This code will need to be updated for any
// backwards incompatible changes to the templated base go func.
// Run the Function
// TODO: in a separate goroutine, submit an HTTP or CloudEvent request to the
// running Function, and confirm expected OK response, then close down the
// running Function by interrupting/canceling run. This may requre an update
// to the runner to run the command with a cancelable context, and cancel on
// normal signals as well as a signal specific to these tests such as SIGUSR1.
/*
runner := appsody.NewRunner()
err := runner.Run("./testdata/example.com/runnable")
if err != nil {
t.Fatal(err)
}
..
// submit cloud event
...
// send signal os.SIGUSR1
*/
}

View File

@ -1,32 +0,0 @@
package function
import (
"context"
"fmt"
"os"
cloudevents "github.com/cloudevents/sdk-go"
)
// Handle a CloudEvent.
// Supported Function signatures:
// func()
// func() error
// func(context.Context)
// func(context.Context) error
// func(cloudevents.Event)
// func(cloudevents.Event) error
// func(context.Context, cloudevents.Event)
// func(context.Context, cloudevents.Event) error
// func(cloudevents.Event, *cloudevents.EventResponse)
// func(cloudevents.Event, *cloudevents.EventResponse) error
// func(context.Context, cloudevents.Event, *cloudevents.EventResponse)
// func(context.Context, cloudevents.Event, *cloudevents.EventResponse) error
func Handle(ctx context.Context, event cloudevents.Event) error {
if err := event.Validate(); err != nil {
fmt.Fprintf(os.Stderr, "invalid event received. %v", err)
return err
}
fmt.Printf("%v\n", event)
return nil
}