Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement golang bootstrapper #5399

Merged
merged 6 commits into from
Jun 20, 2017
Merged

Implement golang bootstrapper #5399

merged 6 commits into from
Jun 20, 2017

Conversation

voievodin
Copy link
Contributor

@voievodin voievodin commented Jun 19, 2017

Added golang app which implements bootstrapper spec(bootstrapper - agents workflow).

Usage

Usage of ./bootstrapper:
  -file string
        Path to configuration file on filesystem (default "/path/to/work/dir/config.json")
  -installer-timeout int
        Time(in seconds) given for one installer to complete its installation.
        If installation is not finished in time it will be interrupted (default 120)
  -machine-name string
        The name of the machine in which this bootstrapper is running
  -push-endpoint string
        WebSocket endpoint where to push statuses
  -push-logs-endpoint string
        WebSocket endpoint where to push logs
  -runtime-id string
        The identifier of the runtime in format 'workspace:environment:owner'
  -server-check-period int
        Time(in seconds) between servers availability checks.
        Once servers for one installer available - checks stopped 

Example

For the configuration file

[
  {
    "id": "exec",
    "description": "Agent for command execution",
    "version": "1.0",
    "script": "printf \"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\""
  },
  {
    "id": "agent",
    "description": "Agent",
    "version": "1.0",
    "script": "echo agent-007"
  },
  {
    "id": "agent-with-server",
    "description": "this is agent with server",
    "version": "1.0",
    "script": "set -e\ntdir\u003d$(mktemp -d)\ncd $tdir\nAGENT_TAR\u003dexec-agent-linux_amd64.tar.gz\nwget http://nightly.codenvy-stg.com/agent-binaries/linux_amd64/exec/${AGENT_TAR}\ntar -xzf ${AGENT_TAR}\n./exec-agent/che-exec-agent\n",
    "servers": {
      "exec": {
        "port": "9000/tcp",
        "protocol": "http"
      }
    }
  }
]

bootstrapper output will be

2017/06/19 11:17:00 Bootstrapper configuration
2017/06/19 11:17:00   Push endpoint: ws://localhost:2288/logging-server-connect
2017/06/19 11:17:00   Push logs endpoint: ws://localhost:2288/logging-server-connect
2017/06/19 11:17:00   Runtime ID:
2017/06/19 11:17:00     Workspace: workspace
2017/06/19 11:17:00     Environment: env
2017/06/19 11:17:00     Owner: owner
2017/06/19 11:17:00   Machine name: my-machine
2017/06/19 11:17:00   Installer timeout: 120seconds
2017/06/19 11:17:00   Check servers period: 3seconds
2017/06/19 11:17:00 Planning to install
2017/06/19 11:17:00 - exec:1.0 - Agent for command execution
2017/06/19 11:17:00 - agent:1.0 - Agent
2017/06/19 11:17:00 - agent-with-server:1.0 - this is agent with server
2017/06/19 11:17:00 Starting installations
2017/06/19 11:17:00 Installing 'exec'
2017/06/19 11:17:00 Installation of 'exec' successfully finished
2017/06/19 11:17:00 Installing 'agent'
2017/06/19 11:17:00 Installation of 'agent' successfully finished
2017/06/19 11:17:00 Installing 'agent-with-server'
2017/06/19 11:17:15 Installation of 'agent-with-server' successfully finished
2017/06/19 11:17:15 All installations successfully finished

During the installation corresponding events are emitted

Starting installations                                    <- bootstrapper/statusChanged { status : "STARTING" } 
Installing 'exec'                                         <- installer/statusChanged    { status : "STARTING" }
Installation of 'exec' successfully finished              <- installer/statusChanged    { status : "DONE" } 
Installing 'agent'                                        <- installer/statusChanged    { status : "STARTING" } 
Installation of 'agent' successfully finished             <- installer/statusChanged    { status : "DONE" } 
Installing 'agent-with-server'                            <- installer/statusChanged    { status : "STARTING" } 
Installation of 'agent-with-server' successfully finished <- installer/statusChanged    { status : "RUNNING" } 
All installations successfully finished                   <- bootstrapper/statusChanged { status : "DONE" } 

What issues does this PR fix or reference?

resolves #4099
spec - #4096 (comment)
new installation approach - #3971

Please note that these changes are going to be merged into SPI branch.

return fmt.Errorf("Port format is not supported %s", server.Port)
}
port := split[0]
addr := "localhost:" + port
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure localhost is always available?

@gazarenkov gazarenkov added the target/branch Indicates that a PR will be merged into a branch other than master. label Jun 19, 2017
@gazarenkov
Copy link
Contributor

Please specify what kind of events will be emitted during the sample bootstrapping
I think corresponding to this part of log:
2017/06/19 11:17:00 Starting installations
2017/06/19 11:17:00 Installing 'exec'
2017/06/19 11:17:00 Installation of 'exec' successfully finished
2017/06/19 11:17:00 Installing 'agent'
2017/06/19 11:17:00 Installation of 'agent' successfully finished
2017/06/19 11:17:00 Installing 'agent-with-server'
2017/06/19 11:17:15 Installation of 'agent-with-server' successfully finished
2017/06/19 11:17:15 All installations successfully finished

@voievodin
Copy link
Contributor Author

ok

<version>5.13.0-SNAPSHOT</version>
</parent>
<artifactId>bootstrapper</artifactId>
<name>Bootstrapper</name>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add more info into the artifact and name fields? E.g. agent-bootstrapper, Agent :: Bootstrapper

// AddAll adds batch of installers to the installation sequence.
func AddAll(installers []Installer) {
for _, installer := range installers {
Add(installer)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider append(installers, newInstallers...) instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

// If there is no installer which provides server, this func exits after
// all the installation are completed.
// In both cases if any error occurs during installation,
// start exists returning that error.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose exits instead of exists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

@codenvy-ci
Copy link

@codenvy-ci
Copy link

func (svi *serverInst) preCheck() error {
for _, server := range svi.installer.Servers {
if tryConn(server) == nil {
return fmt.Errorf("server address 'localhost:%s' already in use", server.Port)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that already running server is not a problem for an agent start. For example, ubuntu_jdk8 image start SSHD as the main command of the container. So with this check SSH agent will fail on that image.

return fmt.Errorf("Timeout reached before installation of '%s' finished", svi.installer.ID)
case <-diedC:
checker.stop()
return fmt.Errorf("Process of installation '%s' exited before server became available", svi.installer.ID)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose in case SSHD is already running, installation script exits immediately, so this error will occur even if the server is available. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that execution of scripts which install servers must not exit, but it turns out that
exitCode == 0 + servers availability should be considered as successful installation.
I will rework it, thank you!

@voievodin
Copy link
Contributor Author

@garagatyi fixed, please review changes

Copy link

@garagatyi garagatyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Good job!

@codenvy-ci
Copy link

@voievodin voievodin merged commit 7a0c1de into spi Jun 20, 2017
@voievodin voievodin deleted the bootstrapper branch June 20, 2017 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
target/branch Indicates that a PR will be merged into a branch other than master.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants