AWS App runner - Django - migrations after deploy fails

144 Views Asked by At

AS part of the development model changes are made and prepared with makemigrations. When deploying this code to another instance (via Git) the migrations need to be run on the database of the instance. I have configured the apprunner.yaml file as:

['''version: 1.0
runtime: python3
build:
  commands:
    build:
      - pip install -r requirements/production.txt
    post-build:
      - source /var/app/venv/*/bin/activate
      - python manage.py migrate
      - deactivate
run:
  runtime-version: 3.8.16
  command: sh startup.sh
  network:
    port: 8000''']

I've also tried it without the 'post-build' section. startup.sh contains: '''#!/bin/bash gunicorn config.wsgi:application''' also tried a version of the startup.sh with below - also fails

'''#!/bin/bash python manage.py migrate && gunicorn config.wsgi:application''' Log:

12-01-2023 10:05:40 AM [AppRunner] Reading apprunner.yaml config 

file.
12-01-2023 10:05:40 AM [AppRunner] Successfully Validate configuration file.
12-01-2023 10:05:42 AM [AppRunner] Starting source code build.
12-01-2023 10:09:00 AM [AppRunner] Service update failed. For details, see service logs.

I've tried variants of the yaml file as mentioned, one without the post-build, a post-build with on,y the Python... line, variants of the startup.sh file as above.

I've also tried using just the build settings it falls back on to change the start command from gunicorn config.wsgi:application to Python manage.py migrate && gunicorn config.wsgi:application. All just fails and rolls back.

0

There are 0 best solutions below