Exemplo n.º 1
0
// NewPipelineOptions big-ass constructor
func NewPipelineOptions(c util.Settings, e *util.Environment) (*PipelineOptions, error) {
	globalOpts, err := NewGlobalOptions(c, e)
	if err != nil {
		return nil, err
	}

	// dockerOpts, err := NewDockerOptions(c, e, globalOpts)
	// if err != nil {
	//   return nil, err
	// }

	awsOpts, err := NewAWSOptions(c, e, globalOpts)
	if err != nil {
		return nil, err
	}

	gitOpts, err := NewGitOptions(c, e, globalOpts)
	if err != nil {
		return nil, err
	}

	keenOpts, err := NewKeenOptions(c, e, globalOpts)
	if err != nil {
		return nil, err
	}

	reporterOpts, err := NewReporterOptions(c, e, globalOpts)
	if err != nil {
		return nil, err
	}

	buildID, _ := c.String("build-id")
	deployID, _ := c.String("deploy-id")
	pipelineID := ""
	if deployID != "" {
		pipelineID = deployID
	} else {
		pipelineID = buildID
	}
	deployTarget, _ := c.String("deploy-target")
	pipeline, _ := c.String("pipeline")

	applicationName, err := guessApplicationName(c, e)
	if err != nil {
		return nil, err
	}
	applicationID := guessApplicationID(c, e, applicationName)
	applicationOwnerName := guessApplicationOwnerName(c, e)
	applicationStartedByName, _ := c.String("application-started-by-name")
	if applicationStartedByName == "" {
		applicationStartedByName = applicationOwnerName
	}

	repository, _ := c.String("commit")
	shouldCommit := (repository != "")
	tag := guessTag(c, e)
	message := guessMessage(c, e)
	shouldStoreLocal, _ := c.Bool("store-local")
	shouldStoreS3, _ := c.Bool("store-s3")

	workingDir, _ := c.String("working-dir")
	workingDir, _ = filepath.Abs(workingDir)

	guestRoot, _ := c.String("guest-root")
	mntRoot, _ := c.String("mnt-root")
	reportRoot, _ := c.String("report-root")

	projectID := guessProjectID(c, e)
	projectPath := guessProjectPath(c, e)
	projectURL := guessProjectURL(c, e)

	if projectPath == workingDir {
		return nil, fmt.Errorf("Project path can't be the same as the working dir")
	}

	// These timeouts are given in minutes but we store them as milliseconds
	commandTimeoutFloat, _ := c.Float64("command-timeout")
	commandTimeout := int(commandTimeoutFloat * 1000 * 60)
	noResponseTimeoutFloat, _ := c.Float64("no-response-timeout")
	noResponseTimeout := int(noResponseTimeoutFloat * 1000 * 60)
	shouldArtifacts, _ := c.Bool("artifacts")
	// TODO(termie): switch negative flag
	shouldRemove, _ := c.Bool("no-remove")
	shouldRemove = !shouldRemove
	sourceDir, _ := c.String("source-dir")

	attachOnError, _ := c.Bool("attach-on-error")
	directMount, _ := c.Bool("direct-mount")
	enableDevSteps, _ := c.Bool("enable-dev-steps")
	publishPorts, _ := c.StringSlice("publish")
	enableVolumes, _ := c.Bool("enable-volumes")
	werckerYml, _ := c.String("wercker-yml")

	return &PipelineOptions{
		GlobalOptions: globalOpts,
		AWSOptions:    awsOpts,
		// DockerOptions:   dockerOpts,
		GitOptions:      gitOpts,
		KeenOptions:     keenOpts,
		ReporterOptions: reporterOpts,

		HostEnv: e,

		BuildID:      buildID,
		DeployID:     deployID,
		PipelineID:   pipelineID,
		DeployTarget: deployTarget,
		Pipeline:     pipeline,

		ApplicationID:            applicationID,
		ApplicationName:          applicationName,
		ApplicationOwnerName:     applicationOwnerName,
		ApplicationStartedByName: applicationStartedByName,

		Message:          message,
		Tag:              tag,
		Repository:       repository,
		ShouldCommit:     shouldCommit,
		ShouldStoreLocal: shouldStoreLocal,
		ShouldStoreS3:    shouldStoreS3,

		WorkingDir: workingDir,

		GuestRoot:  guestRoot,
		MntRoot:    mntRoot,
		ReportRoot: reportRoot,

		ProjectID:   projectID,
		ProjectURL:  projectURL,
		ProjectPath: projectPath,

		CommandTimeout:    commandTimeout,
		NoResponseTimeout: noResponseTimeout,
		ShouldArtifacts:   shouldArtifacts,
		ShouldRemove:      shouldRemove,
		SourceDir:         sourceDir,

		AttachOnError:  attachOnError,
		DirectMount:    directMount,
		EnableDevSteps: enableDevSteps,
		PublishPorts:   publishPorts,
		EnableVolumes:  enableVolumes,
		WerckerYml:     werckerYml,
	}, nil
}