# How to redeploy ray-serve app

**URL:** <https://discuss.ray.io/t/how-to-redeploy-ray-serve-app/12701>\
**Category:** Ray Serve\
**Created:** [November 3, 2023, 7:28pm UTC](https://discuss.ray.io/t/how-to-redeploy-ray-serve-app/12701 "2023-11-03T19:28:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jacob\_Summers](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jacob_summers/32/5278_2.png) [@Jacob\_Summers](https://discuss.ray.io/u/Jacob_Summers)\
**Post date:** [November 3, 2023, 7:28pm UTC](https://discuss.ray.io/t/how-to-redeploy-ray-serve-app/12701/1 "2023-11-03T19:28:52Z")

</div>

**How severe does this issue affect your experience of using Ray?**

- Medium: It contributes to significant difficulty to complete my task, but I can work around it.

I am deploying my app like this:

```auto
# Start Ray
ray start --head --dashboard-host=0.0.0.0

# Deploy my app (Ray Serve)
serve deploy my_app.yaml

```

How do I re-deploy my app? I tried:

```auto
serve deploy my_app.yaml

```

But this doesn’t deploy the latest code…? (See image)

Is there a way to undeploy? Something like serve UNdeploy my\_app.yaml?

 ![foo](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/a/ae0f2c48a6a2a4bc53747608245061810300c31d.png)

* * *

_Cross posted in slack: [Slack](https://ray-distributed.slack.com/archives/CNCKBBRJL/p1699039452415789)_

---

<div class="post-metadata">

**Author:** ![Jacob\_Summers](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jacob_summers/32/5278_2.png) [@Jacob\_Summers](https://discuss.ray.io/u/Jacob_Summers)\
**Post date:** [November 3, 2023, 7:42pm UTC](https://discuss.ray.io/t/how-to-redeploy-ray-serve-app/12701/2 "2023-11-03T19:42:04Z")

</div>

More info

When I run the:`serve deploy my_app.yaml`, I can see some state change in the dashboard but it looks like the new code is not loaded:

 ![bar](https://us1.discourse-cdn.com/flex020/uploads/ray/original/2X/4/43ea50d8556618bb4ad42936a6b00a8f26491d7a.jpeg)

---

<div class="post-metadata">

**Author:** ![shrekris](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@shrekris](https://discuss.ray.io/u/shrekris)\
**Post date:** [November 3, 2023, 11:53pm UTC](https://discuss.ray.io/t/how-to-redeploy-ray-serve-app/12701/3 "2023-11-03T23:53:43Z")

</div>

What does your Serve config look like?

If the Serve config’s `runtime_env` or `import_path` doesn’t change between the `serve deploy` calls, then the app won’t be redeployed because Serve won’t detect a code change. One workaround is to add an env var to the `runtime_env` and change it between deploys to force the `runtime_env` to reinstall.

In general though, the `runtime_env` should change when there’s a code change. This guards against version inconsistencies across nodes. See [the warning in this docs section](https://docs.ray.io/en/releases-2.8.0/ray-core/handling-dependencies.html#option-1-download-zip-quicker-to-implement-but-not-recommended-for-production-environments) to learn more.

---

<div class="post-metadata">

**Author:** ![Jacob\_Summers](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jacob_summers/32/5278_2.png) [@Jacob\_Summers](https://discuss.ray.io/u/Jacob_Summers)\
**Post date:** [November 4, 2023, 2:56am UTC](https://discuss.ray.io/t/how-to-redeploy-ray-serve-app/12701/4 "2023-11-04T02:56:54Z")

</div>

[shrekris](https://discuss.ray.io/u/shrekris)

> What does your Serve config look like?

Something like this:

```auto
proxy_location: EveryNode
http_options:
  host: 0.0.0.0
  port: 9631
applications:
  - name: my_app
    route_prefix: /my_app
    import_path: my_stuff.apps:app
    runtime_env: {}
    deployments:
      - name: ThingOne
      - name: ThingTwo

```

I am including my code & my dependencies using a custom docker image, like this:

```auto
FROM rayproject/ray:latest-py310-gpu
USER root

# Poetry
RUN curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.5.1 python3 -
ENV PATH="${PATH}:${HOME}/.local/bin:/root/.local/bin"
RUN poetry config virtualenvs.create false

WORKDIR /app

# Copy my code & requirements
COPY . /app

# Because we want to install korok itself
RUN poetry install -n --with dev,tf

```

This means that generally my ray-config stays pretty static.

* * *

The workaround that I have been using is to redeploy using:

```auto
serve shutdown --yes
serve deploy my_app.yaml

```

---

<div class="post-metadata">

**Author:** ![cindy\_zhang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/cindy_zhang/32/3559_2.png) [@cindy\_zhang](https://discuss.ray.io/u/cindy_zhang)\
**Post date:** [November 6, 2023, 7:26pm UTC](https://discuss.ray.io/t/how-to-redeploy-ray-serve-app/12701/5 "2023-11-06T19:26:14Z")

</div>

Hi @Jacob_Summers, like Shreyas mentioned if `runtime_env`, `import_path`, or `args` doesn’t change, the code won’t be reloaded. This is because Serve supports [lightweight config updates](https://docs.ray.io/en/latest/serve/advanced-guides/inplace-updates.html), which allow you to update configuration values in-place without having to tear down and restart your application. Also, in a production setting, we typically expect the runtime env to change if your code has changed.

One workaround for your use case is to set an environment variable in your [runtime env](https://docs.ray.io/en/latest/ray-core/handling-dependencies.html#api-reference), and modify it each time you want to reload your code, e.g:

```auto
proxy_location: EveryNode
http_options:
  host: 0.0.0.0
  port: 9631
applications:
  - name: my_app
    route_prefix: /my_app
    import_path: my_stuff.apps:app
    runtime_env:
      env_vars:
        CODE_VERSION: "1" # update when you update code
    deployments:
      - name: ThingOne
      - name: ThingTwo

```

---

<div class="post-metadata">

**Author:** ![Jacob\_Summers](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jacob_summers/32/5278_2.png) [@Jacob\_Summers](https://discuss.ray.io/u/Jacob_Summers)\
**Post date:** [November 7, 2023, 3:15pm UTC](https://discuss.ray.io/t/how-to-redeploy-ray-serve-app/12701/6 "2023-11-07T15:15:17Z")

</div>

Thanks for the reply @cindy_zhang ! This clarifies things immensely.

One question - Is using packaging your code and providing it in the `runtime_env` preferable to packaging in side a docker container?
