Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a shell script in release phase on Heroku

Tags:

shell

heroku

I have two commands to execute in release phase and as per this tutorial (https://devcenter.heroku.com/articles/release-phase), I have included them in a shell script named release.sh (located in the root of my Django project).

#!/bin/bash

python manage.py migrate
python manage.py compress

In my Procfile, I added the script thus, as described in the article.

release: ./release.sh
web: gunicorn myapp.wsgi --log-file -

But during release I get the following error.

/bin/sh: 1: ./release.sh: not found

Then the release fails.

I don't know if the problem is with the path in Procfile (I also tried bash $PWD/releash.sh) or the file not being available at the time it is called. Any help would be appreciated.

EDIT:

My release.sh was in a subfolder and that's why it wasn't found, but now I'm getting permission denied.

/bin/sh: 1: ./release.sh: Permission denied
like image 661
Nicholas Kajoh Avatar asked Mar 14 '18 15:03

Nicholas Kajoh


People also ask

How do I run a Heroku script?

Running the App or bot on Heroku Now in order to turn on/execute our script, we have to open up our app on the Heroku Website, go to Resources, and hit edit on our worker. - Enable both the web and worker, then save. Note: It can take up to two minutes for the script to start running!

How do I run multiple commands in Procfile?

You can run multiple command inside Procfile using sh -c command : worker: sh -c 'firstCommand && secondCommand && etc...' Notes : Procfile should be at the project root level. A good answer will always include an explanation why this would solve the issue, so that the OP and any future readers can learn from it.


2 Answers

This worked

chmod u+x release.sh && ./release.sh

So Procfile becomes

release: chmod u+x release.sh && ./release.sh
web: gunicorn myapp.wsgi --log-file -
like image 182
Nicholas Kajoh Avatar answered Oct 22 '22 10:10

Nicholas Kajoh


For this to work, release.sh must be executable

Locally, you could run chmod a+x release.sh. But you would not want to do that on heroku, so instead you can change the Profile to have this:

release: bash release.sh
web: gunicorn myapp.wsgi --log-file -
like image 11
olaoluwa_98 Avatar answered Oct 22 '22 11:10

olaoluwa_98