I have a Django application running on Heroku with a web
dyno on a container
stack. On adding a worker
dyno via my app.json and heroku.yml files, Heroku's build system for my Review app logs:
=== Fetching app code
=!= Unknown error
The application builds properly locally via Docker and via Docker Compose. It has been building properly on Heroku until I modified my heroku.yml
file and app.json
file to add a worker.
My questions are:
heroku.yml:
build:
docker:
web: Dockerfile
release:
command:
- ./release_commands.sh
image: web
run:
web:
command: newrelic-admin run-program python manage.py runserver 0.0.0.0:$PORT
worker:
command: newrelic-admin run-program python manage.py rqworker app
image: web
app.json:
{
"name": "my-app",
"stack": "container",
"formation": {
"web": {
"quantity": 1
},
"worker": {
"quantity": 1
}
},
"environments": {
"review": {
"formation": {
"web": {
"quantity": 1,
"size": "hobby"
},
"worker": {
"quantity": 1,
"size": "hobby"
}
},
"addons": [
"heroku-redis",
{
"plan": "heroku-postgresql",
"options": {
"version": 13
}
}
],
"env": {
"DEBUG": 1,
"ENVIRONMENT": "dev",
"ALLOWED_HOST": ".herokuapp.com",
"CSRF_TRUSTED_DOMAIN": "*.herokuapp.com"
}
}
}
}
For the next person to encounter this problem: this was corner case between two heroku.yml
issues, caused by YAML ordering.
run.<app>.command
to be an array. If it isn't, Heroku will throw a parsing error (below).run
to be defined above release
. If it isn't, and condition (1) is present, Heroku will fail to throw a parsing error and instead throw Unknown error
. Here is the error the user would see if the above heroku.yml
were modified:
Properly ordered heroku.yml
with command
improperly set as a string instead of an array:
build:
docker:
web: Dockerfile
run:
web:
command: newrelic-admin run-program python manage.py runserver 0.0.0.0:$PORT
worker:
command: newrelic-admin run-program python manage.py rqworker app
image: web
release:
command:
- ./release_commands.sh
image: web
Yields the build error:
=== Fetching app code
=!= There were problems parsing your heroku.yml. We've detected the following issues:
run.worker.command needs to be in array format, such as:
run:
worker:
command:
- newrelic-admin run-program python manage.py rqworker app heap braze
image: web
Order shouldn't matter to YAML keys ( https://yaml.org/spec/1.2.2/#3221-mapping-key-order ). But when run
is defined below release
, and no other changes are made, Heroku's error output looks like this:
=== Fetching app code
=!= Unknown error
So, one cause of this Heroku error output is YAML ordering. Switching keys around fixes the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.