How to upload and deploy django cookiecutter project, with docker, to heroku? - python

I am developing an app with django cookiecutter (with docker and heroku setup) and have come so far as to deploying it. This is my first ever project, so no prior experience with django, docker or heroku. I've read up on it at cookiecutter docs, heroku and a little on the docker website but I still don't how to deploy.
I have downloaded the heroki cli , have set up app on heroku with my own domain and a postgres db and I am planning on getting hobby tier to get the automated certificate. All environment variables are set in the .env file and are set in the heroku config vars in my app at heoku. So everything should be alright as far as code and settings. I am also using git as version control.
Am I supposed to upload the whole project (code, settings, docker files etc) to heroku with git or by some other means? I saw there was an option to deploy the project with docker deploys aswell at herokus website. What option is the correct one?
I was thinking initially that I would just upload the project through git and run docker-compose -f production.yml up (in the heroku bash)... or something like that and that. I dont know, please help.
If some info is missing or is unclear I will try edit it as best as I can.

It is better to deploy the project to Heroku using git.
$ heroku login
$ heroku create your_custom_app_name
$ git add --a
$ git commit -m "My custom app deployment to heroku"
$ git push heroku master
and then once it is deployed.
$ heroku python manage.py migrate

Related

How to upload python modules on Heroku

I have Django app, which I deployed on Heroku.
All the modules were deployed whith requirements.txt and everything is ok
But I also have several classes which are made as modules in separate .py files. On local machine these modules are in ...\Python\Python38-32\Lib\site-packages\modules\ folder
Now I need to upload these modules to Heroku. But I don't know how to do it. Is there any file manager program for windows, which allows to connect to heroku server and upload these /modules/ folder to the site-packages directory?
I've tried to find such a program, but couldn't find anything
Deploy the app
In this step you will deploy the app to Heroku.
Create an app on Heroku, which prepares Heroku to receive your source code:
$ heroku create
When you create an app, a git remote (called heroku) is also created and associated with your local git repository.
Heroku generates a random name (in this case serene-caverns-82714) for your app, or you can pass a parameter to specify your own app name.
Now deploy your code:
$ git push heroku master
The application is now deployed. Ensure that at least one instance of the app is running:
$ heroku ps:scale web=1
Now visit the app at the URL generated by its app name. As a handy shortcut, you can open the website as follows:
$ heroku open

Deploying Flask app on Heroku with local dependencies

I created a Flask app that I would like to deploy on Heroku (or similar platform). The process I've followed in the past is to creating a 'requirements.txt' file with the packages from my venv and Heroku installs them in the virtual server. The issue I am having is that I have changed some of the code in the Flask library to get the app to work like I want. Is there some way to load local packages? Should I remove it from my venv/lib folder and add it to my main folder?
Thanks,
Marc
You can use git for that.
Please check this link. https://devcenter.heroku.com/articles/python-pip#local-file-backed-distributions
You would have to out the local library in the git repo and then update your requirements.txt file

How to restart my Heroku Django app at the command line?

I deleted my app from Heroku web and now I want to recreate again but it says that it keeps the old name. I want to do:
heroku create globalnewstt
but it says:
No such app as peaceful-taiga-6373
(The last name and I deleted that repo from Heroku web)
How can I solve this problem?
You have your old Heroku app in your .git/config file. To fix this, run the command:
$ git remote rm heroku
Then, create your app fresh using heroku create =)

Heroku recognizes Django app as Node app

I'm trying to deploy a Django app to Heroku. That worked fine until I installed Node.js to set up automatic LESS compilation through Grunt. Now this happens:
I'm assuming that this happens because I have a package.json file in my root folder. How do I prevent Heroku from recognizing it as a Node.js app instead of a Django app? Currently my Node.js apps don't include anything that needs to run in production, but that could change in the future.
(PS: I apologize for not posting this as text. Long story short: I'm working in a terminal on a virtual machine.)
You can override the default and specify your own "buildpack" by specifying a custom buildpack in the BUILDPACK_URL config variable:
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-python
See more in the Heroku Buildpack Docs

Heroku Django: Reconnecting and Updating

I've finished the Heroku tutorial on how to upload and launch a basic django based web app using the following:
https://devcenter.heroku.com/articles/django#gitignore
Can anybody provide steps or a link to documentation on how to re-connect to Heroku and properly upload changes you've made to your site? Starting from a fresh terminal and cd'ing into the folder where your manage.py and procfiles live, what would the following steps be?
I then do:
$ virtualenv venv --distribute
$ source venv/bin/activate
after this i try to run $python manage.py runserver but it can't find django modules etc...
Do I need to reinstall django everytime I go to git push an update on the server?
To answer your question:
Heroku is just git, basically. At least on your computer.
So you don't need to "connect" to Heroku. You just cd to your source folder and use it as you would a normal git repository.
If you're using a virtualenv (which you should be), after you cd to your directory, you'll need to reactivate the virtualenv. If you followed heroku's Django tutorial, it'll probably be the command source venv/bin/activate
If you want to dig into some of herokus commands, download the Toolbelt.
To test whether your Procfile is working, use Honcho. It's a python version of foreman, Heroku's Ruby-based local Procfile runner.
To see which files are on your Heroku app:
Launch the bash on heroku by typing this command on your terminal:
heroku run bash --app appname
From there just ls and see your folders.

Categories