Repository: deis/deis

Issue:
`deis run` generates 500 error
[Integration tests](http://ci.deis.io/view/example-apps/job/test-integration-clojure-ring/47/console) against master found an error in `deis run`:

```
=== appssample Domains
No domains


ok
/home/jenkins/workspace/test-integration-clojure-ring/src/github.com/deis/deis/tests/example-clojure-ring
apps:run echo hello

500 INTERNAL SERVER ERROR
<h1>Server Error (500)</h1>

error at command wait
--- FAIL: TestApps (76.15 seconds)
    itutils.go:199: Failed:
        exit status 1
FAIL
exit status 1
```



Discussion:
Stack trace:

``` python
[2014-08-06 09:29:06,804: ERROR/MainProcess] Task api.tasks.run_command[3fecff9c-daa8-4994-a24f-99ceaeda2f50] raised unexpected: KeyError(u'pull_image',)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 437, in __protected_call__
    return self.run(*args, **kwargs)
  File "/app/api/tasks.py", line 87, in run_command
    raise EnvironmentError('Could not pull image: {pull_image}'.format(**locals()))
KeyError: u'pull_image'
ERROR Internal Server Error: /api/apps/appssample/run
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 112, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/viewsets.py", line 78, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/csrf.py", line 57, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py", line 400, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python2.7/dist-packages/rest_framework/views.py", line 397, in dispatch
    response = handler(request, *args, **kwargs)
  File "/app/api/views.py", line 311, in run
    output_and_rc = app.run(command)
  File "/app/api/models.py", line 233, in run
    rc, output = tasks.run_command.delay(c, command).get()
  File "/usr/local/lib/python2.7/dist-packages/celery/result.py", line 169, in get
    no_ack=no_ack,
  File "/usr/local/lib/python2.7/dist-packages/celery/backends/base.py", line 215, in wait_for
    raise result
KeyError: u'pull_image'
```

Shout out to @smothiki: your integration tests caught a major bug as soon as they were put into service. Nice work!

`apps:run` is failing here: https://github.com/deis/deis/blob/master/controller/api/tasks.py#L85

Since the change in #1325, we no longer reference the IP address/port of the container. We'll need to pull it from settings.REGISTRY_HOST and settings.REGISTRY_PORT.


Resolving patch:
diff --git a/controller/api/tasks.py b/controller/api/tasks.py
--- a/controller/api/tasks.py
+++ b/controller/api/tasks.py
@@ -79,12 +79,14 @@ def stop_containers(containers):
 def run_command(c, command):
     release = c.release
     version = release.version
-    image = release.image
+    image = '{}:{}/{}'.format(settings.REGISTRY_HOST,
+                              settings.REGISTRY_PORT,
+                              release.image)
     try:
         # pull the image first
         rc, pull_output = c.run("docker pull {image}".format(**locals()))
         if rc != 0:
-            raise EnvironmentError('Could not pull image: {pull_image}'.format(**locals()))
+            raise EnvironmentError('Could not pull image: {image}'.format(**locals()))
         # run the command
         docker_args = ' '.join(['--entrypoint=/bin/sh',
                                 '-a', 'stdout', '-a', 'stderr', '--rm', image])


Test patch: