Skip to content

Commit

Permalink
Merge pull request #175 from datamade/hcg/docker
Browse files Browse the repository at this point in the history
Containerize application, remove unused edit_data and make_races management commands
  • Loading branch information
hancush authored Nov 7, 2023
2 parents c11b074 + d36c7e3 commit e966e99
Show file tree
Hide file tree
Showing 17 changed files with 1,396 additions and 1,832 deletions.
21 changes: 21 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Overview

Brief description of what this PR does, and why it is needed.

Closes #XXX

### Demo

Optional. Screenshots, `curl` examples, etc.

### Notes

Optional. Ancillary topics, caveats, alternative strategies that didn't work out, anything else.

## Testing Instructions

* How to test this PR
* Prefer bulleted description
* Start after checking out this branch
* Include any setup required, such as bundling scripts, restarting services, etc.
* Include test case, and expected output
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI

on:
push:
branches:
- master
- deploy
pull_request:
branches:
- master

jobs:
test:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build containers and run tests
run: docker-compose -f docker-compose.yml -f camp_fin/tests/docker-compose.yml run --rm app
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM python:3.6

LABEL maintainer "DataMade <[email protected]>"

RUN apt-get update && \
apt-get install -y --no-install-recommends postgresql-client locales && \
rm -rf /var/lib/apt/lists/* && \
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales

ENV LANG en_US.UTF-8
ENV LC_NUMERIC en_US.UTF-8

RUN mkdir /app
WORKDIR /app

COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

COPY . /app

ENV DJANGO_SECRET_KEY 'foobar'
ENV DJANGO_FLUSH_CACHE_KEY 'foobar'
ENV DJANGO_DEBUG 'False'

RUN python manage.py collectstatic --noinput
87 changes: 18 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,42 @@
The Openness Project - New Mexico Campaign Finance Site
==========
# The Openness Project - New Mexico Campaign Finance Site

This site brings greater transparency to New Mexico politics by providing an overview of campaign contributions, expenditures, and the people, businesses, and organizations involved.

## Setup
**Install app requirements**
## Development

We recommend using [virtualenv](http://virtualenv.readthedocs.org/en/latest/virtualenv.html) and [virtualenvwrapper](http://virtualenvwrapper.readthedocs.org/en/latest/install.html) for working in a virtualized development environment. [Read how to set up virtualenv](http://docs.python-guide.org/en/latest/dev/virtualenvs/).
Development requires a local installation of [Docker](https://docs.docker.com/install/)
and [Docker Compose](https://docs.docker.com/compose/install/).

Once you have virtualenvwrapper set up, do this:
To run the application, first build the app image:

```bash
mkvirtualenv openness-project-nmid -p /path/to/your/python3
git clone https://github.com/datamade/openness-project-nmid.git
cd openness-project-nmid
pip install -r requirements.txt
docker-compose build
```

Next, change your application settings. Start by copying the example `settings_local_example.py`
Next, load in data and build your search index:

```
cp nmid/settings_local_example.py nmid/settings_local.py
```

Then set your database name, user and password.

Next, create a postgres database and run the Django migrations to setup the proper tables.

```
createdb nmid
python manage.py migrate
```

## Data import

To import the New Mexico campaign finance data into your database, run the `import_data` command:

```
python manage.py import_data
```

The version of the data sent to us by the Secretary of State in April 2018
contains a number of errors - primarily candidates that are assigned to the
wrong race. To fix these errors, run the `edit_data` command:

```
python manage.py edit_data
```

Next, group campaigns into races with the `make_races` command.

```
python manage.py make_races
```bash
docker-compose run --rm app python manage.py import_data
docker-compose run --rm app python manage.py make_search_index
```

Finally, run the `make_search_index` command to generate the search index.
Finally, run the app:

```bash
docker-compose up
```
python manage.py make_search_index
```

## Redoing an import

The data import scripts for this app will automatically recognize if you have data imported,
and add or update new data accordingly. However, if you'd like to start over from
scratch but don't want to delete your user and page data, you can start by running the
`flush_camp_fin` command to flush campaign finance data from the database:
The app will be available at http://localhost:8000. The database will be exposed
on port 32001.

```
python manage.py flush_camp_fin
```
## Resetting the database

## Run the code
The data import scripts for this app will automatically recognize if you have data imported, and add or update new data accordingly. However, if you'd like to start over from scratch but don't want to delete your user and page data, you can start by running the `flush_camp_fin` command to flush campaign finance data from the database:

Run the server with the following:
```bash
workon openness-project-nmid
python manage.py runserver
docker-compose run --rm app python manage.py flush_camp_fin
```

Then, navigate to: http://localhost:8000/

## Team

* Eric van Zanten - developer
* Derek Eder - developer
* Regina Compton - developer
* Jean Cochrane - developer

## Errors / Bugs

If something is not behaving intuitively, it is a bug, and should be reported.
Expand Down
Loading

0 comments on commit e966e99

Please sign in to comment.