Skip to content

Commit

Permalink
Merge pull request #94 from Osmose/docker-fig
Browse files Browse the repository at this point in the history
Add files and documentation for running the site using docker and fig.
  • Loading branch information
glogiotatidis committed Feb 9, 2015
2 parents 33d7957 + d01fb79 commit 68406da
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 9 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:2.7
RUN apt-get update && apt-get install -y libmysqlclient-dev gettext libjpeg62-turbo-dev

WORKDIR /app

# First copy requirements.txt and peep so we can take advantage of
# docker caching.
COPY requirements /tmp/requirements
RUN pip install -r /tmp/requirements/dev.txt

EXPOSE 8000
ENV PYTHONUNBUFFERED 1
3 changes: 3 additions & 0 deletions bin/run-fig.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

./manage.py runserver 0.0.0.0:8000
3 changes: 3 additions & 0 deletions bin/run-migrations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
./manage.py syncdb
./manage.py migrate
57 changes: 49 additions & 8 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
Contributing
============

Developer Setup
---------------
Docker Setup
------------

These instructions assume you have ``git`` and ``pip`` installed. If you don't
have ``pip`` installed, you can install it with ``easy_install pip``.
These instructions help you set up a copy of the site using `Docker`_ and
`fig`_.

1. `Install Docker <https://docs.docker.com/installation/#installation>`_.

2. `Install fig <http://www.fig.sh/install.html>`_.

3. Grab the source code using git::

$ git clone --recursive git://github.com/mozilla/snippets-service.git
$ cd snippets-service

.. note:: Make sure you use ``--recursive`` when checking the repo out! If you
didn't, you can load all the submodules with ``git submodule update --init
--recursive``.

4. Build the Docker containers using fig::

$ fig build

5. Run the database migrations to set up the database::

$ fig run web ./bin/run-migrations.sh

Once you've finished these steps, you should be able to start the site by
running::

$ fig up

If you're running Docker directly (via Linux), the site should be available at
http://localhost:8000. If you're running `boot2docker`_, the site should be
available on port 8000 at the IP output by running::

$ boot2docker ip

.. _Docker: https://docs.docker.com/
.. _fig: http://www.fig.sh/
.. _boot2docker: http://boot2docker.io/

Local Instance Setup
--------------------

These instructions will set up an instance of the website running on your
computer directly, and assume you have ``git`` and ``pip`` installed. If you
don't have ``pip`` installed, you can install it with ``easy_install pip``.

1. Start by getting the source::

Expand Down Expand Up @@ -47,9 +90,7 @@ have ``pip`` installed, you can install it with ``easy_install pip``.
.. _MySQL Installation Documentation: http://dev.mysql.com/doc/refman/5.6/en/installing.html


Running the Development Server
------------------------------

You can launch the development server like so::
Once you've followed the steps above, you can launch the development server
like so::

$ python manage.py runserver
19 changes: 19 additions & 0 deletions fig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
db:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=asdf
- MYSQL_USER=snippets
- MYSQL_PASSWORD=asdf
- MYSQL_DATABASE=snippets
web:
build: .
ports:
- "8000:8000"
volumes:
- .:/app
links:
- db
environment:
- PYTHONDONTWRITEBYTECODE=1
- DOCKER=1
command: ./bin/run-fig.sh
1 change: 0 additions & 1 deletion requirements/compiled.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#-r ../vendor/src/funfactory/funfactory/requirements/compiled.txt
MySQL-python==1.2.3c1
Jinja2==2.5.5

Expand Down
3 changes: 3 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ nose==1.0.0

# L10n
translate-toolkit==1.8.0

# Etc.
six
2 changes: 2 additions & 0 deletions snippets/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# Load special settings for CI.
if os.environ.get('TRAVIS'):
from .travis import *
elif os.environ.get('DOCKER'):
from .docker import *
else:
try:
from .local import *
Expand Down
42 changes: 42 additions & 0 deletions snippets/settings/docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from . import base

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'snippets',
'USER': 'snippets',
'PASSWORD': 'asdf',
'HOST': 'db',
'PORT': '',
'OPTIONS': {
'init_command': 'SET default_storage_engine=InnoDB',
'charset' : 'utf8',
'use_unicode' : True,
},
'TEST_CHARSET': 'utf8',
'TEST_COLLATION': 'utf8_general_ci',
},
}

DEBUG = TEMPLATE_DEBUG = True

HMAC_KEYS = {
'2012-06-06': 'some secret',
}

from django_sha2 import get_password_hashers
PASSWORD_HASHERS = get_password_hashers(base.BASE_PASSWORD_HASHERS, HMAC_KEYS)

# Make this unique, and don't share it with anybody. It cannot be blank.
SECRET_KEY = 'dev'

# Should robots.txt allow web crawlers? Set this to True for production
ENGAGE_ROBOTS = True

SESSION_COOKIE_SECURE = False

# Snippets-specific caching
SNIPPET_HTTP_MAX_AGE = 90 # Time to cache HTTP responses for snippets.

# Replace with site protocol, domain, and (optionally) port.
SITE_URL = 'http://docker:8000'

0 comments on commit 68406da

Please sign in to comment.