From 176cb3dec018bd65fe04b9e472d51aa2c05933fa Mon Sep 17 00:00:00 2001 From: Robert Lin Date: Sun, 17 Mar 2019 15:40:29 -0700 Subject: [PATCH] config: hack in an ignore-death option (#608) for #607 --- api/api.go | 13 ++++----- cfg/remote.go | 15 ++++++----- client/client.go | 8 +++++- cmd/host/host.go | 7 ++++- daemon/inertiad/daemon/up.go | 5 ++-- daemon/inertiad/project/deployment.go | 39 ++++++++++++++++----------- 6 files changed, 54 insertions(+), 33 deletions(-) diff --git a/api/api.go b/api/api.go index 5859ef88..63ff2c21 100644 --- a/api/api.go +++ b/api/api.go @@ -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 diff --git a/cfg/remote.go b/cfg/remote.go index 62adb75d..0a58ef61 100644 --- a/cfg/remote.go +++ b/cfg/remote.go @@ -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 diff --git a/client/client.go b/client/client.go index f0857224..9ed82c2d 100644 --- a/client/client.go +++ b/client/client.go @@ -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, @@ -240,6 +245,7 @@ func (c *Client) Up(gitRemoteURL, buildType string, stream bool) (*http.Response RemoteURL: common.GetSSHRemoteURL(gitRemoteURL), Branch: c.Branch, }, + DontKillOnDeath: dkod, }) } diff --git a/cmd/host/host.go b/cmd/host/host.go index c33ec127..0c613692 100644 --- a/cmd/host/host.go +++ b/cmd/host/host.go @@ -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) } diff --git a/daemon/inertiad/daemon/up.go b/daemon/inertiad/daemon/up.go index 08b8228d..e443a6a2 100644 --- a/daemon/inertiad/daemon/up.go +++ b/daemon/inertiad/daemon/up.go @@ -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 diff --git a/daemon/inertiad/project/deployment.go b/daemon/inertiad/project/deployment.go index 6c7527e9..f266aa06 100644 --- a/daemon/inertiad/project/deployment.go +++ b/daemon/inertiad/project/deployment.go @@ -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 @@ -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 @@ -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 @@ -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" } } }