Skip to content

This is starting point for a Docker powered Django Backend + FrontEnd Polymer Web Project

License

Notifications You must be signed in to change notification settings

JTarball/docker-django-polymer-starter-kit

Repository files navigation

Circle CI

A Django project.

Current Integrated Version/s

Django Polymer start project using Docker

Intro

This is a quick fire starter kit for getting a Docker Web project up and running. Django web framework is used for the backend essentially making it a REST API. Google Polymer is used for the frontend.

This project integrates generator-polymer project with a dockerized django app.

Cheatsheet

Rebuild and Upload base image

Useful Commands

docker login

  • you will need to login into docker hub (set up an account if you dont have one) docker build -t "<IMAGE>" .
  • this will build the Dockerfile in the current directory and tag it with "jtarball/docker-base:latest" docker push "<IMAGE>"
  • push to docker hub docker-compose up
  • this command will create and start containers docker rm $(docker ps -a -q); docker rmi $(docker images -q);
  • kill and remove all docker images and containers docker rmi $(docker images -q --filter "dangling=true")
  • Ckean up un-tagged docker images

How to use

  1. Install Polymer FrontEnd Components npm install -g gulp bower && npm install && bower install docker-compose run app --create set up databases / initial migrations / ... docker-compose up -d

How to deploy to Amazon Web Services

  1. Get AWS Access Key, AWS Secret Access Key & AWS VPC IPD
  1. Ensure environment variables are set To deploy this project to AWS you must set the following environment variables:
  • DOCKERHUB_USER
  • AWS_ACCESS_KEY_ID
  • AWS_SECRET_ACCESS_KEY
  • AWS_VPC_ID
export DOCKERHUB_USER=jtarball
export AWS_ACCESS_KEY_ID=xxxxxx
export AWS_SECRET_ACCESS_KEY=xxxxxx
export AWS_VPC_ID=xxxx
  1. Create Docker Machine (Only if needs to be created - so only once) create-docker-machine-aws.sh <MACHINE_NAME> where MACHINE_NAME is the name for the machine you want created

python build-tag-push.py which will build the docker app, push it to docker hub and a new compose yml file (you will need to be logged in docker login)

Directory Structure

License

View license information for the software contained in this image.

User Feedback

Any feedback or comments would be greatly appreciated: james.tarball@gmail.com

Issues

If you have any problems with or questions about this image, please contact us through a GitHub issue.

You can also reach me by email. I would be happy to help james.tarball@gmail.com

Developer Notes

#### How to upgrade base directory

Considerations / Future Work

Tutorial

Layers

The versioned filesystem in Docker is based on layers. They're like git commits or changesets for filesystems.

Note that if you're using aufs as your filesystem, Docker does not always remove data volumes containers layers when you delete a container! See PR 8484 for more details.

Links

Links are how Docker containers talk to each other through TCP/IP ports. Linking into Redis and Atlassian show worked examples. You can also (in 0.11) resolve links by hostname.

NOTE: If you want containers to ONLY communicate with each other through links, start the docker daemon with -icc=false to disable inter process communication.

If you have a container with the name CONTAINER (specified by docker run --name CONTAINER) and in the Dockerfile, it has an exposed port:

EXPOSE 1337

Todo

  • create repo docker-base

  • sublink to generator-dockerized django-polymer

  • add comments to explain

  • need to separate

Docker Image

base

  • this has been included if required custom modification (from docker-base in github)

  • has some dependencies when called (requirements etc)

  • app

  • derived from docker-base:latest from docker hub ( 'docker-base' automated build via docker hub to keep up to date )

  • requires manual build, tagging & deployment

  • why not automated build via docker hub ---- more flexibility without, need a different .yml for production etc.

How to get started

Docker Images explained

App Docker Image

  • use a base image - dockerfile and stuff included in case you want to see - automated build so always latest
  • app manual updates

Docker linguistics borrow from git terminology, but it’s rather dangerous to interpret these too literally. Keeping a clean docker environment

run interactive containers with --rm flag to avoid having to remove them later.

Remove all stopped containers:

Clean up un-tagged docker images: docker rmi $(docker images -q --filter "dangling=true") Stop and remove all containers (including running containers!) Docker and Continuous Integration

docker stop $(docker ps -a -q); docker rm $(docker ps -a -q); docker rmi $(docker images -q);

docker run -v /Users/danvir/Masterbox/sideprojects/github/docker-django-polymer/app_mount:/app -i -t dockerdjangopolymer_app_1

Run tests on app

py.test --ds=project.settings.test REUSE_DB=0 python manage.py test --settings=project.settings.test -s --with-queries blog

AWS EB

https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/

NPM version NPM downloads Build Status Dependency Status

Introduction to generator-django-polymer

Yeoman generator that scaffolds out a Django project with Polymer.

This generator extends generator-polymer and integrates it with a Django project generator

Why extend generator-polymer?

Google Polymer is an awesome framework leveraging the new standards of web components however it is still a relatively new framework.

As of yet it has even reached version 1.0 likely to change which will have a knock on effect to the best standards and practices for Polymer project layouts/scaffolds.

Thus this generator project will periodically integrate new changes from generator-polymer to incorporate the latest changes, methods and best practices

This currently is a better solution than creating a rigid custom layout for a Polymer compatible app which may change.

How is Django and Polymer integrated in this project?

This is likely to be the more important question when deciding whether to use this generator or not.

Main points:

  • The output of generator-polymer is kept largerly intact.
  • We symbolic link all polymer elements to Django's static folder.
  • Routing is still performed by Django's urls
  • Django templating is still used but is minimally required with a project like this compared to a standard Django project. See generated output for example on use.
  • Where conflicts exist in templating we use the verbatim django tag.

Thus, we get a project that has all the benefits of a polymer frontend app as well as all the benefits of Django's backend environment including urls, templating etc. without having to interleave both projects in a complex way.

in theory, if you decided that Polymer was not for you; removing it without affecting the Django project should be easy.

Directory Structure

The settings files are split for better separate of roles:

  • README.md

this file

  • app/

this is created by generator-polymer Do not move or rename to keep compatible with polymer generator commands

  • bower_components

this folder is also created by generator-polymer

  • apps/

Django apps folder

  • project/

Django Project folder

  • tests/

Unit tests folder

  • Gulpfile.js | Gruntfile.js | etc. ...

optional files created by generator-polymer

Developer Notes

How to update base docker image 'docker-base'

From docker directory run:

git submodule update --remote --merge 

Considerations / Future

In the future I might consider incorporating ideas from the following projects:

e.g. caching, sendGrid email support, heroku, better management

About

This is starting point for a Docker powered Django Backend + FrontEnd Polymer Web Project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published