diff --git a/README.md b/README.md index baa04bb..dcadd88 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,19 @@ ofc-bootstrap registry-login --username --password-stdi ``` The file will be created in `./credentials/` +### Logs for functions + +You can view the logs of functions using `journalctl`: + +```bash +journalctl -t openfaas-fn:FUNCTION_NAME + + +faas-cli store deploy figlet +journalctl -t openfaas-fn:figlet -f & +echo logs | faas-cli invoke figlet +``` + ### Manual / developer instructions See [here for manual / developer instructions](docs/DEV.md) diff --git a/cmd/collect.go b/cmd/collect.go index d7daff0..253f479 100644 --- a/cmd/collect.go +++ b/cmd/collect.go @@ -12,6 +12,10 @@ import ( "github.com/spf13/cobra" ) +func CollectCommand() *cobra.Command { + return collectCmd +} + var collectCmd = &cobra.Command{ Use: "collect", Short: "Collect logs to the journal", diff --git a/cmd/root.go b/cmd/root.go index 7f995ca..a63494a 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -18,6 +18,10 @@ func init() { rootCommand.AddCommand(collectCmd) } +func RootCommand() *cobra.Command { + return rootCommand +} + var ( // GitCommit Git Commit SHA GitCommit string diff --git a/main.go b/main.go index aa4e172..f189b3c 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "os" "github.com/openfaas/faasd/cmd" @@ -15,6 +16,21 @@ var ( ) func main() { + + if _, ok := os.LookupEnv("CONTAINER_ID"); ok { + collect := cmd.RootCommand() + collect.SetArgs([]string{"collect"}) + collect.SilenceUsage = true + collect.SilenceErrors = true + + err := collect.Execute() + if err != nil { + fmt.Fprintf(os.Stderr, err.Error()) + os.Exit(1) + } + os.Exit(0) + } + if err := cmd.Execute(Version, GitCommit); err != nil { os.Exit(1) } diff --git a/pkg/provider/handlers/deploy.go b/pkg/provider/handlers/deploy.go index bc769c1..0987424 100644 --- a/pkg/provider/handlers/deploy.go +++ b/pkg/provider/handlers/deploy.go @@ -120,7 +120,10 @@ func deploy(ctx context.Context, req types.FunctionDeployment, client *container func createTask(ctx context.Context, client *containerd.Client, container containerd.Container, cni gocni.CNI) error { name := container.ID() - task, taskErr := container.NewTask(ctx, cio.NewCreator(cio.WithStdio)) + // task, taskErr := container.NewTask(ctx, cio.NewCreator(cio.WithStdio)) + + task, taskErr := container.NewTask(ctx, cio.BinaryIO("/usr/local/bin/faasd", nil)) + if taskErr != nil { return fmt.Errorf("unable to start task: %s, error: %s", name, taskErr) }