0

I'm trying to deploy my django-react app to heroku. Deployment goes smoothly but on heroku open I'm greeted by an application error.

heroku logs --tail reveals the following

in short: error code H14 "No web process running"

in detail:

> 2021-01-22T18:12:32.000000+00:00 app[api]: Build started by user
> johndoe@gmail.com 2021-01-22T18:13:42.032970+00:00 app[api]:
> Deploy f905f66c by user johndoe@gmail.com
> 2021-01-22T18:13:42.032970+00:00 app[api]: Running release v3
> commands by user johndoe@gmail.com
> 2021-01-22T18:13:42.786292+00:00 app[api]: Starting process with
> command `/bin/sh -c 'if curl $HEROKU_RELEASE_LOG_STREAM --silent
> --connect-timeout 10 --retry 3 --retry-delay 1 >/tmp/log-stream; then 2021-01-22T18:13:42.786292+00:00 app[api]: chmod u+x /tmp/log-stream
> 2021-01-22T18:13:42.786292+00:00 app[api]: /tmp/log-stream /bin/sh -c
> '"'"'python manage.py migrate --no-input'"'"'
> 2021-01-22T18:13:42.786292+00:00 app[api]: else
> 2021-01-22T18:13:42.786292+00:00 app[api]: python manage.py migrate
> --no-input 2021-01-22T18:13:42.786292+00:00 app[api]: fi'` by user johndoe@gmail.com 2021-01-22T18:13:50.874352+00:00
> heroku[release.2135]: Starting process with command `/bin/sh -c 'if
> curl
> https://heroku-release-output.s3.amazonaws.com/log-stream?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJ3LIQ2SWG7V76SVQ%2F20210122%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20210122T181342Z&X-Amz-Expires=900&X-Amz-SignedHeaders=host&X-Amz-Signature=5fc1b225b8a71466d45518b4029f165af938e8c5d766033b8a335481d6a46e84
> --silent --connect-timeout 10 --retry 3 --retry-delay 1 >/tmp/log-stream; then 2021-01-22T18:13:51.619515+00:00 heroku[release.2135]: State changed from starting to up
> 2021-01-22T18:13:54.000000+00:00 app[api]: Build succeeded
> 2021-01-22T18:13:55.388498+00:00 app[release.2135]:
> /app/.heroku/python/lib/python3.6/site-packages/environ/environ.py:630:
> UserWarning: /app/recipemanager/.env doesn't exist - if you're not
> configuring your environment separately, create one.
> 2021-01-22T18:13:55.388523+00:00 app[release.2135]: "environment
> separately, create one." % env_file) 2021-01-22T18:13:56.208813+00:00
> app[release.2135]: Operations to perform:
> 2021-01-22T18:13:56.208840+00:00 app[release.2135]: Apply all
> migrations: admin, auth, contenttypes, knox, recipes, sessions
> 2021-01-22T18:13:56.247988+00:00 app[release.2135]: Running
> migrations: 2021-01-22T18:13:56.248243+00:00 app[release.2135]: No
> migrations to apply. 2021-01-22T18:13:56.708681+00:00
> heroku[release.2135]: Process exited with status 0
> 2021-01-22T18:13:56.751146+00:00 heroku[release.2135]: State changed
> from up to complete 2021-01-22T18:13:58.083076+00:00 app[api]: Release
> v3 created by user johndoe@gmail.com
> 2021-01-22T18:15:21.067440+00:00 heroku[router]: at=error code=H14
> desc="No web processes running" method=GET path="/"
> host=wholesumapp.herokuapp.com
> request_id=5ea478c4-e333-412d-9605-0c02a660f819 fwd="95.90.240.137"
> dyno= connect= service= status=503 bytes= protocol=https
> 2021-01-22T18:15:21.637645+00:00 heroku[router]: at=error code=H14
> desc="No web processes running" method=GET path="/favicon.ico"
> host=wholesumapp.herokuapp.com
> request_id=eada688a-c875-44df-97ef-b6c06cff95d4 fwd="95.90.240.137"
> dyno= connect= service= status=503 bytes= protocol=https

The steps leading up to it:

git push heroku master
heroku ps:scale web=1
heroku open

My Procfile:

release: python manage.py makemigrations --no-input
release: python manage.py migrate --no-input

web: gunicorn mainapp.wsgi

My file structure:

project
    accounts
    frontend
    mainapp
        __init.py__
        .env
        settings.py
        wsgi.py
    staticfiles
    __init.py__
    manage.py
    package-lock.json
    package.json
    Pipfile
    Pipfile.lock
    Procfile
    webpack.config.js

My settings.py file:

import django_heroku
import os
from pathlib import Path
import environ
import dj_database_url

env = environ.Env()

environ.Env.read_env()

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = env("SECRET_KEY")

DEBUG = env.bool('DEBUG', default=False)

ALLOWED_HOSTS = ['projectapp.herokuapp.com', '127.0.0.1', 'localhost'] 



INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework', 
    'frontend',
    'knox',
    'accounts'

]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication',)
}

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mainapp.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mainapp.wsgi.application'


DATABASES = {}
DATABASES = {'default': dj_database_url.config(default=env("DATABASE_URL"))}

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '../frontend/static/frontend/'




STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'


django_heroku.settings(locals())

I'm assuming something must be wrong with my Procfile, but then again I don't really know. I'm a complete beginner and I would be very glad about every kind of help and feedback.

Thanks in advance.

EliasSDA
  • 17
  • 1
  • 6

1 Answers1

0

As so many times in life, solutions lie in plain sight. I simply had to disable and enable the dyno again, I did that through the GUI of the heroku dashboard under the resources tab. Disabled it, hit save, enable again, hit save and ét voila.

There was nothing wrong with my code, at least not in that particular regard.

Learned a ton in the process and I'll leave my little checklist that I went through for this problem. Hopefully, this helps someone. Again, this is for deploying a django app with gunicorn to heroku, I don't know how much of this applies for other frameworks. Also, there may be alternative ways for this, but this worked for me.

  1. Procfile

    • Procfile can't have an extension like .txt
    • Procfile should be at the root of the directory that you're deploying to heroku along with manage.py
    • Make sure the web process within Procfile points to the right directory where your wsgi.py is located
  2. Dynos

    • After git push heroku master make sure that a dyno is running with heroku ps:scale web=1
    • You can check the Dyno status with heroku ps, in my case this said 'no dyno on app', simple disable/enable through heroku dashboard solved this.

Hope this helps someone, feel free to comment if you other questions. Take care.

EliasSDA
  • 17
  • 1
  • 6