How To Stop Overwriting Directories When Pushing to Heroku - django

This seems simple enough but I can't find a fix. I have a django app on heroku. I'm using heroku as a staging environment. My app uses a directory media for images and files uploaded from the admin pages.
When I git push heroku master it destroys this directory even though it's not added in the repo.
How can I stop this?

Heroku doesn't provide persistent storage.
On git push your code is transformed into a slug and then it is distributed to a dyno that your application runs in. See https://devcenter.heroku.com/articles/slug-compiler for details.
If you want persistent storage you should integrate your application with AWS S3 (Simple Storage Service) or some other service.

Related

How to download updated sqlite Database from AWS EB? (Django app)

I have deployed my django app on AWS Elastic beanstalk, using the sqlite database. The site has been running for a while.
Now I have made some changes to the website and want to deploy again, but by keeping the changes the database went through(by form inputs)
But I am not able to find a way to download the updated database or any files. The only version of the app I am able to download is the one I already uploaded when I first deployed.
How can I download the current running app version and deploy with the same database?
you may use scp to connect to remote server and download all your files.
as commented, you should better use dumpdata and then i/o that file (instead of the db or full site).
however, if your remote system python version is not the same as your django site, then the dumpdata may not work (this is my case), so I managed to download the whole site folder back to local and then use dumpdata
aws elastic beanstalk Python app's files in /opt/python/current/app
just use scp -r to download the whole site to local.
I believe you have sqlite db file being packaged from your local during eb deploy. If that is a case then all you need to do is not include db.sqlite file in your deployments.
Move location of db.sqllite file to s3 or ebs persistent volume so that it persists.
Use .ebextentions to run db migration in aws on top of the aws db file just the way django recommends.
To be on safe side you can ssh into your eb env which is ec2 instance and download db.sqlite file just incase.

Django Web application publishing

How to publish django web application? what are the steps to be followed for publishing a django application? is there any free hosting for pulishing?
thanks in advance
I am using PythonAnyWhere for hosting my project. They provide hosting for python-Django / flask specificly and have a very dedicated team.
You can host your app for free but you can not use your own domain. To use custom domain, you need to purchase paid plan starting from $5 per month.
Their customer support is extremly good.
Steps to follow for hosting:
- Make sure your code is production ready i.e. well tested and bug free.
- Separate production and dev settings file. On production you need to set DEBUG=false.
- Push your code to github. Do not commit sensitive information like credentials or api keys. Keep them in .env file.
- Create account on pythonanywhere server and create database.
- Clone the git repo. Complete the web setup step. Edit the wsgio settings file.
- Run migrations. python manage.py migrate.
- Create cache table if any python manage.py createcachetable.
- Collect static files python manage.py collectstatic.
- Reload the web app.
Refer this step by step article to setup a free account and host web app on pythonanywhere server.
I'm a big fan of Amazon Web Services if you want simplicity and automation. You can create a CodeStar project for Django and Elastic Beanstalk. Everything is set up from you, so as soon as you commit code to your github repo (it even can create the repo for you with the elastic beanstalk config files), it builds, tests, then deploys it.
The best part is you can utilize amazon's free-tier level if you are a new member so it's probably going to be free or extremely cheap.
Look here for reference:
https://aws.amazon.com/codestar/faqs/
digitalocean.com is good for hosting. link
I used this for Django 2.0 with python3.

Deploy Django App on Azure: only displays default app, even after deployment

I am trying to deploy a webapp to Azure. I am following these directions https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-create-deploy-django-app/
First step, I created a webapp (Django) on the portal.
Then it says to follow the directions to configure Continuous deployment using GIT in Azure App Service. This should apparently lead to my having a local directory of Django files. https://azure.microsoft.com/en-us/documentation/articles/web-sites-publish-source-control/
So I follow those directions, installing Git, creating a local repository, adding a webpage, enabling web app repository, deploying.
The webportal now shows that I have deployed ('active' deployment). However, when I go to the web app url, what's showing is NOT what I deployed, but rather what I guess is the default Django app with its urls (login, logout, contacts).
So then I create an actual Django app in my local directory (instead of the static index.html from the directions). I commit and push it to Azure. It shows as being deployed.
The result is the same as before: the default web app is showing.
So what I'm missing is the connection between my local repository and what's actually showing. Is there some way to pull the Azure default app into my local repository? (Once it's there, I'll be able to change it as I see fit.)
Things are working as expected, but you ended up overwriting the Django app in your first the Git commit. The Continuous Deployment instructions as written are generic to any deployment, even a blank Web App.
So what I'm missing is the connection between my local repository and what's actually showing. Is there some way to pull the Azure default app into my local repository? (Once it's there, I'll be able to change it as I see fit.)
All you need to do is git clone your repo after you've initialized your local Git repo on the Azure Web App. You've already gone through most of these steps, but I'll include them here for others who may be looking for this answer.
After you create the Django Web App from the Azure Marketplace/Gallery, scroll down to set up continuous deployment.
Choose Local Git repo.
Notice that you now have a Git Clone URL in both your Quickstart Essentials info and under All Settings >> Properties. Go ahead and copy this URL.
If you haven't already done so, you may need to set or reset your Deployment Credentials. You'll find this under All Settings. This will be your Git & FTP credentials. Note that this is actually the credentials for your Microsoft Account, not just this one Web App.
You already have Git installed from your first attempt. You should now be able to navigate to the folder you want to clone the repo into and run:
git clone <your_git_clone_url>
After you type in your password, you'll have a cloned repo of the Django Web App on your local system. cd into the directory and start working from there. Once you have changes, git add ., git commit, and git push them back to the repo in Azure to see your changes there.

How should I stage my bitbucket + heroku django app for development and deployment?

How should I stage my bitbucket + heroku django app for development and deployment?
I'm working on a Django App.
I don't want to use github because I want to host have a private repo.
So right now I know how to deploy an app on heroku but how do I do it through bitbucket?
What is this deployment key stuff?
Do I have to reset my git remote origins or something?
Do I deploy with different folders? and commit my source code to different folders?
What happens when I want scale up my development environment to multiple computers?
I know I will be using git to monitor changes to the repo, how should I allow all of them to deploy to heroku?
Thanks
Change your git remote to point to your bitbucket URL, then proceed as normal.
Your remote origin would be the URL to your bitbucket found in settings. Your remote heroku would be pointing to Heroku.
#dan-hoerst's answer is still correct but I wanted to draw attention to heroku's new pipeline feature which lets you handle your staging and production environment better way.
A pipeline is a group of Heroku apps that share the same codebase.
Apps in a pipeline are grouped into “review”, “development”,
“staging”, and “production” stages representing different deployment
steps in a continuous delivery workflow.
You can find more about it here https://devcenter.heroku.com/articles/pipelines

Django Deployment Advice

I have a multi-step deployment system setup, where I develop locally, have a staging app with a copy of the production db, and then the production app. I use SVN for version control.
When deploying my production app I have been just moving the urls.py and settings.py files up a directory, deleting my django app directory with rm -rf command and then doing an svn export from the repository which creates a new django app directory with my updated code. I then move my urls.py and settings.py files back into place and everything works great.
My new problem is that I am now storing user uploads in a folder inside of my django app, so I can't just remove the whole app dir anymore or I would loose all of my users files.
What do you think my best approach is now? Would svn export --force work, since it should just be overwriting all of my changed files? Should I take an entirely new approach? I am open to advice?
You may want to watch this presentation by Jacob. It can help you improve your deployment process.
I use Bitbucket as my repo and I can simply perform push on my Dev box and run pull/update on Stage/Prod box. Actually I don't run them manually, I use fabric to do them for me :).
Your could use rsync or something similar to backup your uploaded files and use this backup when you deploy your project.
For deployment you could try to use buildout:
http://www.buildout.org/
http://pypi.python.org/pypi/djangorecipe
http://jacobian.org/writing/django-apps-with-buildout/
For other deployment methods see this question:
Django deployment tools
You can move your files to S3 servers (http://aws.amazon.com/s3/), so you will not ever have to care about moving them with your project.