Skip to content

Commit b3decd8

Browse files
committed
Started reworking the top of our getting started guide for #28. Still lots to do.
1 parent bef0899 commit b3decd8

File tree

2 files changed

+127
-122
lines changed

2 files changed

+127
-122
lines changed

docs/contribute/calaccess_website.rst

Lines changed: 127 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,134 @@
11
Contribute to django-calaccess-downloads-website
22
================================================
33

4-
The infrastructure for our `downloads website <apps/calaccess_downloads_site.html>`_ is hosted on Amazon Web Services.
4+
This walkthrough is for developers who want to contribute to :doc:`/apps/calaccess_downloads_site`, a open-source archive of
5+
campaign-finance and lobbying-disclosure data from the California Secretary of State's :doc:`CAL-ACCESS </calaccess>` database.
56

6-
* The raw data files exported daily from CAL-ACCESS are uploaded to a `Simple Storage Service <https://aws.amazon.com/s3/>`_ (S3) bucket.
7-
* The website's PostgreSQL backend is hosted on a `Relational Database Service <https://aws.amazon.com/rds/>`_ (RDS) instance.
8-
* The application code that downloads, processes and archives the daily CAL-ACCESS exports runs on an `Elastic Compute Cloud <https://aws.amazon.com/ec2/>`_ (EC2) instance.
7+
It will show you how to install the source code of this application to fix bugs, develop new features and administer an archive.
98

10-
We deploy and manage this infrastructure via tasks defined using `Fabric <http://www.fabfile.org/>`_. This makes processes like deploying the entire downloads website as simple as invoking a few commands from the command-line.
9+
---------------
1110

12-
.. toctree::
13-
:maxdepth: 2
11+
-----------------------------------
12+
Preparing a development environment
13+
-----------------------------------
1414

15-
calaccess_website/env-prep
16-
calaccess_website/deployment-walkthru
17-
calaccess_website/fab-task-index
15+
In order to contribute you first need to set up a local development environment, install the source code and configure a few settings.
16+
17+
While not required, we recommend that development be done within a contained virtual environment.
18+
19+
One way to accomplish that is with a two related Python packages: ``virtualenv`` and ``virtualenvwrapper``. If you have both of these installed, a new project can be easily set up by invoking:
20+
21+
.. code-block:: bash
22+
23+
$ mkproject django-calaccess-downloads-website
24+
25+
That will jump into a new folder in your code directory, where you can clone our
26+
code repository from `GitHub <https://github.com/california-civic-data-coalition/django-calaccess-downloads-website>`_
27+
after you make a fork of your own. Don't know what that means? `Read this <https://guides.github.com/activities/forking/>`_.
28+
29+
.. code-block:: bash
30+
31+
$ git clone https://github.com/<YOUR-USERNAME>/django-calaccess-downloads-website.git .
32+
33+
Next, install the other Python libraries our code depends on.
34+
35+
.. code-block:: bash
36+
37+
$ pip install -r requirements.txt
38+
39+
---------------
40+
41+
42+
Configuring development settings
43+
--------------------------------
44+
45+
Many of the settings in this project vary depending on the environment. For instance, your local installation of the code will
46+
likely connect to a different database than live website.
47+
48+
To keep these different environments straight and avoid including sensitive passwords in our public repositories we have developed
49+
a system for storing many of the configuration options in a ``.env`` at the project's root. The file is excluded from tracking by Git.
50+
51+
How .env works
52+
~~~~~~~~~~~~~~
53+
54+
The ``.env`` is expected to contain a separate section for each environment, using the structure favored by Python's `ConfigParser module <https://docs.python.org/2/library/configparser.html>`_. Here's a simple example:
55+
56+
.. code-block:: ini
57+
58+
[DEV]
59+
database_name=calaccess
60+
mysecretpassword=password
61+
62+
[PROD]
63+
database_name=calaccess
64+
mysecretpassword=hotpockets
65+
66+
67+
By default, the source code will draw settings from a section name ``DEV``.To configure it to use ``PROD`` or any other set of variables,
68+
set the ``CALACCESS_WEBSITE_ENV`` environment variable.
69+
70+
.. code-block:: bash
71+
72+
$ export CALACCESS_WEBSITE_ENV=PROD
73+
74+
If you are using virtualenv and virtualenvwrapper, you could add the above line of code to ``$VIRTUAL_ENV/bin/postactivate`` so that
75+
whenever you start the project's virtual environment, this variable will be exported automatically whenever you use ``workon`` to
76+
begin work.
77+
78+
You might also also add this line to your ``$VIRTUAL_ENV/bin/postdeactivate`` script in order to remove the variable
79+
whenever you deactivate the virtual environment:
80+
81+
.. code-block:: bash
82+
83+
$ unset CALACCESS_WEBSITE_ENV
84+
85+
Filling in .env for the first time
86+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87+
88+
The current ``CALACCESS_WEBSITE_ENV`` can be configure in ``.env`` by running a `Fabric <http://www.fabfile.org/>`_ task that will ask you to provide a value for all
89+
of this project's mandatory settings.
90+
91+
.. code-block:: bash
92+
93+
$ fab createconfig
94+
95+
You will prompted to provide the project's full array of settings, though some of them are only necessary when deploying the code
96+
and site with Amazon Web Services.
97+
98+
======================= ======================= =================================================================================================
99+
Setting Required in development Definition
100+
======================= ======================= =================================================================================================
101+
db_name Yes Name of your database.
102+
db_user Yes Database user.
103+
db_password Yes Database password.
104+
rds_host Yes Database host location.
105+
aws_access_key_id No Shorter secret key for accessing Amazon Web Services.
106+
aws_secret_access_key No The longer secret key for accessing Amazon Web Services.
107+
aws_region_name No Amazon Web Services region where you resources are located.
108+
s3_archived_data_bucket No Amazon S3 bucket where archived CAL-ACCESS data will be stored.
109+
s3_baked_content_bucket No Amazon S3 bucket where the public-facing website will be stored.
110+
key_name No Name of the SSH ``.pem`` file associated with Amazon Web Services. Should be found in ``~/.ec2``.
111+
ec2_host No Public address of website's Amazon EC2 instance.
112+
email_user No Gmail account for sending error emails.
113+
email_password No Gmail password for sending error emails.
114+
======================= ======================= =================================================================================================
115+
116+
If necessary, you can overwrite a specific configuration or append a new one:
117+
118+
.. code-block:: bash
119+
120+
$ fab setconfig:key=<new-variable-name>,value=<some-value>
121+
122+
You can also print your current app environment's configuration:
123+
124+
.. code-block:: bash
125+
126+
$ fab printconfig
127+
128+
Or everything in the Fabric environment:
129+
130+
.. code-block:: bash
131+
132+
$ fab printenv
133+
134+
---------------

docs/contribute/calaccess_website/env-prep.rst

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)