Exemplo n.º 1
0
// Build injects a script for loading the environment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if 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.json",
		HandleFile:   file,
		HandleMethod: method,
	})

	if err != nil {
		return err
	}

	fn.Handler = "_apex_index.handle"

	return zip.AddBytes("_apex_index.js", buf.Bytes())
}
Exemplo n.º 2
0
// Build injects a script for loading the environment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if fn.Runtime != RuntimeCanonical || 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_main.handle"

	return zip.AddBytesMTime("_apex_main.py", buf.Bytes(), time.Unix(0, 0))
}
Exemplo n.º 3
0
// Build calls mvn package, add jar contents to zipfile.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) error {
	if fn.Runtime != RuntimeCanonical {
		return nil
	}

	if fn.Environment != nil {
		fn.Log.Debug("creating properties file")
		if err := p.generatePropertiesFile(fn); err != nil {
			return errors.New("Can't generate properties file: " + err.Error())
		}
	}

	fn.Log.Debug("creating jar")
	mvnCmd := exec.Command("mvn", "package", "-Djar.finalName="+targetJarFile)
	mvnCmd.Dir = fn.Path
	if err := mvnCmd.Run(); err != nil {
		return err
	}

	expectedJarPath := filepath.Join(fn.Path, "target", targetJarFile+".jar")
	if _, err := os.Stat(expectedJarPath); err != nil {
		return errors.New("Expected jar file not found")
	}

	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)
	}

	if err := p.cleanProperties(fn); err != nil {
		return err
	}

	return nil
}
Exemplo n.º 4
0
Arquivo: env.go Projeto: elizar/apex
// Build hook adds .env.json populate with Function.Enironment.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) 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.AddBytesMTime(FileName, env, time.Unix(0, 0))
}
Exemplo n.º 5
0
// Build adds the nodejs shim files.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) 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
}
Exemplo n.º 6
0
Arquivo: java.go Projeto: tobyjoe/apex
// Build adds the jar contents to zipfile.
func (p *Plugin) Build(fn *function.Function, zip *archive.Archive) 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
}