These instructions assume you have git and pip installed. If you don’t have pip installed, you can install it with easy_install pip.
Start by getting the source:
$ git clone --recursive git://github.com/mozilla/bedrock.git $ cd bedrock
(Make sure you use –recursive so that legal-docs are included)
You need to create a virtual environment for Python libraries. Skip the first instruction if you already have virtualenv installed:
$ pip install virtualenv # installs virtualenv, skip if already have it $ virtualenv -p python2.7 venv # create a virtual env in the folder `venv` $ source venv/bin/activate # activate the virtual env $ pip install -U pip # securely upgrade pip $ pip install -r requirements/test.txt # installs dependencies
If you are on OSX and some of the compiled dependencies fails to compile, try explicitly setting the arch flags and try again:
$ export ARCHFLAGS="-arch i386 -arch x86_64" $ pip install -r requirements/test.txt
If you are on Linux, you will need at least the following packages or their equivalent for your distro:
Now configure the application to run locally by creating your local settings environment file:
$ cp .env-dist .env
You shouldn’t need to customize anything in there yet.
Sync the database and all of the external data locally. This gets product-details, security-advisories, credits, release notes, etc:
$ npm install
You may also need to install the Gulp cli globally.
Run the tests¶
We’re working on fixing this, but for now you need the localization files for the tests to pass. See the Localization section below for instructions on checking those out.
Now that we have everything installed, let’s make sure all of our tests pass. This will be important during development so that you can easily know when you’ve broken something with a change. You should still have your virtualenv activated, so running the tests is as simple as:
$ py.test lib bedrock
To test a single app, specify the app by name in the command above. e.g.:
$ py.test lib bedrock/firefox
If your local tests run fine, but when you submit a pull-request the tests fail in
CircleCI, it could be due to the
difference in settings between what you have in
and what CircleCI uses:
docker/envfiles/demo.env. You can run tests as close to Circle
as possible by moving your
.env file to another name (e.g.
.env, and running tests again.
Make it run¶
To make the server run, make sure you are inside a virtualenv, and then run the server:
$ ./manage.py runserver
If you are not inside a virtualenv, you can activate it by doing:
$ source venv/bin/activate
If you get the error “NoneType is not iterable”, you didn’t check out the latest product-details. See the above section for that.
Next, in a new terminal tab run gulp to watch for local file changes:
If you have problems with gulp, or you for some reason don’t want to use it you can set:
.env file or otherwise set it in your environment and it will collect media for you as you make changes. The reason that this is not the preferred method is that it is much slower than using gulp.
If you want to install localizations, run the following command:
$ ./manage.py l10n_update
You can read more details about how to localize content here.
Environment variables are used to configure behavior and/or features of select pages on bedrock
via a template helper function called
switch(). It will take whatever name you pass to it
(must be only numbers, letters, and dashes), convert it to uppercase, convert dashes to underscores,
and lookup that name in the environment. For example:
switch('the-dude') would look for the
SWITCH_THE_DUDE. If the value of that variable is any of “on”, “true”, “1”, or
“yes”, then it will be considered “on”, otherwise it will be “off”. If the environment variable
is set to one of those “true” values, then all switches will be considered “on” unless they are
explicitly “off” in the environment.
You can also supply a list of locale codes that will be the only ones for which the switch is active.
If the page is viewed in any other locale the switch will always return
False, even in
mode. This list can also include a “Locale Group”, which is all locales with a common prefix
(e.g. “en-US, en-GB, en-ZA” or “zh-CN, zh-TW”). You specify these with just the prefix. So if you
switch('the-dude', ['en', 'de']) in a template, the switch would be active for German and
any English locale the site supports.
You may also use these switches in Python in
views.py files (though not with locale support).
from bedrock.base.waffle import switch def home_view(request): title = 'Staging Home' if switch('staging-site') else 'Prod Home' ...
To work with/test these Optimizely switches locally, you must add the switches to your local environment. For example:
# to switch on firefox-new-optimizely you'd add the following to your ``.env`` file SWITCH_FIREFOX_NEW_OPTIMIZELY=on
You then must set an Optimizely project code in
# Optimize.ly project code OPTIMIZELY_PROJECT_ID=12345
You are not required to set up Optimizely as detailed above. If not configured,
bedrock will treat the switches as set to
deis config:set SWITCH_FIREFOX_NEW_OPTIMIZELY=on -a bedrock-demo-switch
We have multiple Deis clusters with independent configurations, and recommend using the DEIS_PROFILE environment variable to switch between clusters.