# Installing and Deploying Spirit with Heroku

T
• 1
• 19 Sep '18

Good morning guys.

I am struggling to deploy spirit. Consider I am a newby with Django, but yesterday I studied a book and tried to apply its procedure to my objective: installing and deploying Spirit.
Following the detail of what I have done. The problem arises at the end, when I type: "$git push heroku master". Let's see it. Installing Spirit$ cd ~/Desktop
$mkdir spiritdirectory$ cd spiritdirectory
$pipenv install django$ pipenv shell

$pip install django-spirit$ spirit startproject spirit_project

$cd spirit_project$ python manage.py spiritinstall
list of green OK.

python manage.py createsuperuser
python manage.py runserver

It works clicking on http://127.0.0.1:8000

# Comment:

Now. Am I wrong or we didn’t create a specific app? I was used to digit the following:
(spiritdirectory-etc.etc.) $python manage.py startapp pages Then entering its settings.py (that I don’t see here) and add ‘spiritdirectory’ to INSTALLED_APPS. All of this is not necessary? I found installed_apps into base.py within the folder settings in my folder spirit_project. In this regard, I am confused by the fact that there are two spirit_project folders, though I created just one as shown in the command line’s orders above. End comment # I added spiritdirectory to INSTALLED APPS within base.py http://127.0.0.1:8000 doesn’t work anymore. Removing ‘spiritdirectory’ makes the link working again. Then I will go through Git and Bitbucket. (spiritdirectory-etc.etc.)$ git init
Initialized empty Git repository in /Users/danielevagnoli/Desktop/ spiritdirectory/spirit_project/.git/

(spiritdirectory-etc.etc.) $git status (spiritdirectory-etc.etc.)$ git add -A
(spiritdirectory-etc.etc.) $git commit -m 'initial commit' Then I created a new repository on Bitbucket called: spiritone-app Then I connected my repository to Bitbucket. git remote add origin https://vangoly@bitbucket.org/vangoly/spiritone-app.git git push -u origin master Still works if I click on http://127.0.0.1:8000 Now I want to put my code on production, i.e. deploying my code on an external server. I am using Heroku. (spiritdirecotry- etc. etc.)$ heroku login
Logged in as etc. etc.

# I made the following changes to my spirit project so we can deploy it online with Heroku.

(spiritdirectory-etc.etc.) $pipenv lock (spiritdirectory-etc.etc.)$ touch Procfile

I copied the following code: web: gunicorn spirit_project.wsgi --log-file - into Procfile. This should tell to use our spirit_project wsgi file but with gunicorn, a web server suitable for production, instead of local development with Django’s own server.

(spiritdirectory-etc.etc.) $pipenv install gunicorn (follows in the next post) T • 19 Sep '18 # Should I do something with ALLOWED_HOSTS? Something like ALLOWED_HOSTS = [‘*’] Now I use git status to check our changes, add the new files, and then commit it: (spiritdirectory-etc.etc.)$ git status
(spiritdirectory-etc.etc.) $git add -A (spiritdirectory-etc.etc.)$ git commit -m “New updates for Heroku deployment”

The I push it to bitbucket so I have an online backup of our code changes.

Now I deploy with Heroku.
$heroku create$ heroku git:remote -a randomnameheroku-app
$git push heroku master At this point everything fails and I don’t understand why. remote: ! No default language could be detected for this app. remote: HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically. remote: See https://devcenter.heroku.com/articles/buildpacks remote: remote: ! Push failed remote: Verifying deploy... remote: remote: ! Push rejected to tranquil-bastion-28846. remote: To https://git.heroku.com/tranquil-bastion-28846.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/tranquil-bastion-28846.git' Do you have any suggestions or idea on why it doesn't work? Perhaps I need to change strategy? Best and thank you! nitely Esteban C Borsani • 20 Sep '18 Hey, First of, there is a spirit-heroku repo with everything needed to deploy into heroku (just clicking a deploy button) here: https://github.com/nitely/spirit-heroku but I remember nothing about the process of creating the heroku app Now. Am I wrong or we didn’t create a specific app? There is a Django command called startproject. The spirit command (spirit startproject spirit_project) is pretty much the same, except it adds all the Spirit settings. The file base.py is basically your regular settings.py, then there's a setting file for every environment (test, dev and prod) that extend the base. You should use dev when developing on local machine, and prod on say heroku. A good example is the heroku_prod.py. When you click on "deploy to heroku", you are asked to fill some form. Each field on that form ends up as an environment variable that is then used by heroku_prod.py. The heroku_prod.py is set as the default DJANGO_SETTINGS_MODULE, see the manage.py file in that repo. But if you may be better off with a single settings.py. In that case just rename the base.py to setting.py, and set the DJANGO_SETTINGS_MODULE env var (in manage.py or by other means). There will be some missing setting you can find in dev.py. Then entering its settings.py (that I don’t see here) and add ‘spiritdirectory’ to INSTALLED_APPS. All of this is not necessary? Well no. Open the base.py and you'll see spirit within the INSTALLED_APPS setting. I am confused by the fact that there are two spirit_project folders Let's see: esteban@dev:~/PycharmProjects$ source venv35/bin/activate
(venv35) esteban@dev:~/PycharmProjects/spirit_test_project$pip install django-spirit (venv35) esteban@dev:~/PycharmProjects$ cd spirit_test_project/
(venv35) esteban@dev:~/PycharmProjects/spirit_test_project$spirit startproject forum Creating spirit project... ok (venv35) esteban@dev:~/PycharmProjects/spirit_test_project$ tree
.
└── forum
├── forum
│   ├── __init__.py
│   ├── settings
│   │   ├── base.py
│   │   ├── dev.py
│   │   ├── __init__.py
│   │   ├── prod.py
│   │   └── test.py
│   ├── urls.py
│   └── wsgi.py
├── __init__.py
└── manage.py

3 directories, 10 files
(venv35) esteban@dev:~/PycharmProjects/spirit_test_project/forum$python manage.py spiritinstall Operations to perform: # ... many lines here ok (venv35) esteban@dev:~/PycharmProjects/spirit_test_project/forum$ python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
September 20, 2018 - 00:41:50
Django version 1.11.15, using settings 'forum.settings.dev'
Starting development server at http://127.0.0.1:8000/
nitely
Esteban C Borsani
• 20 Sep '18

I copied the following code: web: gunicorn spirit_project.wsgi --log-file - into Procfile. This should tell to use our spirit_project wsgi file but with gunicorn, a web server suitable for production, instead of local development with Django’s own server.

The heroku code for he aove example would be:

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

(notice how the path ./forum/wsgi.py is translated to forum.wsgi on python import path notation)

Should I do something with ALLOWED_HOSTS? Something like ALLOWED_HOSTS = [‘*’]

The wildcard is supposed to be used on development only (ie a local machine while developing). On production you should change it to the forum domain, ie: ALLOWED_HOSTS = [".spirit-project.com"] (notice the starting dot)

At this point everything fails and I don’t understand why.

Read the heroku manual. You are likely missing one or more of their magical file, like the runtime.txt that tells heroku what language to use (I think that's the error you are getting). Check my spirit-heroku repo.

Once you have deployed into heroku, you can check the error log by running heroku logs command.

nitely
Esteban C Borsani
• 2
• 20 Sep '18

Oh, I just noticed my spirit-heroku repo won't work since base.py tries to import spirit.settings which was removed on the last Spirit release. I'll fix it this weekend.

T
• 1
• 20 Sep '18

Oh thanks. Yes, deploying it to Heroku doesn't work because of what you said Esteban.

However what I found confusing also is the following aspect: when I download let's say the spirit-heroku folder, is this automatically the directory I would create with $mkdir randomspiritname ? Or, on the opposite, should I navigate to it through the terminal and run some specific command to make it a directory? I am asking this because once I created the directory and the project (as described above) I cloned your most update package through the procedure specified here. In this way my folder obtained everything that was inside your package, however it already possessed what I created before cloning. Is it normal? I don't think so. Then, nonetheless, at the end of the procedure when I ran$ heroku logs, I had several errors H10 or H14, depending on the moment. However, cloning your repository into mine solved the previous problem and I was able to run $git push Heroku master and the build was successful on Heroku but when I tried to$ Heroku open It was saying it was not possible.

Best!

nitely
Esteban C Borsani
• 3
• 21 Sep '18

I'm not sure, but in theory yes. Also, you could replace the setting base.py by the one startproject generates, that's the first thing I'll try. Just wait for me to fix it. I'll do it tomorrow or the next day.

However what I found confusing also is the following aspect: when I download let's say the spirit-heroku folder, is this automatically the directory I would create with $mkdir randomspiritname ? Or, on the opposite, should I navigate to it through the terminal and run some specific command to make it a directory? Yes, cloning a project will just create the repo structure and files in your machine. They are regular directories, like the one you create with mkdir. Let me tell you how I built spirit-heroku: I basically followed the Spirit installation steps, then made the weird files heroku asks to create, then initialized my spirit-heroku as a git project, and then created the github repo and pushed the repo there (with the git remote add ... command, etc) very similar to what you do with heroku. So spirit-heroku is already a Django project with Spirit installed. Granted I used an old version of Spirit, so it won't work anymore. When you clone a project, you get all the files in a repo_name directory. But I think cloning a repo is for developing. For example if you want to make changes to Spirit code itself, you would fork the project, so you have a copy in your github account and you can make changes to it, then clone it, create your own branch, make the desire changes and push them to your fork, and then maybe make a pull request to the original repo. In the very weird case of spirit-heroku, you have to clone it to then push the changes to heroku. But cloning is not entirely necessary , there is a way to download the repo as a zip. however it already possessed what I created before cloning. Is it normal? I don't think so. Probably normal. Cloning won't overwrite files, I don't think (but I've never tried that). when I ran$ heroku logs, I had several errors H10 or H14,

I've no idea what that is. Logs should be empty if everything works.

but when I tried to \$ Heroku open It was saying it was not possible.

I had to google that command. The command is heroku open -a myapp. If the build was successful, the app should be in your heroku account apps section (I don't remember where to find that but I know is there somewhere).

nitely
Esteban C Borsani
• 22 Sep '18

I fixed spirit-heroku, it works now. Here I tested it -> https://spirit-forum.herokuapp.com/

seal's comment was removed 3 years, 2 months ago