Beispiel #1
0
func setupAgentFromCli(c *cli.Context, command string) *buildbox.Agent {
	// Init debugging
	if c.Bool("debug") {
		buildbox.LoggerInitDebug()
	}

	agentAccessToken := c.String("access-token")

	// Should we look to the environment for the agent access token?
	if agentAccessToken == AgentAccessTokenDefault {
		agentAccessToken = os.Getenv(AgentAccessTokenEnv)
	}

	if agentAccessToken == "" {
		fmt.Println("buildbox-agent: missing agent access token\nSee 'buildbox-agent start --help'")
		os.Exit(1)
	}

	bootstrapScript := c.String("bootstrap-script")

	// Expand the envionment variable.
	if bootstrapScript == BootstrapScriptDefault {
		bootstrapScript = os.ExpandEnv(bootstrapScript)
	}

	// Make sure the boostrap script exists.
	if _, err := os.Stat(bootstrapScript); os.IsNotExist(err) {
		print("buildbox-agent: no such file " + bootstrapScript + "\n")
		os.Exit(1)
	}

	// Set the agent options
	var agent buildbox.Agent
	agent.BootstrapScript = bootstrapScript

	// Client specific options
	agent.Client.AgentAccessToken = agentAccessToken
	agent.Client.URL = c.String("url")

	// Setup the agent
	agent.Setup()

	// A nice welcome message
	buildbox.Logger.WithFields(logrus.Fields{
		"pid":     os.Getpid(),
		"version": buildbox.Version,
	}).Infof("Started buildbox-agent `%s`", agent.Name)

	return &agent
}
Beispiel #2
0
func setupAgent(command string, agentAccessToken string, bootstrapScript string, url string) *buildbox.Agent {
	// Should we look to the environment for the agent access token?
	if agentAccessToken == AgentAccessTokenDefault {
		agentAccessToken = os.Getenv(AgentAccessTokenEnv)
	}

	if agentAccessToken == "" {
		fmt.Println("buildbox-agent: missing agent access token\nSee 'buildbox-agent " + command + " --help'")
		os.Exit(1)
	}

	// Expand the envionment variable.
	if bootstrapScript == BootstrapScriptDefault {
		bootstrapScript = os.ExpandEnv(bootstrapScript)
	}

	// Make sure the boostrap script exists.
	if _, err := os.Stat(bootstrapScript); os.IsNotExist(err) {
		print("buildbox-agent: no such file " + bootstrapScript + "\n")
		os.Exit(1)
	}

	// Set the agent options
	var agent buildbox.Agent
	agent.BootstrapScript = bootstrapScript

	// Client specific options
	agent.Client.AuthorizationToken = agentAccessToken
	agent.Client.URL = url

	// Setup the agent
	agent.Setup()

	// A nice welcome message
	buildbox.Logger.WithFields(logrus.Fields{
		"pid":     os.Getpid(),
		"version": buildbox.Version,
	}).Infof("Started buildbox-agent `%s`", agent.Name)

	return &agent
}