Deploying Code Hub Blog

Author

Jade Danial

Calendar

08 01, 2020 9:26 PM

Feedback

0 feedbacks

View

388 views

There are a lot of cloud platforms that provide great services but I chose the Heroku cloud platform because it is easy to use and they offer free and I do not need to add my credit card for payment at the early stage. It is also the cheapest option for a low traffic site like my blog site.

 

 

 

Sign Up To Heroku

 

I visit the Heroku website heroku.com then I click the Sign Up button to create my account then I receive a confirmation message in my email to confirm my password.

 

 

 

Install Heroku Toolbelt

 

Using my Mac terminal I type the command :

 

$ brew tap heroku/brew && brew install heroku

 

 

After installing Heroku Toolbelt I log in to my account using the terminal:

 

$ heroku login
Enter your Heroku credentials.
Email: myemailaddress@gmail.com
Password (typing will be hidden):
Authentication successful.

 

 

 

Preparing The Application

 

Here is the list of things I need to add to my project:

 

Add a Procfile in the project root.

Add requirements.txt file with all the requirements in the project root.

Add Gunicorn to requirements.txt.

A runtime.txt to specify the correct Python version in the Project root.

 

 

 

The Procfile

 

Create a file named Procfile in the project root with the following content:

 

web: gunicorn Codehub.wsgi --log-file -

 

 

 

The requirements.txt

 

I simply run in my terminal:

 

pip freeze > requirements.txt

 

This is how my requirements.txt looks like:

 

altgraph==0.14
astroid==1.6.0
beautifulsoup4==4.6.0
certifi==2018.11.29
chardet==3.0.4
dj-database-url==0.5.0
Django==2.1.3
django-ckeditor==5.6.1
django-js-asset==1.1.0
docopt==0.6.2
et-xmlfile==1.0.1
future==0.16.0
gunicorn==19.9.0
idna==2.8
isort==4.2.15
jdcal==1.4.1
lazy-object-proxy==1.3.1
macholib==1.8
mccabe==0.6.1
openpyxl==2.6.3
pefile==2017.11.5
Pillow==5.4.1
pipreqs==0.4.9
psycopg2==2.7.3.2
PyInstaller==3.3
pylint==1.8.1
PyQt5==5.9.1
pytz==2018.7
requests==2.21.0
sip==4.19.5
six==1.11.0
urllib3==1.24.1
whitenoise==4.1.2
wrapt==1.10.11
yarg==0.1.9

 

 

 

The runtime.txt

 

I create a file named runtime.txt in the project root and I put the specific Python version of my project use:

 

python-3.6.3

 

 

 

Set Up The Static Assets

 

Configure the static related parameters on settings.py:

 

# Static files (CSS, JavaScript, Images)

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

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'


# Media files (uploaded images)

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

 

 

 

Deployment

 

I login to Heroku using toolbelt:

 

$ heroku login

 

 

Inside the project root, I create a Heroku app:

 

$ heroku create codehub

 

 

I add PostgreSQL database to my app:

 

$ heroku addons:create heroku-postgresql:hobby-dev

 

 


Now I login to Heroku Dashboard and access my recently created app.
I click on the Settings menu and then on the button Reveal Config Vars and I add SECRET_KEY that I copied from settings.py

 

 

 

Push To Deploy

 

$ git status
$ git add .
$ git commit -m "Deploy Codehub"
$ git push origin master
$ git push heroku master

 

 

 

Migrate The Database

 

$ heroku run python manage.py migrate

 

 

 

Create A Superuser Account

 

$ heroku run python manage.py createsuperuser
Username: username
Email address: myemailaddress@gmail.com
Password: 
Password (again):
Superuser created successfully.

 

 

And finally, my app is live on https://codehubbyjadedanial.herokuapp.com

 

 

 

 

Please feel free to submit the feedback below. I appreciate it.

 

Thank You and Happy Coding.



0 Feedbacks

Jade

Jade Danial is a passionate programmer and creator of Code Hub blog. He is fueled by his passion for learning. He is fascinated by the idea of discovering the world of programming.


Meanwhile, he is developing desktop and web applications using his skills in programming.

Get In Touch With Me

Facebook

Facebook

Dev.to

Dev.to

Github

Github

LinkedIn

LinkedIn

Twitter

Twitter