Skip to content

Commit

Permalink
cmd(config): intermediary containers (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Mar 5, 2020
1 parent d65708d commit 9c8cc3c
Show file tree
Hide file tree
Showing 23 changed files with 568 additions and 294 deletions.
14 changes: 8 additions & 6 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ const (
)

// UpRequest is the configurable body of a UP request to the daemon.
// TODO: unify with configuration definitions
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"`
IntermediaryContainers []string `json:"intermediary_containers"`
}

// GitOptions represents GitHub-related deployment options
Expand Down
2 changes: 2 additions & 0 deletions cfg/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func AsBuildType(s string) (BuildType, error) {
type Build struct {
Type BuildType `toml:"type"`
BuildFilePath string `toml:"buildfile"`

IntermediaryContainers []string `toml:"intermediary_containers"`
}

// NewProject sets up Inertia configuration with given properties
Expand Down
1 change: 1 addition & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (c *Client) Up(ctx context.Context, req UpRequest) error {
RemoteURL: common.GetSSHRemoteURL(req.URL),
Branch: req.Profile.Branch,
},
IntermediaryContainers: req.Profile.Build.IntermediaryContainers,
})
if err != nil {
return fmt.Errorf("failed to make request: %s", err.Error())
Expand Down
11 changes: 6 additions & 5 deletions daemon/inertiad/daemon/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ func (s *Server) upHandler(w http.ResponseWriter, r *http.Request) {
// apply configuration updates
s.state.WebhookSecret = upReq.WebHookSecret
s.deployment.SetConfig(project.DeploymentConfig{
ProjectName: upReq.Project,
BuildType: upReq.BuildType,
BuildFilePath: upReq.BuildFilePath,
RemoteURL: gitOpts.RemoteURL,
Branch: gitOpts.Branch,
ProjectName: upReq.Project,
BuildType: upReq.BuildType,
BuildFilePath: upReq.BuildFilePath,
RemoteURL: gitOpts.RemoteURL,
Branch: gitOpts.Branch,
IntermediaryContainers: upReq.IntermediaryContainers,
})

// Configure streamer
Expand Down
53 changes: 36 additions & 17 deletions daemon/inertiad/project/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ type Deployment struct {
active bool
directory string

project string
branch string
buildType string
buildFilePath string
project string
branch string
buildType string
buildFilePath string
intermediaryContainers []string

builder build.ContainerBuilder

Expand All @@ -68,12 +69,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
IntermediaryContainers []string
}

// DeploymentMetadata is used to store metadata relevant
Expand Down Expand Up @@ -152,6 +154,7 @@ func (d *Deployment) SetConfig(cfg DeploymentConfig) {
if cfg.BuildFilePath != "" {
d.buildFilePath = cfg.BuildFilePath
}
d.intermediaryContainers = cfg.IntermediaryContainers

// TODO: register notifiers
}
Expand Down Expand Up @@ -451,23 +454,39 @@ func (d *Deployment) Watch(client *docker.Client) (<-chan string, <-chan error)
}

case status := <-eventsCh:
var containerName string
if status.Actor.Attributes != nil {
logsCh <- fmt.Sprintf("container %s (%s) has stopped", status.Actor.Attributes["name"], status.ID[:11])
containerName = status.Actor.Attributes["name"]
}

if containerName != "" {
logsCh <- fmt.Sprintf("container %s (%s) has stopped", containerName, status.ID[:11])
} else {
logsCh <- fmt.Sprintf("container %s has stopped", status.ID[:11])
}

if d.active {
// Check if we should ignore this container's death
var ignore bool
if len(d.intermediaryContainers) > 0 && containerName == "" {
for _, c := range d.intermediaryContainers {
if containerName == c {
ignore = true
}
}
}

// 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 !ignore {
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())
}
}
}
}

}
}()

Expand Down
539 changes: 284 additions & 255 deletions docs/tip/api/index.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/tip/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ For a more general usage guide, refer to the [Inertia Usage Guide](https://inert

For documentation regarding the daemon API, refer to the [API Reference](https://inertia.ubclaunchpad.com/api).

* Generated: 2019-Oct-06
* Version: v0.6.0-preview1-11-gbc4bb8e
* Generated: 2020-Mar-04
* Version: v0.6.0-preview2-6-g729e2dc
2 changes: 1 addition & 1 deletion docs/tip/cli/inertia_remote_upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ inertia remote upgrade dev staging
```
--all upgrade all remotes
-h, --help help for upgrade
--version string specify Inertia daemon version to set (default "v0.6.0-preview1-11-gbc4bb8e")
--version string specify Inertia daemon version to set (default "v0.6.0-preview2-6-g729e2dc")
```

### Options inherited from parent commands
Expand Down
Binary file added docs/tip/fonts/slate-33847ce5.woff
Binary file not shown.
Binary file added docs/tip/fonts/slate-7b7da4fe.ttf
Binary file not shown.
Binary file added docs/tip/fonts/slate-cfc9d06b.eot
Binary file not shown.
Binary file added docs/tip/fonts/slate-ddd488db.woff2
Binary file not shown.
14 changes: 14 additions & 0 deletions docs/tip/fonts/slate-e55b8307.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tip/images/aws-ec2-iam-add-acf0227b.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tip/images/aws-ec2-iam-perm-408741e4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tip/images/logo-a410de0a.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/tip/images/navbar-cad8cdcb.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 28 additions & 8 deletions docs/tip/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,20 @@
color: #f92672;
}
</style>
<link href="stylesheets/screen.css" rel="stylesheet" media="screen" />
<link href="stylesheets/print.css" rel="stylesheet" media="print" />
<script src="javascripts/all_nosearch.js"></script>
<link href="stylesheets/screen-af868d8f.css" rel="stylesheet" media="screen" />
<link href="stylesheets/print-4373c1b9.css" rel="stylesheet" media="print" />
<script src="javascripts/all_nosearch-c275c2f6.js"></script>
</head>

<body class="index" data-languages="[]">
<a href="#" id="nav-button">
<span>
NAV
<img src="images/navbar.png" alt="Navbar" />
<img src="images/navbar-cad8cdcb.png" alt="Navbar" />
</span>
</a>
<div class="toc-wrapper">
<img src="images/logo.png" class="logo" alt="Logo" />
<img src="images/logo-a410de0a.png" class="logo" alt="Logo" />
<ul id="toc" class="toc-list-h1">
<li>
<a href="#inertia" class="toc-h1 toc-link" data-title="Inertia">Inertia</a>
Expand Down Expand Up @@ -292,6 +292,9 @@
<li>
<a href="#custom-ssl-certificate" class="toc-h2 toc-link" data-title="Custom SSL Certificate">Custom SSL Certificate</a>
</li>
<li>
<a href="#intermediary-containers" class="toc-h2 toc-link" data-title="Intermediary Containers">Intermediary Containers</a>
</li>
</ul>
</li>
<li>
Expand Down Expand Up @@ -558,7 +561,7 @@ <h3 id='example-provisioning-an-ec2-instance'>Example: Provisioning an EC2 Insta

<blockquote>
<p>The IAM users page:
<img src="images/aws-ec2-iam-add.png" alt="Aws ec2 iam add" /></p>
<img src="images/aws-ec2-iam-add-acf0227b.png" alt="Aws ec2 iam add" /></p>
</blockquote>

<p>To get started, make an account on the <a href="aws.amazon.com">AWS website</a>. If you&#39;re
Expand All @@ -574,7 +577,7 @@ <h3 id='example-provisioning-an-ec2-instance'>Example: Provisioning an EC2 Insta

<blockquote>
<p>Configuring IAM permissions:
<img src="images/aws-ec2-iam-perm.png" alt="Aws ec2 iam perm" /></p>
<img src="images/aws-ec2-iam-perm-408741e4.png" alt="Aws ec2 iam perm" /></p>
</blockquote>

<p>This will take you through a brief walkthrough to configure your new IAM user:</p>
Expand Down Expand Up @@ -1042,7 +1045,24 @@ <h2 id='custom-ssl-certificate'>Custom SSL Certificate</h2>
<p>Just place your SSL certificate and key on your remote in <code>~/.inertia/ssl</code> as
<code>daemon.cert</code> and <code>daemon.key</code> respectively, and the Inertia daemon will use
them automatically.</p>
<h1 id='miscellaneous'>Miscellaneous</h1><h2 id='learn-more'>Learn More</h2>
<h2 id='intermediary-containers'>Intermediary Containers</h2>
<aside class="warning">
This is an experimental solution to a problem we've run into - refer to
<a href="https://github.com/ubclaunchpad/inertia/issues/607">#607</a> for more details.
</aside>

<p>You can declare intermediary containers used during builds that don&#39;t persist for the lifetime of
your project - for example, containers that run tasks. This tells the Inertia daemon not to worry
if it detects that containers with the given names die.</p>
<pre class="highlight toml tab-toml"><code><span class="py">name</span> <span class="p">=</span> <span class="s">"my_project"</span>
<span class="c"># ...</span>

<span class="nn">[[profile]]</span>
<span class="c"># ...</span>
<span class="nn">[profile.build]</span>
<span class="c"># ...</span>
<span class="py">intermediary_containers</span> <span class="p">=</span> <span class="p">[</span> <span class="s">"nginx"</span> <span class="p">]</span>
</code></pre><h1 id='miscellaneous'>Miscellaneous</h1><h2 id='learn-more'>Learn More</h2>
<blockquote>
<p>Some quick links to help you get started:</p>

Expand Down
131 changes: 131 additions & 0 deletions docs/tip/javascripts/all-c5541673.js

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions docs/tip/javascripts/all_nosearch-c275c2f6.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/tip/stylesheets/print-4373c1b9.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9c8cc3c

Please sign in to comment.