Пример #1
0
func (s *OptionsSuite) TestBuildOptions() {
	args := defaultArgs("--run-id", "fake-build-id")
	test := func(c *cli.Context) {
		opts, err := core.NewBuildOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.Equal("fake-build-id", opts.RunID)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Пример #2
0
func (s *OptionsSuite) TestEmptyBuildOptions() {
	args := defaultArgs()
	test := func(c *cli.Context) {
		opts, err := core.NewBuildOptions(util.NewCLISettings(c), emptyEnv())
		s.Nil(err)
		s.NotEqual("", opts.BuildID)
		s.Equal(opts.BuildID, opts.PipelineID)
		s.Equal("", opts.DeployID)
	}
	run(s, globalFlags, pipelineFlags, test, args)
}
Пример #3
0
func (b *DockerBuilder) getOptions(env *util.Environment, config *core.BoxConfig) (*core.PipelineOptions, error) {
	c, err := b.configURL(config)
	if err != nil {
		return nil, err
	}
	servicePath := filepath.Join(c.Host, c.Path)
	if !filepath.IsAbs(servicePath) {
		servicePath, err = filepath.Abs(
			filepath.Join(b.options.ProjectPath, servicePath))
		if err != nil {
			return nil, err
		}
	}

	flagSet := func(name string, flags []cli.Flag) *flag.FlagSet {
		set := flag.NewFlagSet(name, flag.ContinueOnError)

		for _, f := range flags {
			f.Apply(set)
		}
		return set
	}

	set := flagSet("runservice", FlagsFor(PipelineFlagSet, WerckerInternalFlagSet))
	args := []string{
		servicePath,
	}
	if err := set.Parse(args); err != nil {
		return nil, err
	}
	ctx := cli.NewContext(nil, set, set)
	settings := util.NewCLISettings(ctx)
	newOptions, err := core.NewBuildOptions(settings, env)
	if err != nil {
		return nil, err
	}

	newOptions.GlobalOptions = b.options.GlobalOptions
	newOptions.ShouldCommit = true
	newOptions.PublishPorts = b.options.PublishPorts
	// TODO(termie): PACKAGING these moved
	// newOptions.DockerLocal = true
	// newOptions.DockerOptions = s.dockerOptions
	newOptions.Pipeline = c.Fragment
	return newOptions, nil
}
Пример #4
0
)

var (
	cliLogger    = util.RootLogger().WithField("Logger", "CLI")
	buildCommand = cli.Command{
		Name:      "build",
		ShortName: "b",
		Usage:     "build a project",
		Action: func(c *cli.Context) {
			envfile := c.GlobalString("environment")
			_ = godotenv.Load(envfile)

			env := util.NewEnvironment(os.Environ()...)

			settings := util.NewCLISettings(c)
			opts, err := core.NewBuildOptions(settings, env)
			if err != nil {
				cliLogger.Errorln("Invalid options\n", err)
				os.Exit(1)
			}
			dockerOptions, err := dockerlocal.NewDockerOptions(settings, env)
			if err != nil {
				cliLogger.Errorln("Invalid options\n", err)
				os.Exit(1)
			}
			_, err = cmdBuild(context.Background(), opts, dockerOptions)
			if err != nil {
				cliLogger.Fatal(err)
			}
		},
		Flags: FlagsFor(PipelineFlagSet, WerckerInternalFlagSet),