I have deployed my first web application to google cloud and I have been having a lot of difficulties on my first trip.
My main question (and reason for creating this post) is how to execute commands with manage.py like migrations? If that is not possible, how to handle migrations in the database?
I'm having trouble working in the cloud, I'm using the Cloud SQL for Postgresql and App Engine Flexible environment, I would appreciate if the more experienced ones could help me.
Thanks in advance.
Ok, problem solved. I solved it by using a local copy of Cloud SQL Proxy and actually it was pretty easy.
Found the answer here https://cloud.google.com/python/django/appengine#deploying_the_app_to_the_standard_environment_
I highlighted the most important part of this article in my TIL repository, if you are looking to a quicker answer.
https://github.com/jaocfilho/til/blob/master/google-cloud-platform/proxy-with-sql-instance.md
Thanks everyone.
Related
For my job interview, I got assignment to create CRUD with Django and Postgresql. I created database locally and finished my assignment.
Now I have to upload my code to github. The problem is, they asked for some exampled for CRUD. Developer that is reviewing my code obviously can't access my local DB.
What can I do to solve this issue? Do I have to upload my DB to cloud (if so what is the best way to do that)? Or is there any other way to resolve this?
Thanks in advance
When they download your code they would need to create their own local db, run python manage.py makemigrations and python manage.py migrate, then all the db tables will be created. However, there won't be any initial data.
I recommend downloading your code and running through every step it takes to get your project up and running. This would include things like create an admin user, etc. Then create a basic README with all the steps to make it as easy as possible for them to get it up and running.
Alternatively, you could Dockerize your application and provide a Dockerfile, but that's a bit overkill for a take home interview in my opinion. It may impress the interviewer nonetheless. They may not even want to download and run your project, just review your code in Github.
To provide initial data, you would want to look into writing fixtures. Then have them run python manage.py dumpdata to populate the db.
Just upload it to Heroku or something similar. You already have postgres as database so it's valid way. It is pretty straightforward with Heroku's official guide for django applications. I had same issue in my recruitment process and it was a solution that satisfied recruiter.
Database obviously will be empty unless you prepare some fixtures, which is very good idea. Django docs have something for that.
I'm developing small single user applications in Django. Currently I do so with Heroku, which works just fine. I would like to deploy the application on Google Cloud run to have in the future a bit more flexibility.
In order to keep the overhead as small as possible I was considering using Sqlite. To keep persistency all I would need is a persistent volume, which could be achived via Google Cloud storage that is mounted into the docker container via gcsfuse. But here is the issue. I can't find a small Image with python and gcsfuse. I'm not a docker pro. Just getting started...
Any help is appreciated.
Google itself provides a HowTo Deploy a (simple) Django app to Google Cloud Run:
https://codelabs.developers.google.com/codelabs/cloud-run-django/
I myself as a Google Cloud rookie followed it step by step and it worked without any problems. By the way, I found that via the episode of the podcast Django Chat "Advanced Deployment" with Katie McLaughlin.
The HowTo use a Cloud SQL instance instead of Sqlite, but this seems to be a good choice:
„Generally speaking SQLite is not a good database choice for
professional websites. So while it is fine to use SQLite locally while
prototyping an idea, it is rare to actually use SQLite as the database
on a production project.“
William S. Vincent. „Django for Professionals, Chapter 2
Letting this apart it shouldn't be so hard to skip the Cloud SQL step and keep SQLite.
I'am new with the framework django and I want to realize a project using microservices.
I have been looking for detailed documentation about but til now I've found nothing
very helpful and which explains the procedure step by step. Different microservices must be able to communicate with one another.
I've already tried django microservices explain by Pypi but no good results.
So if someoene can help me with the procedure or templates for microservices I'll be grateful.
PS. My OS is windows7 64bits and I can't use docker on it.
Thank you for your help...
I really need help here please.
I made a rails application with the default gemfile and then followed the instructions for installation in comfy's wiki. Ran my app in the local host with webrick and sqlite3 getting no issues really, even though I am learning as I develop, but when the app was kind of ready (I judge it so it probably wasn't) for getting it up and running on heroku it failed, I checked the logs I migrated the database and tried with new apps, even tried installing psql and using unicorn as a web server (tried is emphasized cause neither of em worked for various reasons).
I've spent 6 hours (more or less) going through wikis and stuff but there really isn't much material for this CMS, please help, I even created a stack overflow account because of this issue.
I need a more detailed guide of the configuration needed for heroku.
And I have another question, what happens to the info generated by the users in heroku, how can I backup that. If I push something the differences in the cloud get erased? (Obviously the answer is no, but I want to know how and why)
Thanks a lot, this is driving me crazy.
FYI I'm an amateur.
Pd I can post some of my code's app if required.
I want to work locally on my django(1.7) project and regularly deploy updates to a production server. How would you do this? I have not found anything about this in the docs. I am confused about that because it seems like many people would want to do that and there should be some kind of standard solution to this. Or am I getting the whole workflow wrong?
I should note that I'm not expecting a step-by-step guide. I am just trying to understand the concept.
Assuming you already have your deployment server setup, and all you need to do is push code to your server, then you can just use git as a form of deployment.
Digital Ocean has a good tutorial at this link https://www.digitalocean.com/community/tutorials/how-to-set-up-automatic-deployment-with-git-with-a-vps
Push sources to a git repository from a dev machine.
pull sources on a production server. Restart uwsgi/whatever.
There is no standard way of doing this, so no, it cannot be included with Django or be thoroughly described in the docs.
If you're using a PaaS how you deploy depends on the PaaS. Ditto for a container like docker, you must follow the rules of that particular container.
If you're old-school and can ssh into a server you can rsync a snapshot of the code to the correct place after everything else is taken care of: database, ports, webserver setup etc. That's what I do, and I control stuff with bash scripts utilizing a makefile.
REMOETHOST=user#yourbox
REMOTEPATH=yourpath
REMOTE=$REMOTEHOST:$REMOTEPATH
make rsync REMOTE_URI=$REMOTE
ssh $REMOTEHOST make -C $REMOTEPATH deploy
My "deploy"-action is a monster but might be as easy as something that touches the wsgi-file used in order to reload the site. My medium complex ones cleans out stale files, run collectstatic and then reloads the site. The really complex ones creates a timestamped virtualenv, cloned database and remote code tree, a new server-setup that points to this, runs connection tests on the remote and if they succeed, switches the main site to point to the new versioned site, then emails me the version that is now in production, with the git hash and timestamp.
Lots of good solutions. Heroku has a good tutorial: https://devcenter.heroku.com/articles/getting-started-with-django
Check out a general guide for deploying to multiple PaaS providers here: http://www.paascheatsheet.com