示例#1
0
// NewDockerOptions constructor
func NewDockerOptions(c util.Settings, e *util.Environment) (*DockerOptions, error) {
	dockerHost, _ := c.String("docker-host")
	dockerTLSVerify, _ := c.String("docker-tls-verify")
	dockerCertPath, _ := c.String("docker-cert-path")
	dockerDNS, _ := c.StringSlice("docker-dns")
	dockerLocal, _ := c.Bool("docker-local")

	speculativeOptions := &DockerOptions{
		DockerHost:      dockerHost,
		DockerTLSVerify: dockerTLSVerify,
		DockerCertPath:  dockerCertPath,
		DockerDNS:       dockerDNS,
		DockerLocal:     dockerLocal,
	}

	// We're going to try out a few settings and set DockerHost if
	// one of them works, it they don't we'll get a nice error when
	// requireDockerEndpoint triggers later on
	guessAndUpdateDockerOptions(speculativeOptions, e)
	return speculativeOptions, nil
}
示例#2
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
}