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

Show attached runs in emp ps. #911

Merged
merged 10 commits into from
Jul 11, 2016
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

**Features**

* Empire now includes experimental support for showing attached runs in `emp ps`. This can be enabled with the `--x.showattached` flag, or `EMPIRE_X_SHOW_ATTACHED` [#911](https://github.com/remind101/empire/pull/911)

**Improvements**

* The Custom::ECSService custom resource now waits for newly created ECS services to stabilize [#878](https://github.com/remind101/empire/pull/878)
Expand Down
31 changes: 13 additions & 18 deletions cmd/empire/factories.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
"github.com/remind101/empire/pkg/dockerauth"
"github.com/remind101/empire/pkg/dockerutil"
"github.com/remind101/empire/pkg/ecsutil"
"github.com/remind101/empire/pkg/runner"
"github.com/remind101/empire/scheduler"
"github.com/remind101/empire/scheduler/cloudformation"
"github.com/remind101/empire/scheduler/docker"
"github.com/remind101/empire/scheduler/ecs"
"github.com/remind101/pkg/logger"
"github.com/remind101/pkg/reporter"
Expand Down Expand Up @@ -104,12 +104,11 @@ func newEmpire(db *empire.DB, c *cli.Context) (*empire.Empire, error) {
// Scheduler ============================

func newScheduler(db *empire.DB, c *cli.Context) (scheduler.Scheduler, error) {
r, err := newDockerRunner(c)
if err != nil {
return nil, err
}
var (
s scheduler.Scheduler
err error
)

var s scheduler.Scheduler
switch c.String(FlagScheduler) {
case "ecs":
s, err = newECSScheduler(db, c)
Expand All @@ -125,10 +124,14 @@ func newScheduler(db *empire.DB, c *cli.Context) (scheduler.Scheduler, error) {
return nil, fmt.Errorf("failed to initialize %s scheduler: %v", c.String(FlagScheduler), err)
}

return &scheduler.AttachedRunner{
Scheduler: s,
Runner: r,
}, nil
d, err := newDockerClient(c)
if err != nil {
return nil, err
}

a := docker.RunAttachedWithDocker(s, d)
a.ShowAttached = c.Bool(FlagXShowAttached)
return a, nil
}

func newMigrationScheduler(db *empire.DB, c *cli.Context) (*cloudformation.MigrationScheduler, error) {
Expand Down Expand Up @@ -254,14 +257,6 @@ func newConfigProvider(c *cli.Context) client.ConfigProvider {
return p
}

func newDockerRunner(c *cli.Context) (*runner.Runner, error) {
client, err := newDockerClient(c)
if err != nil {
return nil, err
}
return runner.NewRunner(client), nil
}

// DockerClient ========================

func newDockerClient(c *cli.Context) (*dockerutil.Client, error) {
Expand Down
8 changes: 8 additions & 0 deletions cmd/empire/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const (
FlagLogsStreamer = "logs.streamer"

FlagEnvironment = "environment"

// Expiremental flags.
FlagXShowAttached = "x.showattached"
)

// Commands are the subcommands that are available.
Expand Down Expand Up @@ -326,6 +329,11 @@ var EmpireFlags = []cli.Flag{
Usage: "If true, messages will be required for empire actions that emit events.",
EnvVar: "EMPIRE_MESSAGES_REQUIRED",
},
cli.BoolFlag{
Name: FlagXShowAttached,
Usage: "If true, attached runs will be shown in `emp ps` output.",
EnvVar: "EMPIRE_X_SHOW_ATTACHED",
},
}

func main() {
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ server:
EMPIRE_DATABASE_URL: postgres://postgres:postgres@db/postgres?sslmode=disable
DOCKER_HOST: unix:///var/run/docker.sock
EMPIRE_SCHEDULER: cloudformation-migration
EMPIRE_X_SHOW_ATTACHED: 'true'
db:
image: postgres
ports:
Expand Down
4 changes: 4 additions & 0 deletions docs/cloudformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,10 @@
{
"Name": "EMPIRE_GITHUB_TEAM_ID",
"Value": { "Ref": "GitHubTeamId" }
},
{
"Name": "EMPIRE_X_SHOW_ATTACHED",
"Value": "true"
}
],
"Command": ["server", "-automigrate=true"],
Expand Down
170 changes: 0 additions & 170 deletions pkg/runner/runner.go

This file was deleted.

40 changes: 0 additions & 40 deletions pkg/runner/runner_test.go

This file was deleted.

4 changes: 2 additions & 2 deletions scheduler/cloudformation/cloudformation.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,10 @@ func (s *Scheduler) Services(appID string) (map[string]string, error) {
}

// Stop stops the given ECS task.
func (s *Scheduler) Stop(ctx context.Context, instanceID string) error {
func (s *Scheduler) Stop(ctx context.Context, taskID string) error {
_, err := s.ecs.StopTask(&ecs.StopTaskInput{
Cluster: aws.String(s.Cluster),
Task: aws.String(instanceID),
Task: aws.String(taskID),
})
return err
}
Expand Down
Loading