├── api ├── films │ ├── __init__.py │ ├── migrations │ │ ├── __init__.py │ │ └── 0001_initial.py │ ├── tests.py │ ├── apps.py │ ├── admin.py │ ├── models.py │ ├── serializers.py │ ├── views.py │ ├── fixtures │ │ └── films.json │ └── urls.py ├── project │ ├── __init__.py │ ├── wsgi.py │ ├── urls.py │ └── settings.py ├── requirements.txt ├── manage.py ├── start.sh └── Dockerfile ├── .gitignore ├── db ├── Dockerfile └── setup.sh ├── README.md ├── runInDevMode └── eco └── backend └── docker-compose.yml /api/films/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /api/project/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /api/films/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | __pycache__ 3 | -------------------------------------------------------------------------------- /api/films/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /db/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM postgres:9.4 2 | 3 | COPY setup.sh /docker-entrypoint-initdb.d/ 4 | 5 | -------------------------------------------------------------------------------- /api/requirements.txt: -------------------------------------------------------------------------------- 1 | django==1.9.1 2 | psycopg2==2.6.1 3 | djangorestframework==3.3.2 4 | django-environ==0.4.0 -------------------------------------------------------------------------------- /api/films/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class FilmsConfig(AppConfig): 5 | name = 'films' 6 | -------------------------------------------------------------------------------- /db/setup.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | createuser -U postgres --createdb --createrole dbuser; 4 | createdb -U dbuser films; 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Demo Docker app. 2 | 3 | ``` 4 | git clone git@github.com:jdelight/docker-rancher.git 5 | cd docker-rancher 6 | ./runInDevMode 7 | ``` 8 | 9 | -------------------------------------------------------------------------------- /api/films/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from films.models import Film 3 | 4 | 5 | @admin.register(Film) 6 | class FilmAdmin(admin.ModelAdmin): 7 | pass 8 | 9 | 10 | -------------------------------------------------------------------------------- /runInDevMode: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # create the dbdata volume 4 | docker volume create --name=dbdata 5 | 6 | # start the applications on the backend network 7 | cd ./eco/backend/ && docker-compose --x-networking up -------------------------------------------------------------------------------- /api/films/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Film(models.Model): 5 | title = models.CharField(max_length=100) 6 | 7 | def __str__(self): 8 | return '{0}'.format(self.title) 9 | 10 | -------------------------------------------------------------------------------- /api/films/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from films.models import Film 3 | 4 | 5 | class FilmSerializer(serializers.ModelSerializer): 6 | class Meta: 7 | model = Film 8 | fields = ('id', 'title') 9 | 10 | -------------------------------------------------------------------------------- /api/films/views.py: -------------------------------------------------------------------------------- 1 | from films.models import Film 2 | from films.serializers import FilmSerializer 3 | from rest_framework import generics 4 | 5 | 6 | class FilmList(generics.ListAPIView): 7 | queryset = Film.objects.all() 8 | serializer_class = FilmSerializer 9 | -------------------------------------------------------------------------------- /api/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import sys 4 | 5 | if __name__ == "__main__": 6 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") 7 | 8 | from django.core.management import execute_from_command_line 9 | 10 | execute_from_command_line(sys.argv) 11 | -------------------------------------------------------------------------------- /eco/backend/docker-compose.yml: -------------------------------------------------------------------------------- 1 | api: 2 | build: ../../api 3 | ports: 4 | - "8000:8000" 5 | volumes: 6 | - ../../api:/var/www/app 7 | tty: true 8 | command: /var/www/app/start.sh 9 | 10 | db: 11 | build: ../../db 12 | volumes: 13 | - dbdata:/var/lib/postgresql/data 14 | 15 | -------------------------------------------------------------------------------- /api/start.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | source ~/.bashrc 4 | 5 | # Wait for the db service to be ready before continuing 6 | echo "waiting for db..." 7 | while ! nc -w 1 -z backend_db_1 5432 2>/dev/null; 8 | do 9 | echo -n . 10 | sleep 1 11 | done 12 | 13 | echo "db ready" 14 | 15 | python manage.py migrate 16 | 17 | python manage.py loaddata films 18 | 19 | python manage.py runserver 0.0.0.0:8000 -------------------------------------------------------------------------------- /api/project/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for project project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings") 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /api/films/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.9.1 on 2016-01-27 08:14 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | initial = True 11 | 12 | dependencies = [ 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='Film', 18 | fields=[ 19 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 20 | ('title', models.CharField(max_length=100)), 21 | ], 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /api/films/fixtures/films.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "model": "films.film", 4 | "pk": 1, 5 | "fields": { 6 | "title": "Steve Jobs" 7 | } 8 | }, 9 | { 10 | "model": "films.film", 11 | "pk": 2, 12 | "fields": { 13 | "title": "Inside Out" 14 | } 15 | }, 16 | { 17 | "model": "films.film", 18 | "pk": 3, 19 | "fields": { 20 | "title": "The Revenant" 21 | } 22 | }, 23 | { 24 | "model": "films.film", 25 | "pk": 4, 26 | "fields": { 27 | "title": "Spectre" 28 | } 29 | }, 30 | { 31 | "model": "films.film", 32 | "pk": 5, 33 | "fields": { 34 | "title": "The Martian" 35 | } 36 | }, 37 | { 38 | "model": "films.film", 39 | "pk": 6, 40 | "fields": { 41 | "title": "Jurassic World" 42 | } 43 | } 44 | ] -------------------------------------------------------------------------------- /api/films/urls.py: -------------------------------------------------------------------------------- 1 | """project URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.9/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import url 17 | from films import views 18 | 19 | film_urls = [ 20 | url(r'^films/', views.FilmList.as_view()), 21 | ] 22 | -------------------------------------------------------------------------------- /api/project/urls.py: -------------------------------------------------------------------------------- 1 | """project URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/1.9/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.conf.urls import url, include 14 | 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 | """ 16 | from django.conf.urls import url, include 17 | from django.contrib import admin 18 | from films.urls import film_urls 19 | 20 | 21 | urlpatterns = [ 22 | url(r'^admin/', admin.site.urls), 23 | url(r'^api/', include(film_urls)), 24 | ] 25 | -------------------------------------------------------------------------------- /api/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.4-slim 2 | 3 | ENV WORKON_HOME=~/envs 4 | 5 | # May not need this - but I had some issues with a Debian mirror not responding 6 | # and added another as a fallback 7 | RUN echo "deb http://ftp.uk.debian.org/debian jessie main" >> /etc/apt/sources.list 8 | 9 | RUN apt-get update && apt-get install -y \ 10 | gcc \ 11 | gettext \ 12 | postgresql-client \ 13 | libpq-dev \ 14 | netcat \ 15 | --no-install-recommends && rm -rf /var/lib/apt/lists/* \ 16 | && pip install virtualenvwrapper \ 17 | && mkdir -p $WORKON_HOME \ 18 | && mkdir -p /var/www/app \ 19 | && echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc 20 | 21 | EXPOSE 8000 22 | 23 | WORKDIR /var/www/app 24 | 25 | COPY requirements.txt /var/www/app 26 | 27 | RUN /bin/bash --login -c "mkvirtualenv -a /var/www/app -r requirements.txt app" \ 28 | && echo "workon app" >> ~/.bashrc 29 | 30 | COPY . /var/www/app 31 | 32 | CMD [] -------------------------------------------------------------------------------- /api/project/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for project project. 3 | 4 | Generated by 'django-admin startproject' using Django 1.9.1. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/1.9/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/1.9/ref/settings/ 11 | """ 12 | 13 | import os 14 | import sys 15 | 16 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 17 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 18 | 19 | sys.path.append(BASE_DIR) 20 | 21 | # Quick-start development settings - unsuitable for production 22 | # See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ 23 | 24 | # SECURITY WARNING: keep the secret key used in production secret! 25 | SECRET_KEY = '60_=pd!pu1e9f@f4o0@-6(su96z$wwmysqyl1sb_mi!q(cz8h0' 26 | 27 | # SECURITY WARNING: don't run with debug turned on in production! 28 | DEBUG = True 29 | 30 | ALLOWED_HOSTS = [] 31 | 32 | 33 | # Application definition 34 | 35 | INSTALLED_APPS = [ 36 | 'django.contrib.admin', 37 | 'django.contrib.auth', 38 | 'django.contrib.contenttypes', 39 | 'django.contrib.sessions', 40 | 'django.contrib.messages', 41 | 'django.contrib.staticfiles', 42 | 'rest_framework', 43 | 'films', 44 | ] 45 | 46 | MIDDLEWARE_CLASSES = [ 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'django.middleware.common.CommonMiddleware', 50 | 'django.middleware.csrf.CsrfViewMiddleware', 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 52 | 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 53 | 'django.contrib.messages.middleware.MessageMiddleware', 54 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 55 | ] 56 | 57 | ROOT_URLCONF = 'project.urls' 58 | 59 | TEMPLATES = [ 60 | { 61 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 62 | 'DIRS': [], 63 | 'APP_DIRS': True, 64 | 'OPTIONS': { 65 | 'context_processors': [ 66 | 'django.template.context_processors.debug', 67 | 'django.template.context_processors.request', 68 | 'django.contrib.auth.context_processors.auth', 69 | 'django.contrib.messages.context_processors.messages', 70 | ], 71 | }, 72 | }, 73 | ] 74 | 75 | WSGI_APPLICATION = 'project.wsgi.application' 76 | 77 | 78 | # Database 79 | # https://docs.djangoproject.com/en/1.9/ref/settings/#databases 80 | 81 | DATABASES = { 82 | 'default': { 83 | 'ENGINE': 'django.db.backends.postgresql', 84 | 'NAME': 'films', 85 | 'USER': 'dbuser', 86 | 'PASSWORD': '', 87 | 'HOST': 'backend_db_1', 88 | 'PORT': '5432', 89 | } 90 | } 91 | 92 | 93 | # Password validation 94 | # https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators 95 | 96 | AUTH_PASSWORD_VALIDATORS = [ 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 99 | }, 100 | { 101 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 102 | }, 103 | { 104 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 105 | }, 106 | { 107 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 108 | }, 109 | ] 110 | 111 | 112 | # Internationalization 113 | # https://docs.djangoproject.com/en/1.9/topics/i18n/ 114 | 115 | LANGUAGE_CODE = 'en-us' 116 | 117 | TIME_ZONE = 'UTC' 118 | 119 | USE_I18N = True 120 | 121 | USE_L10N = True 122 | 123 | USE_TZ = True 124 | 125 | 126 | # Static files (CSS, JavaScript, Images) 127 | # https://docs.djangoproject.com/en/1.9/howto/static-files/ 128 | 129 | STATIC_URL = '/static/' 130 | --------------------------------------------------------------------------------