// Build injects a script for loading the environment. func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { if !p.runtimeSupported(fn) || len(fn.Environment) == 0 { return nil } fn.Log.Debug("injecting prelude") var buf bytes.Buffer file := strings.Split(fn.Handler, ".")[0] method := strings.Split(fn.Handler, ".")[1] err := prelude.Execute(&buf, struct { EnvFile string HandleFile string HandleMethod string }{ EnvFile: env.FileName, HandleFile: file, HandleMethod: method, }) if err != nil { return err } fn.Handler = "_apex_index.handle" return zip.AddBytes("_apex_index.js", buf.Bytes()) }
// Build injects a script for loading the environment. func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { if fn.Runtime != RuntimeCanonical || len(fn.Environment) == 0 { return nil } if len(strings.Split(fn.Handler, ".")) < 2 { return errors.New("lambda requires handler function name to be of the format 'filename.function_name'") } fn.Log.Debug("injecting prelude") var buf bytes.Buffer file := strings.Split(fn.Handler, ".")[0] method := strings.Split(fn.Handler, ".")[1] err := prelude.Execute(&buf, struct { EnvFile string HandleFile string HandleMethod string }{ EnvFile: env.FileName, HandleFile: file, HandleMethod: method, }) if err != nil { return err } fn.Handler = "_apex_main." + method return zip.AddBytes("_apex_main.py", buf.Bytes()) }
// Build hook adds .env.json populate with Function.Enironment. func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { if len(fn.Environment) == 0 { return nil } fn.Log.WithField("env", fn.Environment).Debug("adding env") env, err := json.Marshal(fn.Environment) if err != nil { return err } return zip.AddBytes(FileName, env) }
// Build adds the nodejs shim files. func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { if fn.Shim { fn.Log.Debug("add shim") if err := zip.AddBytes("index.js", shim.MustAsset("index.js")); err != nil { return err } if err := zip.AddBytes("byline.js", shim.MustAsset("byline.js")); err != nil { return err } } return nil }
// Build adds the jar contents to zipfile. func (p *Plugin) Build(fn *function.Function, zip *archive.Zip) error { if fn.Runtime != Runtime { return nil } fn.Runtime = RuntimeCanonical fn.Log.Debugf("searching for JAR (%s) in directories: %s", jarFile, strings.Join(jarSearchPaths, ", ")) expectedJarPath := findJar(fn.Path) if expectedJarPath == "" { return errors.New("Expected jar file not found") } fn.Log.Debugf("found jar path: %s", expectedJarPath) fn.Log.Debug("appending compiled files") reader, err := azip.OpenReader(expectedJarPath) if err != nil { return err } defer reader.Close() for _, file := range reader.File { r, err := file.Open() if err != nil { return err } b, err := ioutil.ReadAll(r) if err != nil { return err } r.Close() zip.AddBytes(file.Name, b) } return nil }