#59 Docker development environment
Merged 5 years ago by algogator. Opened 5 years ago by echoduck.
fedora-commops/ echoduck/fedora-happiness-packets dockerfile  into  master

file added
+27
@@ -0,0 +1,27 @@ 

+ FROM python:2-alpine

+ 

+ #Install required system packages

+ RUN apk add --update --no-cache build-base bash readline libffi-dev ncurses-dev openssl-dev

+ 

+ # Install required Python packages

+ COPY ./requirements /requirements

+ RUN pip install -r /requirements/dev.txt

+ 

+ # Set correct DJANGO_SETTINGS_MODULE

+ ENV DJANGO_SETTINGS_MODULE=happinesspackets.settings.dev

+ 

+ # Copy project files into container

+ COPY . /

+ 

+ 

+ # Check if client_secrets.json is present, and generate if not

+ RUN apk add --update --no-cache curl

+ RUN chmod +x generate_client_secrets.sh

+ RUN ./generate_client_secrets.sh

+ 

+ RUN ./manage.py collectstatic --noinput

+ RUN python manage.py migrate

+ 

+ # Expose Django port

+ EXPOSE 8000 

+ 

file modified
+9 -21
@@ -4,39 +4,27 @@ 

  

  # Setup

  

- To run this project or the tests, you need to set up a virtualenv, install the dev requirements and set

- the correct ``DJANGO_SETTINGS_MODULE``, for example with::

- 

-     virtualenv --no-site-packages --prompt='(happinesspackets)' virtualenv/

-     source virtualenv/bin/activate

-     pip install -r requirements/dev.txt

-     export DJANGO_SETTINGS_MODULE=happinesspackets.settings.dev

- 

- Before running the server locally, you must collect all the static files and perform a database migration.

- 

-     ./manage.py collectstatic

-     python manage.py migrate

+ Make sure you have Docker and Docker Compose installed.

  

  In order for the login and send views to work, you must supply an OpenID Connect Client ID and Client Secret:

  

-     oidc-register https://iddev.fedorainfracloud.org/openidc/ http://localhost:8000/oidc/callback/ 

+     chmod +x generate_client_secrets.sh 

+     ./generate_client_secrets.sh 

  

- ``oidc-register`` outputs to ``client_secrets.json``. Export the client ID as ``OIDC_RP_CLIENT_ID`` and the secret as ``OIDC_RP_CLIENT_SECRET``

-     

-     export OIDC_RP_CLIENT_ID=<client id>

-     export OIDC_RP_CLIENT_SECRET=<client secret>

+ To run on http://localhost:8000/ :

  

- To run on http://127.0.0.1:8000/ :

+     docker-compose up

  

-     python manage.py runserver

+ After making any changes to the code, make sure to rebuild the container:

  

- Don't forget to start the mail server:

+     docker-compose up --build

  

-     python -m smtpd -n -c DebuggingServer localhost:2525

  

  The ``t`` command is a very short shell script that runs the tests with the correct settings and reports on coverage.

  

  To run it:

+     

+     docker-compose exec web sh

      ./t

  

  To run the integration tests::

file added
+18
@@ -0,0 +1,18 @@ 

+ version: "3"

+ services:

+   web:

+     build: .

+     command: python manage.py runserver 0.0.0.0:8000

+     ports:

+       - "8000:8000"

+     links:

+       - redis

+   redis:

+     image: redis:alpine

+     ports:

+       - "6379:6379"

+   celery:

+     build: .

+     command: celery worker -A happinesspackets -l info

+     links:

+       - redis

@@ -0,0 +1,7 @@ 

+ #!/bin/sh

+ if [ ! -f "client_secrets.json" ] 

+ then

+ 	echo "client_secrets.json not found, generating..."

+  	curl --request POST --header "Content-Type: application/json" --data '{"redirect_uris": ["http://localhost:8000/oidc/callback/"], "application_type": 

+ "native","token_endpoint_auth_method": "client_secret_post"}' https://iddev.fedorainfracloud.org/openidc/Registration -o client_secrets.json

+ fi

@@ -1,1 +1,9 @@ 

+ from __future__ import absolute_import, unicode_literals

+ 

+ # This will make sure the app is always imported when

+ # Django starts so that shared_task will use this app.

+ from happinesspackets._celery import app as celery_app

+ 

+ __all__ = ('celery_app',)

+ 

  __author__ = 'erik'

file modified
+2 -1
@@ -1,10 +1,11 @@ 

+ from __future__ import absolute_import

  import os

  from celery import Celery

  

  os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'happinesspackets.settings')

  

  app = Celery('happinesspackets')

- app.config_from_object('django.conf:settings')

+ app.config_from_object('django.conf:settings', namespace='CELERY')

  

  # Load task modules from all registered Django app configs.

  app.autodiscover_tasks()

@@ -1,5 +1,7 @@ 

  # -*- coding: utf-8 -*-

  # noinspection PyUnresolvedReferences

+ import json

+ 

  from .base import *  # noqa

  

  DEBUG = True
@@ -13,13 +15,18 @@ 

      }

  }

  

- # EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

- EMAIL_HOST = 'localhost'

- EMAIL_PORT = 2525

+ EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" 

+ 

+ 

  SECRET_KEY = 'only-for-testing'

  

  INTERNAL_IPS = ('127.0.0.1',)

  

+ DEBUG_TOOLBAR_CONFIG = {

+     "SHOW_TOOLBAR_CALLBACK" : lambda request: DEBUG,

+ }

+ 

+ 

  SECURE_SSL_REDIRECT = False

  SESSION_COOKIE_SECURE = False

  CSRF_COOKIE_SECURE = False
@@ -42,3 +49,17 @@ 

  )

  

  SELENIUM_SCREENSHOT_DIR = PROJECT_DIR.child('selenium-screenshots')

+ 

+ 

+ # Uses a separate Docker container to act as the Redis server

+ CELERY_BROKER_URL = 'redis://redis:6379/0'

+ CELERY_RESULT_BACKEND = 'redis://redis:6379/0'

+ 

+ # Loads OIDC Client ID and Secret from client_secrets.json

+ 

+ with open("client_secrets.json") as f:

+     secrets = json.load(f)

+     OIDC_RP_CLIENT_ID = secrets["client_id"]

+     OIDC_RP_CLIENT_SECRET = secrets["client_secret"]

+ 

+ 

Introduces a simplified development environment using Docker and docker-compose.

1 new commit added

  • Added wrapper script to detect if client_secrets.json is present, and to generate it if not.
5 years ago

Pull-Request has been merged by algogator

5 years ago