Jack L.
Jack L.

Reputation: 1335

Heroku multiple commands in Docker deployment

I'm trying to execute multiple steps after Heroku builds the container with my Python Django application inside.

What I started with in heroku.yml (and it worked just fine), was:

build:
  docker:
    web: Dockerfile
release:
  image: web
  command:
    - python manage.py collectstatic --noinput

Now, I'd like to run migrations as well, and run some other commands (I'm using sqlite database), but the following does not work, and does not produce any output.

build:
  docker:
    web: Dockerfile
release:
  image: web
  command:
    - python manage.py collectstatic --noinput && python manage.py makemigrations --no-input && python manage.py migrate --no-input && python manage.py migrate auth --no-input && python manage.py makemigrations auth --no-input && python manage.py migrate --no-input --run-syncdb && echo "from django.contrib.auth.models import User; User.objects.create_superuser('user', '[email protected]', 'example', first_name='The', last_name='User')" | python manage.py shell"

Do you know what I could be missing here? I'm using Free Heroku plan.

I tried wrapping the commands in bash -c "COMMANDS GO HERE", but then it get errors of python not found (tried both python and python3)

Upvotes: 0

Views: 571

Answers (1)

Jack L.
Jack L.

Reputation: 1335

I've managed to get it working. In the heroku.yml, just call the shell script containing all the steps:

build:
  docker:
    web: Dockerfile
release:
  image: web
  command:
    - ./on_release.sh

For me, it worked when I placed the script in the workdir of my container (the same place where manage.py resides). I couldn't find more information about how exactly it works alltogether.

From heroku logs -t, it turns out that Heroku already uses "bash -c" under the hood (probably that's also how Docker wraps the commands from Yaml file).

Upvotes: 1

Related Questions