Repository: deis/deis

Issue:
Rollback fails to rollback to v1
If you create a project it starts at `v1`, then you push something to updated it to `v2`, when you roll back to `v1` it creates `v3`, only the process fails and there is no `v3` container to deploy. This starts and endless failure loop.

```
2014-12-02T17:00:36UTC deis[api]: hello: config hello-d176c15 updated
2014-12-02T17:00:36UTC deis[api]: hello: release hello-v1 created
2014-12-02T17:00:36UTC deis[api]: sirwolfgang created initial release
2014-12-02T17:00:46UTC deis[api]: hello: build hello-7c90f2f created
2014-12-02T17:00:46UTC deis[api]: hello: release hello-v2 created
2014-12-02T17:00:46UTC deis[api]: sirwolfgang deployed tutum/hello-world
2014-12-02T17:08:19UTC deis[api]: hello: release hello-v3 created
2014-12-02T17:08:19UTC deis[api]: sirwolfgang rolled back to v1
```

```
Dec 05 15:53:17 cloud1 systemd[1]: Starting hello_v3.cmd.3...
Dec 05 15:53:17 cloud1 docker[1637]: I1205 15:53:17.314810 00001 manager.go:428] Destroyed container: "/system.slice/hello_v3.cmd.3.service" (aliases: [], namespace: "")
Dec 05 15:53:17 cloud1 docker[1637]: I1205 15:53:17.321136 00001 manager.go:394] Added container: "/system.slice/hello_v3.cmd.3.service" (aliases: [], namespace: "")
Dec 05 15:53:17 cloud1 docker[1637]: I1205 15:53:17.322433 00001 container.go:141] Start housekeeping for container "/system.slice/hello_v3.cmd.3.service"
Dec 05 15:53:17 cloud1 docker[1637]: I1205 15:53:17.325184 00001 manager.go:394] Added container: "/system.slice/hello_v3.cmd.1.service" (aliases: [], namespace: "")
Dec 05 15:53:17 cloud1 docker[1637]: I1205 15:53:17.325212 00001 container.go:141] Start housekeeping for container "/system.slice/hello_v3.cmd.1.service"
Dec 05 15:53:17 cloud1 docker[727]: [info] POST /v1.15/images/create?fromImage=10.51.213.56%3A5000%2Fhello%3Av3
Dec 05 15:53:17 cloud1 docker[727]: [6c17bbb6] +job pull(10.51.213.56:5000/hello, v3)
Dec 05 15:53:17 cloud1 sh[1220]: time="2014-12-05T15:53:17Z" level="info" msg="10.51.213.54 - - [05/Dec/2014:15:53:17 +0000] \"HEAD / HTTP/1.1\" 200 0 \"-\" \"-\""
Dec 05 15:53:19 cloud1 sh[20983]: Pulling repository 10.51.213.56:5000/hello
Dec 05 15:53:19 cloud1 sh[1220]: time="2014-12-05T15:53:19Z" level="info" msg="10.51.213.54 - - [05/Dec/2014:15:53:19 +0000] \"HEAD / HTTP/1.1\" 200 0 \"-\" \"-\""
Dec 05 15:53:20 cloud1 sh[1298]: 2014-12-05 15:53:20.561195 7ff5d4986700  0 log_channel(cluster) log [INF] : pgmap v263205: 1536 pgs: 1536 active+undersized+degraded; 2832 MB data, 35493 MB used, 118 GB / 155 GB avail; 25993 B/s rd, 1637 B/s wr, 9 op/s; 4076/10131 objects degraded (40.233%)
Dec 05 15:53:20 cloud1 docker[727]: Tag v3 not found in repository 10.51.213.56:5000/hello
Dec 05 15:53:20 cloud1 sh[20983]: 2014/12/05 15:53:20 Tag v3 not found in repository 10.51.213.56:5000/hello
Dec 05 15:53:20 cloud1 docker[727]: [6c17bbb6] -job pull(10.51.213.56:5000/hello, v3) = ERR (1)
Dec 05 15:53:20 cloud1 systemd[1]: hello_v3.cmd.3.service: control process exited, code=exited status=1
Dec 05 15:53:20 cloud1 systemd[1]: Failed to start hello_v3.cmd.3.
Dec 05 15:53:20 cloud1 systemd[1]: Unit hello_v3.cmd.3.service entered failed state.
Dec 05 15:53:20 cloud1 systemd[1]: hello_v3.cmd.1.service holdoff time over, scheduling restart.
Dec 05 15:53:20 cloud1 systemd[1]: Stopping hello_v3.cmd.1...
```



Discussion:

Resolving patch:
diff --git a/controller/api/models.py b/controller/api/models.py
--- a/controller/api/models.py
+++ b/controller/api/models.py
@@ -401,15 +401,13 @@ def _get_scheduler(self):
     _scheduler = property(_get_scheduler)
 
     def _get_command(self):
-        # handle special case for Dockerfile deployments
-        if self.type == 'cmd':
-            return ''
         try:
             # ensure they cannot break out and run commands on the host
             return "bash -c '{}'".format(self.release.build.procfile[self.type])
         # if the key is not present or if a parent attribute is None
-        except (KeyError, TypeError):
-            return 'start {}'.format(self.type)
+        except (KeyError, TypeError, AttributeError):
+            # handle special case for Dockerfile deployments
+            return '' if self.type == 'cmd' else 'start {}'.format(self.type)
 
     _command = property(_get_command)
 


Test patch:
diff --git a/controller/api/tests/test_container.py b/controller/api/tests/test_container.py
--- a/controller/api/tests/test_container.py
+++ b/controller/api/tests/test_container.py
@@ -462,12 +462,15 @@ def test_command_good(self):
                                      type='web',
                                      num=1)
         self.assertEqual(c._command, "bash -c 'node server.js'")
+        c.type = 'cmd'
+        self.assertEqual(c._command, '')
+        # ensure we can override the cmd process type in a Procfile
+        build.procfile['cmd'] = 'node server.js'
+        self.assertEqual(c._command, "bash -c 'node server.js'")
         c.type = 'worker'
         self.assertEqual(c._command, "bash -c 'node worker.js'")
         c.release.build.procfile = None
         self.assertEqual(c._command, 'start worker')
-        c.type = 'cmd'
-        self.assertEqual(c._command, '')
 
     def test_run_command_good(self):
         """Test the run command for each container workflow"""