Deploy bot on Heroku

Hi there

I am trying to deploy my bot on heroku using a docker. When I release

Since Heroku dynamically generates the port number for the app, I used the $PORT variable. The problem is for some reason, the port number generated comes with a preceding backslash and this caused the app to fail. Any ideas on how I can fix this??

This is my dockerfile

FROM chatbotv3

ENV PORT 5005

WORKDIR /app COPY ./ ./

CMD [“run”, “-p”, “5005:$PORT”, “-m”, “models”,"–credentials", “credentials.yml”, “–enable-api”, “–log-file”, “out.log”, “–endpoints”, “endpoints.yml”]

EXPOSE 5005

And this is the command what the app attempts to run before it fails

2019-09-19T01:33:42.182999+00:00 heroku[web.1]: Starting process with command run -p 5005:\5427 -m models --credentials credentials.yml --enable-api --log-file out.log --e ndpoints endpoints.yml

I got the same issue. Why heroku add slash before port?

Solved it by using sed to remove the preceding beckslash

So the cmd ended up being:

CMD $(echo “rasa run -p $PORT -m models --credentials credentials.yml --enable-api --log-file out.log --endpoints endpoints.yml” | sed ‘s/=//’)

hi, can you help me step by step deloying rasa to heroku?

1 Like

Hey cityhunter25197

Apologies for the late response. I dont have the detailed steps but the steps you find on this link are just as good --> Container Registry & Runtime (Docker Deploys) | Heroku Dev Center

One thing that you will need to take note of is that in the dockerfile… coz of the issue that I mentioned above you will need to change the CMD command. Below is an example of a dockerfile that I used to run the action server at one time #Make sure that the directory has the init.py and action.py files

	FROM rasa/rasa:latest-full
	WORKDIR /app
	ADD . .
	ENTRYPOINT []
	EXPOSE 5005
	CMD $(echo "rasa run actions -p $PORT --debug" | sed 's/=//')

Hope this helps…

Hi Simba. I’m totally new in this field. Can you show me all your root file and dockerfile? and what type of <process-type> should I use in this command

heroku container:push <process-type>

I’m confused between your dockerfile in the first comment and the last one you reply me. I use Rasa Open Source (not Rasa X) and my folder just like this

data
models
_init_.py
actions.py
config.yml
credentials.yml
domain.yml
endpoints.yml
requirements.txt

I really need your help :slight_smile:

Hey!

I am happy to help but i think its worth taking a few steps back to look at the bigger picture. Tell me… why is it u want to run yo bot on heroku… reason why i am asking is… after playing around with it for quite a bit… i gathered its not the best of platforms to run your bot from. In fact, from the sound of it… it seems you already have a basic bot that provides some of your key responses (also known as happy paths) you would rather look for another cloud service provider and set yo bot up and run it from there.

Check out this Rasa Master Class, it will walk you through what u need to do to have it up and running step by step.

Let me know…

Simba

Thank you. I have built a simple bot and used ngrok to make it available for everyone who visit my website (to complete my thesis in school). But I can’t always use ngrok. (turn on my computer). So I want to deploy my bot to a cloud server. I think heroku is a good choice.

I have deployed it follow your help but I got some errors in CMD command. This is my dockerfile

FROM rasa/rasa:latest-full

ENV PORT 5005

WORKDIR /app COPY ./ ./

EXPOSE 5005

CMD $(echo “rasa run -p $PORT -m models --credentials credentials.yml --enable-api --log-file out.log --endpoints endpoints.yml” | sed ‘s/=//’)


I see… another question… for your bot, do you also have a action server to run your custom actions?

Yes. I have successfully deployed actions server separately to heroku. Currentlly, in my endpoint.yml

 action_endpoint:
  url: "https://****.herokuapp.com/webhook"

When I use ngrok, I just need to open port 5005. I think that when I deploy core (5005) to heroku, it will work

Oh… glad to hear you already deployed the action server successfully. It means you are almost there… Can you please share the error that you are having with the CMD

Hi. I don’t have my pc right now but my CMD errors is almost the same as yours.

Starting process with command run -p 5005:\5427 -m models --credentials credentials.yml --enable-api --log-file out.log --e ndpoints endpoints.yml

I think the I have the problem with $PORT. my dockerfile is on comment above. I usually run rasa on local with this command

rasa run -m models --enable-api --cors "*" --debug

Do you think I don’t need the line $PORT -m models --credentials credentials.yml

I got this error https://imgur.com/a/idjxswK

2020-03-03T16:00:36.773757+00:00 heroku[web.1]: Starting process with command /bin/sh -c \$\(echo\ \“rasa\ run\ -p\ \14809\ -m\ models\ --enable-api\ --cors\ \"\*\"\ --debug\”\ \|\ sed\ \'s/\=//\'\) 2020-03-03T16:00:41.005458+00:00 heroku[web.1]: State changed from starting to crashed 2020-03-03T16:00:41.008912+00:00 heroku[web.1]: State changed from crashed to starting 2020-03-03T16:00:40.984321+00:00 heroku[web.1]: Process exited with status 2 2020-03-03T16:00:40.773246+00:00 app[web.1]: usage: rasa [-h] [–version] 2020-03-03T16:00:40.773272+00:00 app[web.1]: {init,run,shell,train,interactive,test,visualize,data,x} … 2020-03-03T16:00:40.773273+00:00 app[web.1]: rasa: error: invalid choice: ‘/bin/sh’ (choose from ‘init’, ‘run’, ‘shell’, ‘train’, ‘interactive’, ‘test’, ‘visualize’, ‘data’, ‘x’) 2020-03-03T16:01:01.242800+00:00 heroku[web.1]: Starting process with command /bin/sh -c \$\(echo\ \“rasa\ run\ -p\ \52625\ -m\ models\ --enable-api\ --cors\ \"\*\"\ --debug\”\ \|\ sed\ \'s/\=//\'\) 2020-03-03T16:01:05.255590+00:00 heroku[web.1]: State changed from starting to crashed 2020-03-03T16:01:05.078706+00:00 app[web.1]: usage: rasa [-h] [–version] 2020-03-03T16:01:05.078721+00:00 app[web.1]: {init,run,shell,train,interactive,test,visualize,data,x} … 2020-03-03T16:01:05.078722+00:00 app[web.1]: rasa: error: invalid choice: ‘/bin/sh’ (choose from ‘init’, ‘run’, ‘shell’, ‘train’, ‘interactive’, ‘test’, ‘visualize’, ‘data’, ‘x’) 2020-03-03T16:01:05.235918+00:00 heroku[web.1]: Process exited with status 2 2020-03-03T16:01:07.970488+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/" host=fierce-falls-67780.herokuapp.com request_id=364f58d5-f18f-4643-844a-9668e3bd545d fwd=“171.225.251.30” dyno= connect= service= status=503 bytes= protocol=https 2020-03-03T16:01:08.892200+00:00 heroku[router]: at=error code=H10 desc=“App crashed” method=GET path="/favicon.ico" host=fierce-falls-67780.herokuapp.com request_id=290fb116-e183-4f87-98b0-5e13118dc854 fwd=“171.225.251.30” dyno= connect= service= status=503 bytes= protocol=https

Hi @cityhunter25197, Did you find a solution? Also looking into deploying my rasa chatbot to heroku server, but not sure where to start actually. It is also a bit confusing as it is sometime not clear whether the info is about how to deploy with Rasa Open Source or Rasa X… So really would like to know the steps you undertook (also for the deployment of your actions!) Many thanks!

Can you please tell me , what is in the _init_.py file?

Hey @cityhunter25197,

Did you manage to deploy the bot to heroku ??

did anybody find the solution for this please, I have the same issue!

here my dockerfile

FROM ubuntu:18.04

ENTRYPOINT []

RUN apt-get update && apt-get install -y python3 python3-pip && python3 -m pip install --no-cache --upgrade pip && pip3 install --no-cache rasa==1.9.5 && pip install spacy==2.1.9 && pip install https://github.com/explosion/spacy-models/releases/download/fr_core_news_md-2.1.0/fr_core_news_md-2.1.0.tar.gz && python3 -m spacy link fr_core_news_md fr

RUN pip3 install gunicorn

ENV LANG C.UTF-8

ADD . /app/

WORKDIR /app

CMD rasa run --model models --enable-api --cors “*” --debug -p $PORT

Hello @SimbaM, Can you help me, why they used :
FROM chatbotv3

I didn’t find any chatbotv3 repo in hub.docker.com

When I use : FROM rasa/rasa:1.10.2-full WORKDIR /app COPY . /app EXPOSE 5005 CMD [“run”, “–cors”, “*”, “–debug”] Heroku give me this error:

Can you help me please?

Hi @yassine.lamarti @ahnineamine @_sanjay_r @losimons @cityhunter25197

Apologies on responding on this very late. As they say… better late than never :slight_smile:

I still have my reservations on using heroku for this but I have seen that there are a number of people exploring this route so here are some steps that can help you

Steps to create bot using docker and deploy on heroku

  1. Create a docker image using a docker file with the text below and the command: docker build -t chat_bot:v1 .

    FROM rasa/rasa:1.10.3-full

    USER root

    RUN apt-get update -qq

    WORKDIR /app

    ADD . .

    ENTRYPOINT []

    USER 1001

    CMD $(echo “rasa run -p $PORT -m models --credentials credentials.yml --enable-api --log-file out.log --endpoints endpoints.yml” | sed ‘s/=//’)

  2. Create a project using the new image using the command:

    docker run -v /c/Temp/bot:/app chat_bot:v1 rasa init --no-prompt

  3. At this point you can make changes to your bot (add stories\intents etc) and to run and train the bot after making the changes you can train the bot using the command:

    docker run -v /c/Temp/bot:/app chat_bot:v1 rasa train --domain domain.yml --data data --out models

  4. To see your bot in action, you use the command:

    docker run -it -v /c/Temp/bot:/app chat_bot:v1 rasa shell

  5. Now lets deploy to heroku. Assuming you already have a heroku acc and the cli installed)

    a. heroku login

    b. heroku container:login

    c. heroku create * this creates the app that will be used by the docker

    d. heroku container:push web --app xxxxxxxxx * xxxxxxxxx is the name of the heroku app that was created in step c

    e. heroku container:release web --app xxxxxxxxx * this is what starts the heroku app

    f. heroku logs --tail --app xxxxxxxxx * run this to confirm that the bot is up and running.

This is it… let me know if you have any questions

Cheers

Simba

3 Likes