Running Django's createsuperuser in Google Cloud Run - django

I'm trying to run a Django app on Google Cloud Run. The site itself works nicely, can run migrations and collect static assets via a startup script. The one thing I cannot figure out how to do is create a superuser. This requires interactively typing in a password or at least setting it via a django shell. I currently cannot figure out how to do this and it seems like it might not be possible; which would make Cloud Run unusable for Django. Has anyone been able to achieve this or have a sustainable workaround? Thanks!

Instead of Django Shell use the api to create the superuser. Once you have the script make it part of the container build process.

Related

How to set virtualenv to stay active on a host server

I created a website that uses vuejs as the frontend and django as the backend with another service running behind everything that im making api calls to.
So django is setup in a way to look at the dist folder of Vuejs and serve it if you run manage.py runserver. but the problem is that my service that I created is
is also in python and it needs to run in a virtualenv in order to work (It uses tensorflow 1.15.2 and this can only run in a contained environment)
I'm sitting here and wondering how I can deploy the django application and keep the virtualenv active and Im coming up with nothing, I've tried doing some research on this but everything I found was not relevant to my problem. I've deployed it and when I close the ssh connection the virtualenv stops.
If there is anyone that can enlighten my ways I would appreciate it.
i think you need to nginx: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
if you are search for keep states just in terminal i suggest tmux https://github.com/tmux/tmux/wiki
You can use uWSGI and nginx to deploy Django apps on server. Here's helpful articles:
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
Django official docs also has a page about it: https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/uwsgi/
There are articles from developers so you can refer them in case you get stuck anywhere:
https://www.freecodecamp.org/news/django-uwsgi-nginx-postgresql-setup-on-aws-ec2-ubuntu16-04-with-python-3-6-6c58698ae9d3/
https://medium.com/#biswashirok/deploying-django-python-3-6-to-digital-ocean-with-uwsgi-nginx-ubuntu-18-04-3f8c2731ade1

Django un Azure Webapp: Run command on deployment

I am deploying a Django app to Azure Webapp, which does everything automatically. I have set it up so when I push to a specific Github branch, it is deployed and everything works. If I have to run a migration, I must login via SSH and run it manually (which is not perfect but I can accept it).
However, I need to use django-background-tasks, which needs to have a command running constantly listen for new tasks. I can't find a way to run this on every deployment. I found some documentation but most of it is for Node apps, it seems. For example, following some (oudated) tutoriales, I logged into {myapp}.scm.azurewebsites.net but I didnt find any "Download deployment scripts", which it seemed to be the proper way to do it.
Is there a way to set up some commands to run on deployment (without changing my current setup of deploy directly from Github using Github actions)? Or I have to do it manually?
Well, if someone is looking how to do it, I found the solution.
Create a startup file (sh), add the first line the gunicorn instruction and after that your own custom commands.
Here is explained: https://learn.microsoft.com/en-us/azure/developer/python/tutorial-deploy-app-service-on-linux-04#create-a-startup-file

Permanent Superuser Django Docker

So, I have a dockerfile that I run Django via CapRover to run the backend of my website. Amongst the components, I have an admin panel that I log into using a superuser that I've created by ssh-ing into the docker container. The problem is that whenever I change my backend by uploading it as a .tar via CapRover, I have to create my superuser again.
My question is, is there any way to avoid this by creating some sort of persistance? Or is there any way of automating this via my dockerfile?
Thanks!

Basic cookiecutter-flask implementation

So I have got my app up and running. However it still runs off the cmd console at the moment. Next steps is for me to build a simple web app interface.
After much research, rather than to setup an entire flask site from scratch. I decided to use cookiecutter-flask from https://github.com/konstantint/cookiecutter-flask boilerplate to quickly get the boilerplate up and running.
Everything looks good in a sense where I understand:
Templating
App function
Static
I still cannot figure out how to get the user registration function working. I keep getting a wsgi error. I know is somewhat related to my database not being installed.
Not specific to that, what I am really looking for is a walk through tutorial on how to get it working by bare minimum and then enhance from there.
I have been looking around for tutorials and walk through but to no avail.
Appreciate any help out there.
After clone you have to do these steps ... These will create the database tables for you...
python manage.py db init
python manage.py db migrate
python manage.py db upgrade
python manage.py server

django command does it require django server must be running?

I have introduced a new django command which i can run from cronjob. This is particulary helpful to get ORM specification.
To Run this django command, do we need the django server should be running ?
No, the django server is a separate process completly independent from your custom command.
If you are using virtualenv (if you aren't yo probably should) keep in mind you must source the virtualenv or use the python interpreter within it in order to get the managemente command properly run.