Skip to content

getslideapp/django-starter

 
 

Repository files navigation

Django starter project

Local development

  1. Set up a python virtual environment. E.g. with Anaconda: conda create -n django-starter python=3.5
    source activate django-starter
    pip install -r requirements.txt

If psycopg2 installation fails to install, try conda install psycopg2==2.6.2

  1. Install invoke and related libraries in your virtual environment (you can do this in a separate environment if you prefer):
    pip install invoke python-dotenv fabric3 pyyaml semver

  2. Add the project name and details to as well as the virtual environment path to local.yaml. For Anaconda, if you don't know the path to your virtual environment, you can run which python from within your virtual environment to find your virtual environment path.

  3. Use .local.env.example as a template to create a .local.env with the project environmental variables.

  4. To generate a key use python -c "import string,random; uni=string.ascii_letters+string.digits+string.punctuation; print repr(''.join([random.SystemRandom().choice(uni) for i in range(random.randint(45,50))]))"

  5. Start the postgres database:
    inv local.compose -c 'up -d postgres'

  6. Check if Docker is running: docker ps or inv local.compose -c ps

  7. Migrate database: inv local.manage migrate

  8. Start the webserver on port 8000:
    inv local.manage 'runserver --insecure'

Automated Deployment:

TODO

Manual deployment:

Push to container registry:

  1. Build the static webserver:
    inv k8s.build -c production -v v0.001
  2. Deploy to Kubernetes Cluster:
    inv deploy -c production.yaml -v v0.001 .

Once-off build-server setup:

  1. Provision the virtual machine:
    fab -f ./etc/base_image/server/fabric_tasks.py create:provider='digitalocean'
  2. Add the machine to your SSH config fab -f ./etc/base_image/server/fabric_tasks.py add
    fab -f ./etc/base_image/server/fabric_tasks.py install fab -f ./etc/base_image/server/fabric_tasks.py factory

Once-off Kubernetes Cluster Setup:

  1. Create a Kubernetes Cluster
  2. Athenticate gcloud:
    gcloud auth login
    gcloud config set project {project-name}
  3. Connect to kubernetes cluster:
    gcloud container clusters get-credentials {cluster-name} --zone us-west1-a --project {project-name}
  4. Letsencrypt SSL setup:
    kubectl apply -f etc/k8s/lego/00-namespace.yaml && kubectl apply -f etc/k8s/lego/configmap.yaml && kubectl apply -f etc/k8s/lego/deployment.yaml
  5. Webserver setup:
    inv templater production (templater is not yet very smart. you will need to manually configure things like multiple domains) inv setup production
  6. Check the external IP address and setup DNS:
    inv ip production

About

Example Django project set up for Docker, Kubernetes and Pg-pool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 97.9%
  • HTML 2.1%