Skip to content

Commit

Permalink
run specific release
Browse files Browse the repository at this point in the history
allow users to run a command on a container for a given release

This allows user to build a release, then run commands such as
migrations then promote the release
  • Loading branch information
Drew Bowman authored and nzoschke committed Apr 8, 2016
1 parent 2394880 commit 1e6c63d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
6 changes: 4 additions & 2 deletions api/controllers/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ func ProcessRunDetached(rw http.ResponseWriter, r *http.Request) *httperr.Error
app := vars["app"]
process := vars["process"]
command := GetForm(r, "command")
release := GetForm(r, "release")

a, err := models.GetApp(app)

if awsError(err) == "ValidationError" {
return httperr.Errorf(404, "no such app: %s", app)
}

err = a.RunDetached(process, command)
err = a.RunDetached(process, command, release)

if err != nil {
return httperr.Server(err)
Expand All @@ -138,6 +139,7 @@ func ProcessRunAttached(ws *websocket.Conn) *httperr.Error {
app := vars["app"]
process := vars["process"]
command := header.Get("Command")
release := header.Get("Release")
height, _ := strconv.Atoi(header.Get("Height"))
width, _ := strconv.Atoi(header.Get("Width"))

Expand All @@ -151,7 +153,7 @@ func ProcessRunAttached(ws *websocket.Conn) *httperr.Error {
return httperr.Server(err)
}

return httperr.Server(a.RunAttached(process, command, height, width, ws))
return httperr.Server(a.RunAttached(process, command, release, height, width, ws))
}

func ProcessStop(rw http.ResponseWriter, r *http.Request) *httperr.Error {
Expand Down
10 changes: 7 additions & 3 deletions api/models/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func (a *App) ExecAttached(pid, command string, height, width int, rw io.ReadWri
return nil
}

func (a *App) RunAttached(process, command string, height, width int, rw io.ReadWriter) error {
func (a *App) RunAttached(process, command, releaseId string, height, width int, rw io.ReadWriter) error {
resources, err := a.Resources()

if err != nil {
Expand Down Expand Up @@ -499,7 +499,11 @@ func (a *App) RunAttached(process, command string, height, width int, rw io.Read
ea = append(ea, fmt.Sprintf("%s=%s", *env.Name, *env.Value))
}

release, err := GetRelease(a.Name, a.Release)
if len(releaseId) == 0 {
releaseId = a.Release
}

release, err := GetRelease(a.Name, releaseId)

if err != nil {
return err
Expand Down Expand Up @@ -668,7 +672,7 @@ func (a *App) RunAttached(process, command string, height, width int, rw io.Read
return nil
}

func (a *App) RunDetached(process, command string) error {
func (a *App) RunDetached(process, command, releaseId string) error {
resources, err := a.Resources()

if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions client/processes.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *Client) ExecProcessAttached(app, pid, command string, in io.Reader, out
return code, nil
}

func (c *Client) RunProcessAttached(app, process, command string, height, width int, in io.Reader, out io.WriteCloser) (int, error) {
func (c *Client) RunProcessAttached(app, process, command, release string, height, width int, in io.Reader, out io.WriteCloser) (int, error) {
r, w := io.Pipe()

defer r.Close()
Expand All @@ -91,6 +91,7 @@ func (c *Client) RunProcessAttached(app, process, command string, height, width

headers := map[string]string{
"Command": command,
"Release": release,
"Height": strconv.Itoa(height),
"Width": strconv.Itoa(width),
}
Expand All @@ -106,11 +107,12 @@ func (c *Client) RunProcessAttached(app, process, command string, height, width
return code, nil
}

func (c *Client) RunProcessDetached(app, process, command string) error {
func (c *Client) RunProcessDetached(app, process, command, release string) error {
var success interface{}

params := map[string]string{
"command": command,
"release": release,
}

err := c.Post(fmt.Sprintf("/apps/%s/processes/%s/run", app, process), params, &success)
Expand Down
16 changes: 12 additions & 4 deletions cmd/convox/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func init() {
Name: "detach",
Usage: "run in the background",
},
cli.StringFlag{
Name: "release, r",
Usage: "Release Name. Defaults to current release.",
},
},
})
}
Expand All @@ -50,7 +54,9 @@ func cmdRun(c *cli.Context) {

args := strings.Join(c.Args()[1:], " ")

code, err := runAttached(c, app, ps, args)
release := c.String("release")

code, err := runAttached(c, app, ps, args, release)

if err != nil {
stdcli.Error(err)
Expand Down Expand Up @@ -82,9 +88,11 @@ func cmdRunDetached(c *cli.Context) {
command = strings.Join(args, " ")
}

release := c.String("release")

fmt.Printf("Running `%s` on %s... ", command, ps)

err = rackClient(c).RunProcessDetached(app, ps, command)
err = rackClient(c).RunProcessDetached(app, ps, command, release)

if err != nil {
stdcli.Error(err)
Expand All @@ -94,7 +102,7 @@ func cmdRunDetached(c *cli.Context) {
fmt.Println("OK")
}

func runAttached(c *cli.Context, app string, ps string, args string) (int, error) {
func runAttached(c *cli.Context, app, ps, args, release string) (int, error) {
fd := os.Stdin.Fd()

if terminal.IsTerminal(int(fd)) {
Expand All @@ -113,7 +121,7 @@ func runAttached(c *cli.Context, app string, ps string, args string) (int, error
return -1, err
}

code, err := rackClient(c).RunProcessAttached(app, ps, args, h, w, os.Stdin, os.Stdout)
code, err := rackClient(c).RunProcessAttached(app, ps, args, release, h, w, os.Stdin, os.Stdout)

if err != nil {
return -1, err
Expand Down

0 comments on commit 1e6c63d

Please sign in to comment.