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

Adds environment & version to Deploy events #758

Merged
merged 8 commits into from
Feb 13, 2016
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* It's now possible to lock down the GitHub authorization to a specific team via the `--github.team.id` flag [#745](https://github.com/remind101/empire/pull/745).
* Empire can now integrate with Conveyor to build Docker images on demand when using the GitHub Deployments integration [#747](https://github.com/remind101/empire/pull/747).
* Stdout and Stdin from interactive run sessions can now be sent to CloudWatch Logs for longterm storage and auditing [#757](https://github.com/remind101/empire/pull/757).
* Add `Environment` and `Release` to Deploy Events. `--environment` will likely be used for tagging resource later. [#758](https://github.com/remind101/empire/pull/758)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, s/resource/resources/g


**Bugs**

Expand Down
1 change: 1 addition & 0 deletions cmd/empire/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func newEmpire(c *cli.Context) (*empire.Empire, error) {
e.EventStream = empire.AsyncEvents(events)
e.ExtractProcfile = empire.PullAndExtract(docker)
e.Logger = newLogger()
e.Environment = c.String(FlagEnvironment)
e.RunRecorder = runRecorder

return e, nil
Expand Down
8 changes: 8 additions & 0 deletions cmd/empire/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
FlagReporter = "reporter"
FlagRunner = "runner"
FlagLogsStreamer = "logs.streamer"

FlagEnvironment = "environment"
)

// Commands are the subcommands that are available.
Expand Down Expand Up @@ -287,6 +289,12 @@ var EmpireFlags = []cli.Flag{
Usage: "When using the SNS events backend, this is the SNS topic that gets published to",
EnvVar: "EMPIRE_SNS_TOPIC",
},
cli.StringFlag{
Name: FlagEnvironment,
Value: "",
Usage: "Used to distinguish the environment this Empire is used to manage. Used for tagging of resources and annotating events.",
EnvVar: "EMPIRE_ENVIRONMENT",
},
cli.StringFlag{
Name: FlagCloudWatchLogGroup,
Value: "",
Expand Down
4 changes: 4 additions & 0 deletions docs/cloudformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,10 @@
"Name": "AWS_REGION",
"Value": { "Ref": "AWS::Region" }
},
{
"Name": "EMPIRE_ENVIRONMENT",
"Value": "demo"
},
{
"Name": "EMPIRE_DATABASE_URL",
"Value": "postgres://postgres:postgres@postgres/postgres?sslmode=disable"
Expand Down
17 changes: 16 additions & 1 deletion empire.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ type Empire struct {
// from the newly deployed image.
ExtractProcfile ProcfileExtractor

// Environment represents the environment this Empire server is responsible for
Environment string

// EventStream service for publishing Empire events.
EventStream

Expand Down Expand Up @@ -451,6 +454,9 @@ type DeploymentsCreateOpts struct {
// Image is the image that's being deployed.
Image image.Image

// Environment is the environment where the image is being deployed
Environment string
Copy link
Contributor

Choose a reason for hiding this comment

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

This is probably ok for now, but it'd probably be better in the long run if we had this on the Empire struct itself, so it works for non-github deployments. If I emp deploy <image>, I'd still expect to see the environment in the event.

That means we'd need an --environment flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm - yeah, I guess actually taking the environment FROM the github deployment isn't actually all that useful. It's not like Empire runs multiple environments. Let me think about that - doesn't seem like it'd need to be super far reaching?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the initial version could just be used for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, took a first stab at addressing this. Let me know what you think.


// Output is an io.Writer where deployment output and events will be
// streamed in jsonmessage format.
Output io.Writer
Expand All @@ -464,6 +470,7 @@ func (opts DeploymentsCreateOpts) Event() DeployEvent {
if opts.App != nil {
e.App = opts.App.Name
}

return e
}

Expand All @@ -481,7 +488,15 @@ func (e *Empire) Deploy(ctx context.Context, opts DeploymentsCreateOpts) (*Relea
return r, err
}

return r, e.PublishEvent(opts.Event())
event := opts.Event()
event.Release = r.Version
event.Environment = e.Environment
// Deals with new app creation on first deploy
if event.App == "" && r.App != nil {
event.App = r.App.Name
}

return r, e.PublishEvent(event)
}

// ScaleOpts are options provided when scaling a process.
Expand Down
10 changes: 6 additions & 4 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ func (e ScaleEvent) String() string {

// DeployEvent is triggered when a user deploys a new image to an app.
type DeployEvent struct {
User string
App string
Image string
User string
App string
Image string
Environment string
Release int
}

func (e DeployEvent) Event() string {
Expand All @@ -84,7 +86,7 @@ func (e DeployEvent) String() string {
return fmt.Sprintf("%s deployed %s", e.User, e.Image)
}

return fmt.Sprintf("%s deployed %s to %s", e.User, e.Image, e.App)
return fmt.Sprintf("%s deployed %s to %s %s (v%d)", e.User, e.Image, e.App, e.Environment, e.Release)
}

// RollbackEvent is triggered when a user rolls back to an old version.
Expand Down
2 changes: 1 addition & 1 deletion events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestEvents_String(t *testing.T) {
{ScaleEvent{User: "ejholmes", App: "acme-inc", Process: "web", Quantity: 5, PreviousQuantity: 10}, "ejholmes scaled `web` on acme-inc from 10 to 5 (-5)"},

// DeployEvent
{DeployEvent{User: "ejholmes", App: "acme-inc", Image: "remind101/acme-inc:master"}, "ejholmes deployed remind101/acme-inc:master to acme-inc"},
{DeployEvent{User: "ejholmes", App: "acme-inc", Image: "remind101/acme-inc:master", Environment: "production", Release: 32}, "ejholmes deployed remind101/acme-inc:master to acme-inc production (v32)"},
{DeployEvent{User: "ejholmes", Image: "remind101/acme-inc:master"}, "ejholmes deployed remind101/acme-inc:master"},

// RollbackEvent
Expand Down