sei-ec-remote / project-4-issues

Open an issue to receive help on project 4
0 stars 0 forks source link

Can't deploy the App #235

Closed AlexMcBex closed 11 months ago

AlexMcBex commented 1 year ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

Django Views

What's the problem you're trying to solve?

I can't deploy the app with render and bit

Post any code you think might be relevant (one fenced block per file)

settings.py

"""
Django settings for xketchez project.

Generated by 'django-admin startproject' using Django 4.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/4.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.1/ref/settings/
"""

from pathlib import Path
import dj_database_url
import environ
import os

env = environ.Env(
    DEBUG = (bool, False)

)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
environ.Env.read_env(os.path.join(BASE_DIR, '.env'))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# SECRET_KEY = 'django-insecure-y&6))%%&_ek%k&s0d327@s1^4^p6cos(($d&okk95it%2d!1-*'
SECRET_KEY = env('SECRET_KEY')
AWS_ACCESS_KEY = env('AWS_ACCESS_KEY')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
S3_BUCKET = env('S3_BUCKET')
S3_BASE_URL = env('S3_BASE_URL')

# print(' this is SECRET_KEY :', SECRET_KEY)
# print(' this is AWS_ACCESS_KEY :', AWS_ACCESS_KEY)
# print(' this is AWS_SECRET_ACCESS_KEY :', AWS_SECRET_ACCESS_KEY)
# print(' this is S3_BUCKET :', S3_BUCKET)
# print(' this is S3_BASE_URL :', S3_BASE_URL)

# SECURITY WARNING: don't run with debug turned on in production!
# DEBUG = True
DEBUG = 'RENDER' not in os.environ

ALLOWED_HOSTS = []

RENDER_EXTERNAL_HOSTNAME = os.environ.get('RENDER_EXTERNAL_HOSTNAME')
if RENDER_EXTERNAL_HOSTNAME:    
    ALLOWED_HOSTS.append(RENDER_EXTERNAL_HOSTNAME)

# Application definition

INSTALLED_APPS = [
    'main_app',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

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 = 'xketchez.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 = 'xketchez.wsgi.application'

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

# DATABASES = {
#     'default': {
#         'ENGINE': 'django.db.backends.postgresql',
#         'NAME': 'xketchez2',
#     }
# }

DATABASES = {
    'default': dj_database_url.config(     
    default='postgresql://postgres:postgres@localhost:5432/xketchez2',        
    conn_max_age=600    
) }

DATETIME_FORMAT = 'Y/m/d'
USE_L10N = False
USE_TZ = False

# Password validation
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

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',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

# STATIC_URL = 'static/'
# if not DEBUG:
# Tell Django to copy statics to the `staticfiles` directory
# in your application directory on Render.
STATIC_URL = os.path.join(BASE_DIR, 'static/')
# print('THIS IS STATIC_URL', STATIC_URL)

if not DEBUG:
    # Tell Django to copy statics to the `staticfiles` directory
    # in your application directory on Render.
    STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

    # Turn on WhiteNoise storage backend that takes care of compressing static files
    # and creating unique names for each version so they can safely be cached forever.
    STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Turn on WhiteNoise storage backend that takes care of compressing static files
# and creating unique names for each version so they can safely be cached forever.
# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

LOGIN_REDIRECT_URL = '/arts/'

LOGOUT_REDIRECT_URL = '/'

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

I get this log when I try to deploy or run the server

Mar 13 04:18:06 PM  ==> Cloning from https://github.com/AlexMcBex/Xketchez...
Mar 13 04:18:06 PM  ==> Checking out commit cec090df3705fc390aa8e8e88cf5a992fb75df75 in branch deploy
Mar 13 04:18:10 PM  ==> Using Python version: 3.7.10
Mar 13 04:18:13 PM  ==> Running build command './build.sh'...
Mar 13 04:18:13 PM  Collecting asgiref==3.6.0
Mar 13 04:18:13 PM    Downloading asgiref-3.6.0-py3-none-any.whl (23 kB)
Mar 13 04:18:14 PM  Collecting backports.zoneinfo==0.2.1
Mar 13 04:18:14 PM    Downloading backports.zoneinfo-0.2.1-cp37-cp37m-manylinux1_x86_64.whl (70 kB)
Mar 13 04:18:15 PM  Collecting boto3==1.26.84
Mar 13 04:18:15 PM    Downloading boto3-1.26.84-py3-none-any.whl (134 kB)
Mar 13 04:18:16 PM  Collecting botocore==1.29.84
Mar 13 04:18:16 PM    Downloading botocore-1.29.84-py3-none-any.whl (10.5 MB)
Mar 13 04:18:17 PM  Collecting dj-database-url==1.2.0
Mar 13 04:18:17 PM    Downloading dj_database_url-1.2.0-py3-none-any.whl (7.1 kB)
Mar 13 04:18:18 PM  ERROR: Could not find a version that satisfies the requirement Django==4.1.7 (from -r requirements.txt (line 6)) (from versions: 1.1.3, 1.1.4, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 1.2.7, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.4, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.4.12, 1.4.13, 1.4.14, 1.4.15, 1.4.16, 1.4.17, 1.4.18, 1.4.19, 1.4.20, 1.4.21, 1.4.22, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11, 1.5.12, 1.6, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.6.11, 1.7, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9, 1.7.10, 1.7.11, 1.8a1, 1.8b1, 1.8b2, 1.8rc1, 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10, 1.8.11, 1.8.12, 1.8.13, 1.8.14, 1.8.15, 1.8.16, 1.8.17, 1.8.18, 1.8.19, 1.9a1, 1.9b1, 1.9rc1, 1.9rc2, 1.9, 1.9.1, 1.9.2, 1.9.3, 1.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6, 3.1.7, 3.1.8, 3.1.9, 3.1.10, 3.1.11, 3.1.12, 3.1.13, 3.1.14, 3.2a1, 3.2b1, 3.2rc1, 3.2, 3.2.1, 3.2.2, 3.2.3, 3.2.4, 3.2.5, 3.2.6, 3.2.7, 3.2.8, 3.2.9, 3.2.10, 3.2.11, 3.2.12, 3.2.13, 3.2.14, 3.2.15, 3.2.16, 3.2.17, 3.2.18)
Mar 13 04:18:18 PM  ERROR: No matching distribution found for Django==4.1.7 (from -r requirements.txt (line 6))
Mar 13 04:18:18 PM  WARNING: You are using pip version 20.1.1; however, version 23.0.1 is available.
Mar 13 04:18:18 PM  You should consider upgrading via the '/opt/render/project/src/.venv/bin/python -m pip install --upgrade pip' command.
Mar 13 04:18:18 PM  Traceback (most recent call last):
Mar 13 04:18:18 PM    File "manage.py", line 11, in main
Mar 13 04:18:18 PM      from django.core.management import execute_from_command_line
Mar 13 04:18:18 PM  ModuleNotFoundError: No module named 'django'
Mar 13 04:18:18 PM  
Mar 13 04:18:18 PM  The above exception was the direct cause of the following exception:
Mar 13 04:18:18 PM  
Mar 13 04:18:18 PM  Traceback (most recent call last):
Mar 13 04:18:18 PM    File "manage.py", line 22, in <module>
Mar 13 04:18:18 PM      main()
Mar 13 04:18:18 PM    File "manage.py", line 17, in main
Mar 13 04:18:18 PM      ) from exc
Mar 13 04:18:18 PM  ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Mar 13 04:18:18 PM  Traceback (most recent call last):
Mar 13 04:18:18 PM    File "manage.py", line 11, in main
Mar 13 04:18:18 PM      from django.core.management import execute_from_command_line
Mar 13 04:18:18 PM  ModuleNotFoundError: No module named 'django'
Mar 13 04:18:18 PM  
Mar 13 04:18:18 PM  The above exception was the direct cause of the following exception:
Mar 13 04:18:18 PM  
Mar 13 04:18:18 PM  Traceback (most recent call last):
Mar 13 04:18:18 PM    File "manage.py", line 22, in <module>
Mar 13 04:18:18 PM      main()
Mar 13 04:18:18 PM    File "manage.py", line 17, in main
Mar 13 04:18:18 PM      ) from exc
Mar 13 04:18:18 PM  ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?
Mar 13 04:18:18 PM  ==> Build failed 😞
Mar 13 04:18:18 PM  ==> Generating container image from build. This may take a few minutes...

What is your best guess as to the source of the problem?

I accidently ran pipenv install django in the project folder, I may have messed up...

What things have you already tried to solve the problem?

rerun the install dependencies in the django env folder

Paste a link to your repository here https://github.com/AlexMcBex/Xketchez

scarletpuma commented 1 year ago

Make sure your django is installed in your pip environment. It's having an issue with where your django is installed, I think, based on this: Could not find a version that satisfies the requirement Django==4.1.7

AlexMcBex commented 1 year ago

I already reran it with pipenv install django. If I run it with pip instead I get this:

(django-env) ➜  django-env pip install django
Requirement already satisfied: django in /home/alexmcbex/.local/share/virtualenvs/django-env-3fOLF7ra/lib/python3.8/site-packages (4.1.7)
Requirement already satisfied: asgiref<4,>=3.5.2 in /home/alexmcbex/.local/share/virtualenvs/django-env-3fOLF7ra/lib/python3.8/site-packages (from django) (3.6.0)
Requirement already satisfied: sqlparse>=0.2.2 in /home/alexmcbex/.local/share/virtualenvs/django-env-3fOLF7ra/lib/python3.8/site-packages (from django) (0.4.3)
Requirement already satisfied: backports.zoneinfo in /home/alexmcbex/.local/share/virtualenvs/django-env-3fOLF7ra/lib/python3.8/site-packages (from django) (0.2.1)
AlexMcBex commented 1 year ago

Anything else I could try to do?

asands94 commented 1 year ago

Do you currently have a pipfile and a piplock file inside your project or only in your django environment folder?

AlexMcBex commented 1 year ago

only in the environment folder, not in the project one

asands94 commented 1 year ago

When you deploy, do you have that requirements.txt file?

AlexMcBex commented 1 year ago

yes, it contains this:

asgiref==3.6.0
backports.zoneinfo==0.2.1
boto3==1.26.84
botocore==1.29.84
dj-database-url==1.2.0
Django==4.1.7
django-environ==0.10.0
gunicorn==20.1.0
jmespath==1.0.1
psycopg2-binary==2.9.5
python-dateutil==2.8.2
s3transfer==0.6.0
six==1.16.0
sqlparse==0.4.3
urllib3==1.26.14
whitenoise==6.4.0
AlexMcBex commented 1 year ago

does the fact that Django is spelled with a capital D in requirements important?

asands94 commented 1 year ago

Have you installed Django or only django? Also were you able to run your app before?

AlexMcBex commented 1 year ago

I followed the instructions in here https://git.generalassemb.ly/sei-ec-remote/django-render-deployment I installed the dependencies listed in the readme

asands94 commented 1 year ago

install django with a capital D, sometimes it matters. Hopefully that works since everything else looks installed, then you'll need to delete your requirements.txt and add it again

AlexMcBex commented 1 year ago

Before following the instructions in the settings.py the app server runs normally, I have a development branch with the original settings.py file that I'm using to work on the code. I ran pipenv install Django in the env folder and with pip freeze > requirements.txt I made a new requirements file. It's identical to the one I deleted and there's no new code to push, the deployment still gives me the same error...

asands94 commented 1 year ago

If you follow the deploy instructions and comment out your old database and add the new one, youre code will not work locally and will only work in production, but the databases section should be the only thing that affects your code. I would say to keep working in the development branch and when thats done push all your code to main since you know it's working then re follow the deploy instructions. AT least your development branch will stay working if you run into errors again

AlexMcBex commented 1 year ago

Yeah, that's how I worked on the code since yesterday, working locally is not the problem, the problem is the error that I receive when I try to deploy the app in the deploy branch

mqpiffle commented 1 year ago

Has anyone figured this out? I'm running into the same issue when I try to deploy, even though it worked just fine with the finchcollector app.