Skip to content

smtilson/ci-django-exercises

Repository files navigation

Deployment notes

These notes are for use later when I need to write part of the deployment section for pp4

  1. Log in to Heroku and navigate to your dashboard.
  2. Click on the 'New' button in the upper right and select 'Create new app.'
  3. Pick a unique name for your App, select the appropriate region, and click 'Create app.'
  4. Click on the 'Settings' tab, scroll down to the 'Config Vars' section, and click 'Reveal Config Vars.'
  5. Add a key-value pair with key DISABLE_COLLECTSTATIC and value 1.
  6. Add a key-value pair with key DATABASE_URLand value the database url provided. (If you no longer have access to this, please contact me.)

(should this be a different deployment section)

  1. Install a production ready web-server by entering pip3 install gunicorn~=20.1 into the terminal.
  2. Add this to the requirements.txt file with the terminal command pip3 freeze --local > requirements.txt.
  3. Create a file (without any extension) named 'Procfile' in the root directory of the repository.
  4. Add the line web: gunicorn my_project.wsgi to this file and save it. Heroku will use this to run our web app.

(should this be a different deployment section)

  1. In the settings.py file located in the my_project directory, change DEBUG=True to DEBUG=False.
  2. While in settings.py, append , '.herokuapp.com' to the end of the ALLOWED_HOSTS list (if there are no other hosts listed, simply add '.herokuapp.com'). (it says to remember the comma, but this is only relevant if there are other hosts, right?)

(is this even a deployment step? I guess so since we will deploy from github and need the procfile)

  1. Push these changes to GitHub.
  2. Navigate to the 'Deploy' tab of your app on Heroku and enable 'Connect to GitHub' in the 'Deployment method' section.
  3. Enter the name of the repository for the project in the search box and click 'Search.'
  4. Select the repository from the list of search results.
  5. Click 'Deploy Branch' to begin a manual deployment of the relevant branch.

(is this a different deployment section?)

  1. Scroll up and open the 'Resources' tab. there are steps about adding eco dynos and making sure there is no db installed yet. The first isn't entirely relevant to this but will be, not sure about the second. The steps are saved in logseq.

Environment variables 18. Create a file called env.py in the root directory. Add `import os

os.environ.setdefault( "DATABASE_URL", >database_url<)where you replace>database_url<` with the database url provided. (If you no longer have access to this, please contact me.)

static files deployment

  1. install whitenoise~=5.3.0

  2. add 'whitenoise.middleware.WhiteNoiseMiddleware', to the MIDDLEWAREvariable in settings.py directly after the SecurityMiddleware from Django.

  3. add STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') to settings.py

  4. run python3 manage.py collectstaticin the terminal

  5. ?? check version of python3 with python3 -v?? (in my case it was python-3.12.2)

  6. copy supported run time closest to yours in https://devcenter.heroku.com/articles/python-support#specifying-a-python-version (in my case it is python-3.12.3)

  7. add runtime.txt file to root and add the run time version (in my case this is python-3.12.3)

  8. git add, commit, and then push these changes to github.

  9. got to heroku page for the deployed app. click on settings. scroll down to config vars and remove the key value pair for DISABLE_COLLECTSTATIC

  10. then redeploy??

I think the above about collect static can sort of be collapsed, like take out the earlier stuff about collect static as well.

cloudinary set up

  1. download required packages for cloudinary api pip3 install cloudinary~=1.36.0 dj3-cloudinary-storage~=0.0.6 urllib3~=1.26.15 (this will likely be done by just having them install the requirements with pip).

  2. sign up to cloudinary

  3. go to the dashboard and copy the CLOUDINARY_URL (mine is CLOUDINARY_URL=cloudinary://736759862794426:NIk-OfM7ERFV3NWf9KoSMKxTXlc@djf0ieux6).

  4. go to settings and add the following to the list of installed apps. cloudinary_storage must be immediately after django.contrib.staticfiles, and add cloudinary as well.

  5. Go to settings in Heroku, Add CLOUDINARY_URL to the config vars.

About

This repository is for working with Django and following along the CI coruse material.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors