Exemple #1
0
// Run command.
func run(c *cobra.Command, args []string) error {
	stats.Track("Deploy", map[string]interface{}{
		"concurrency": concurrency,
		"has_alias":   alias != "",
		"env":         len(env),
		"args":        len(args),
	})

	root.Project.Concurrency = concurrency
	root.Project.Alias = alias

	if err := root.Project.LoadFunctions(args...); err != nil {
		return err
	}

	for _, fn := range root.Project.Functions {
		stats.Track("Deploy Function", map[string]interface{}{
			"runtime":      fn.Runtime,
			"has_alias":    alias != "",
			"has_env_file": envFile != "",
			"env":          len(env),
		})
	}

	if envFile != "" {
		if err := root.Project.LoadEnvFromFile(envFile); err != nil {
			return fmt.Errorf("reading env file %q: %s", envFile, err)
		}
	}

	vars, err := utils.ParseEnv(env)
	if err != nil {
		return err
	}

	for k, v := range vars {
		root.Project.Setenv(k, v)
	}

	return root.Project.DeployAndClean()
}
Exemple #2
0
// Run command.
func run(c *cobra.Command, args []string) error {
	if err := root.Project.LoadFunctions(name); err != nil {
		return err
	}

	fn := root.Project.Functions[0]

	stats.Track("Build", map[string]interface{}{
		"runtime":      fn.Runtime,
		"env":          len(env),
		"has_env_file": envFile != "",
	})

	if envFile != "" {
		if err := root.Project.LoadEnvFromFile(envFile); err != nil {
			return fmt.Errorf("reading env file %q: %s", envFile, err)
		}
	}

	vars, err := utils.ParseEnv(env)
	if err != nil {
		return err
	}

	for k, v := range vars {
		root.Project.Setenv(k, v)
	}

	zip, err := fn.Build()
	if err != nil {
		return err
	}

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

	_, err = io.Copy(os.Stdout, zip)
	return err
}
Exemple #3
0
func Test_ParseEnv_missingValue(t *testing.T) {
	m, err := utils.ParseEnv([]string{"foo=bar", "bar"})
	assert.Error(t, err, "expected an error")
	assert.Equal(t, `environment variable "bar" is missing a value`, err.Error())
	assert.Nil(t, m)
}
Exemple #4
0
func Test_ParseEnv_ok(t *testing.T) {
	m, err := utils.ParseEnv([]string{"foo=bar", "bar=baz"})
	assert.NoError(t, err, "error parsing")
	expected := map[string]string{"foo": "bar", "bar": "baz"}
	assert.Equal(t, expected, m)
}