How to chain commands for a Flask app

Hi
what is the right format to chain commands in the “Docker command” settings in order to run the following: flask db upgrade, flask translate compile and then the command to run the application?
At the moment when calling this command the deployment is successful:
gunicorn src.app:create_main_and_celery_apps()

but before doing this I need to run the other 2 flask commands

Note: FLASK_APP has been set to src.app:create_main_and_celery_apps()

Thanks

Hey,

Thanks for reaching out.

You can chain commands like this: “command 1 && command 2” or like this: “command 1; command 2;”

The difference between the 2 methods lies in how the second command is executed relative to the success or failure of the first command.

When you use "&&" to chain commands… command2 will only be executed if command1 succeeds (returns a zero exit status). Example:

echo "This is command 1" && echo "This is command 2"

In this case, “This is command 2” will only be printed if “This is command 1” is printed successfully.

When you use ";" to chain commands… command2 will be executed regardless of whether command1 succeeds or fails (irrespective of its exit status). Example:

echo "This is command 1"; echo "This is command 2"

Here, “This is command 2” will be printed even if there is some problem with printing “This is command 1” (although echo is likely to succeed in this trivial case).

Jérémy.
Render Support, UTC+3

Good morning Jeremy
I might be doing something wrong but I tried your suggestion and it seems to me that it is not working.
I used your suggested command, echo “This is command 1” && echo “This is command 2” and this is the output
I also tried launching my flask app in between the echo commands but the application is not launched

Many thanks

Hey,

The ‘echo’ statements were merely examples to demonstrate how you can chain commands on Render. You could use something like ‘flask db upgrade && flask translate compile && src.app:create_main_and_celery_apps’ for your build and start commands. Since you’re using a Docker environment, these would need to be applied within the Dockerfile, at least for the build phase.

Jérémy.
Render Support, UTC+3

Hi Jeremy
thanks for getting back me and sorry for not being clear. Yes I understand the echos were examples, but based on the screenshot I provided, it seems to be that even that simple chained commands is not working, maybe I am wrong.
AnywayI tried specifying this command instead, with and without the quote, without success
flask db upgrade && flask translate compile && src.app:create_main_and_celery_apps

If I run any of the above commands independently (not chained) they work but as soon as I chained them I get an error.
For example with this command: flask db upgrade && flask translate compile, I get this error:

Note as the second command seems to be treated as argument of the first command
Thanks

Hey,

My bad, this is how Docker is designed. It would not accept the && operator.

Try:

["sh", "-c", "flask db upgrade && flask translate compile"]

or

["sh", "-c", "flask db upgrade; flask translate compile"]

as your CMD command.

Jérémy.
Render Support, UTC+3

Hi Jeremy
thanks again for looking into this. I tried yous suggestion with and without but I get this error

I also tried without and double quotes around sh and -c but I got a different error

Is there any additional settings that I need to change?
Many thanks

Hey,

The “sh,” formatting is odd here. If you’ve provided the array content in your “Docker Command”, make sure that it’s provided as such:

sh -c flask db upgrade

and not:

"sh", "-c", "flask db upgrade"

Also:

/bin/bash -c flask db upgrade

may work

Jérémy.
Render Support, UTC+3

Hi Jeremy
thanks again. Based on your input I was able to successfully chain two commands as follow:

sh -c flask db upgrade; gunicorn “src.app:create_main_and_celery_apps()”

Many thanks for your great support

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.