Deploy a pre existing django git repo to heroku - python

I have a DJango git repository.Me and some other developers are working on it and it has multiple branchs also. Now i want to deploy it to Heroku or want to use the heroku as a staging server means before pushing to git i want to push the code changes to heroku and if verified will push changes to git. For this i have created a heroku app using this git repo by running
heroku create
command for heruku. But the problem is when i make a commit it is directly committed to the git not to the heroku.
I have tried to delete the heroku app from the local git repo by running
`heroku apps:destroy –a guarded-tundra-1589 --confirm`
but when i again tried to push the heroku master code is pushed to it. means it doesn't get deleted.
Tell me the right way to deploy the project which already has a git repo to heroku.

There are standart Heroku commands to do this:
$ heroku auth:login
... output omitted ...
$ heroku create --stack cedar
... output omitted ...
$ git commit -a -m 'Mods to run on Heroku.'
$ git push heroku master
UPDATE:
Also if you are planning to use Heroku in future it could be useful frt you to check their official Documentation - Getting Started with Django on Heroku

This will delete your repo, but this what worked for me when I got that error.
rm -rf .git
git init
git add .
git commit -m "First commit"
heroku create --stack cedar
git push heroku master

Related

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

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

Updating heroku django deployed site with new commits to github repo

Say I have deployed a django website on heroku through a github repository. (For deployment I simply clicked on the deploy button here - https://github.com/AmmsA/theresumator#theresumator---using-django-resumator.) I now update the repository with new commits.
Q: How can I make changes in the deployed website from the repository without losing the data already present on the repository.
When you are pushing the fresh commits git push heroku master or via git hook git push origin master -- these nothing to do with heroku database.
But this will run this command when build python manage.py migrate so if you are changed something in the migrations definetly db schema get alter not the values stored in there.
Just set your remote project:
heroku git:remote -a
And then, push your project on Heroku:
git push heroku main
I've written an article on it. You can see that. https://medium.com/#sreebash/how-to-update-previous-deployed-project-on-heroku-c778d555cd8a

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 =)

Openshift: How to and the Drawbacks of a Hot Deployment

I work with Openshift and in specific with Python. I have done many projects in there and I think the most irretating thing is that when you deploy your application, the server is down and you cannot even show a custom message.
I was socked after months when I searched in Google that there is an option to Hot Deploy an application. To git push it without the server get down. I am not a computer scientist, so I cannot understand if this technique has any drawbacks on my application.
Also, until now, when I wanted to update my application, I was doing:
git add .
git commit -a -m 'mycommit'
git push
I read on the manual that I have to enable the Hot Deployment with creating a file on the directory:
C:\app_directory> copy NUL > .openshift\markers\hot_deploy
But after that, how will I (hot) deploy the changes in my server?
Thank you
Once you have added the hot_deploy marker to your git repository, you need to follow the same git add, git commit, git push procedure, the only difference will be that your site will not shut down while it is being deployed. The new code will be deployed and everything should work as expected.
You need to add the marker file to your Git to make the change through to the the server.
git add .openshift/markers/hot_deploy
git commit -m "Changing application to hot deploy"
After this your subsequent commits (using the git add/commit/push combination) will not restart your server.
Alternatively you can use the following rhc commands to enable and disable auto-deployment.
rhc app-configure <app> auto-deploy
rhc app-configure <app> no-auto-deploy

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