Skip to content

Commit

Permalink
config: hack in an ignore-death option (#608)
Browse files Browse the repository at this point in the history
for #607
  • Loading branch information
bobheadxi authored Mar 17, 2019
1 parent d755488 commit 176cb3d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 33 deletions.
13 changes: 7 additions & 6 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ const (

// UpRequest is the configurable body of a UP request to the daemon.
type UpRequest struct {
Stream bool `json:"stream"`
Project string `json:"project"`
BuildType string `json:"build_type"`
BuildFilePath string `json:"build_file_path"`
GitOptions GitOptions `json:"git_options"`
WebHookSecret string `json:"webhook_secret"`
Stream bool `json:"stream"`
Project string `json:"project"`
BuildType string `json:"build_type"`
BuildFilePath string `json:"build_file_path"`
GitOptions GitOptions `json:"git_options"`
WebHookSecret string `json:"webhook_secret"`
DontKillOnDeath bool `json:"dont_kill_on_death"`
}

// GitOptions represents GitHub-related deployment options
Expand Down
15 changes: 8 additions & 7 deletions cfg/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cfg

// RemoteVPS contains parameters for the VPS
type RemoteVPS struct {
Name string `toml:"name"`
IP string `toml:"IP"`
User string `toml:"user"`
PEM string `toml:"pemfile"`
Branch string `toml:"branch"`
SSHPort string `toml:"ssh-port"`
Daemon *DaemonConfig `toml:"daemon"`
Name string `toml:"name"`
IP string `toml:"IP"`
User string `toml:"user"`
PEM string `toml:"pemfile"`
Branch string `toml:"branch"`
SSHPort string `toml:"ssh-port"`
Daemon *DaemonConfig `toml:"daemon"`
DontKillOnDeath *bool `toml:"no-kill-on-death"`
}

// DaemonConfig contains parameters for the Daemon
Expand Down
8 changes: 7 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,16 @@ func (c *Client) getDaemonAPIToken(session SSHSession, daemonVersion string) (st

// Up brings the project up on the remote VPS instance specified
// in the deployment object.
func (c *Client) Up(gitRemoteURL, buildType string, stream bool) (*http.Response, error) {
func (c *Client) Up(gitRemoteURL, buildType string, stream bool, dontKillOnDeath ...bool) (*http.Response, error) {
if buildType == "" {
buildType = c.buildType
}

var dkod bool
if len(dontKillOnDeath) > 0 {
dkod = dontKillOnDeath[0]
}

return c.post("/up", &api.UpRequest{
Stream: stream,
Project: c.project,
Expand All @@ -240,6 +245,7 @@ func (c *Client) Up(gitRemoteURL, buildType string, stream bool) (*http.Response
RemoteURL: common.GetSSHRemoteURL(gitRemoteURL),
Branch: c.Branch,
},
DontKillOnDeath: dkod,
})
}

Expand Down
7 changes: 6 additions & 1 deletion cmd/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ This requires an Inertia daemon to be active on your remote - do this by running
printutil.Fatal(err)
}

resp, err := root.client.Up(url, buildType, !short)
var dkod bool
if root.client.RemoteVPS.DontKillOnDeath != nil {
dkod = *root.client.RemoteVPS.DontKillOnDeath
}

resp, err := root.client.Up(url, buildType, !short, dkod)
if err != nil {
printutil.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions daemon/inertiad/daemon/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ func (s *Server) upHandler(w http.ResponseWriter, r *http.Request) {

// Change deployment parameters if necessary
s.deployment.SetConfig(project.DeploymentConfig{
ProjectName: upReq.Project,
Branch: gitOpts.Branch,
ProjectName: upReq.Project,
Branch: gitOpts.Branch,
DontKillOnDeath: upReq.DontKillOnDeath,
})

// Deploy project
Expand Down
39 changes: 23 additions & 16 deletions daemon/inertiad/project/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ type Deployment struct {
active bool
directory string

project string
branch string
buildType string
buildFilePath string
project string
branch string
buildType string
buildFilePath string
dontKillOnDeath bool

builder build.ContainerBuilder

Expand All @@ -62,12 +63,13 @@ type Deployment struct {

// DeploymentConfig is used to configure Deployment
type DeploymentConfig struct {
ProjectName string
BuildType string
BuildFilePath string
RemoteURL string
Branch string
PemFilePath string
ProjectName string
BuildType string
BuildFilePath string
RemoteURL string
Branch string
PemFilePath string
DontKillOnDeath bool
}

// NewDeployment creates a new deployment
Expand Down Expand Up @@ -137,6 +139,7 @@ func (d *Deployment) SetConfig(cfg DeploymentConfig) {
if cfg.BuildFilePath != "" {
d.buildFilePath = cfg.BuildFilePath
}
d.dontKillOnDeath = cfg.DontKillOnDeath
}

// DeployOptions is used to configure how the deployment handles the deploy
Expand Down Expand Up @@ -376,12 +379,16 @@ func (d *Deployment) Watch(client *docker.Client) (<-chan string, <-chan error)
}

if d.active {
// Shut down all containers if one stops while project is active
d.active = false
logsCh <- "container stoppage was unexpected, project is active"
err := containers.StopActiveContainers(client, os.Stdout)
if err != nil {
logsCh <- ("error shutting down other active containers: " + err.Error())
if !d.dontKillOnDeath {
// Shut down all containers if one stops while project is active
d.active = false
logsCh <- "container stoppage was unexpected, project is active"
err := containers.StopActiveContainers(client, os.Stdout)
if err != nil {
logsCh <- ("error shutting down other active containers: " + err.Error())
}
} else {
logsCh <- "ignoring container stoppage because dontKillOnDeath is set to true"
}
}
}
Expand Down

0 comments on commit 176cb3d

Please sign in to comment.