Skip to content

Commit 97766ab

Browse files
authored
Merge pull request #163 from caktus/develop
Production release v1.8.0
2 parents 654597e + 32cf371 commit 97766ab

File tree

116 files changed

+1481
-387
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+1481
-387
lines changed

.devcontainer/devcontainer.json

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.0/containers/docker-existing-docker-compose
3+
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
4+
{
5+
"name": "CopWatch",
6+
7+
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
8+
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
9+
"dockerComposeFile": [
10+
"../docker-compose.yml",
11+
"docker-compose.yml"
12+
],
13+
14+
// The 'service' property is the name of the service for the container that VS Code should
15+
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
16+
"service": "django",
17+
18+
// The optional 'workspaceFolder' property is the path VS Code should open by default when
19+
// connected. This is typically a file mount in .devcontainer/docker-compose.yml
20+
"workspaceFolder": "/code",
21+
22+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
23+
// "forwardPorts": [],
24+
25+
// Uncomment the next line if you want start specific services in your Docker Compose config.
26+
// "runServices": [],
27+
28+
// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
29+
"shutdownAction": "stopCompose",
30+
31+
// Uncomment the next line to run commands after the container is created - for example installing curl.
32+
"postCreateCommand": "sudo chown appuser /home/appuser/.cache /code/frontend/node_modules /code/venv /code/public /var/run/docker.sock",
33+
34+
// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
35+
"remoteUser": "appuser",
36+
37+
// A command to run each time the container is successfully started.
38+
"postStartCommand": "git config --global --add safe.directory ${containerWorkspaceFolder}",
39+
40+
"customizations": {
41+
"vscode": {
42+
"extensions": [
43+
"ms-python.python",
44+
"ms-python.vscode-pylance",
45+
"batisteo.vscode-django",
46+
"ms-vsliveshare.vsliveshare-pack",
47+
"yzhang.markdown-all-in-one"
48+
]
49+
}
50+
}
51+
}

.devcontainer/docker-compose.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '3.4'
2+
services:
3+
# Update this to the name of the service you want to work with in your docker-compose.yml file
4+
django:
5+
# If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
6+
# property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks,
7+
# debugging) to execute as the user. Uncomment the next line if you want the entire
8+
# container to run as this user instead. Note that, on Linux, you may need to
9+
# ensure the UID and GID of the container user you create matches your local user.
10+
# See https://aka.ms/vscode-remote/containers/non-root for details.
11+
#
12+
# user: vscode
13+
14+
# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
15+
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
16+
# docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
17+
# array). The sample below assumes your primary file is in the root of your project.
18+
#
19+
# build:
20+
# context: .
21+
# dockerfile: .devcontainer/Dockerfile
22+
23+
volumes:
24+
# Update this to wherever you want VS Code to mount the folder of your project
25+
- .:/code:cached
26+
27+
# Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker-compose for details.
28+
- /var/run/docker.sock:/var/run/docker.sock
29+
30+
# Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
31+
# cap_add:
32+
# - SYS_PTRACE
33+
# security_opt:
34+
# - seccomp:unconfined
35+
36+
# Overrides default command so things don't shut down after the process ends.
37+
command: /bin/sh -c "while sleep 1000; do :; done"

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ frontend/node_modules
1616
deploy/
1717
.env
1818
.envrc
19+
.devcontainer
20+
.github
21+
nc/notebooks
22+
venv

.github/workflows/deploy.yaml

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fetch-depth: 0
2020
- name: Set env vars (production)
2121
if: endsWith(github.ref, '/main')
22-
run: |
22+
run: |
2323
echo "ENV=production" >> $GITHUB_ENV
2424
echo "ENV_URL=https://nccopwatch.org/" >> $GITHUB_ENV
2525
- uses: actions/setup-python@v2

.github/workflows/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Install dependencies
3535
run: |
3636
sudo apt update
37-
sudo apt install -y --no-install-recommends postgresql-client-12
37+
sudo apt install -y --no-install-recommends postgresql-client-14
3838
python -m pip install pip-tools
3939
pip-sync requirements/base/base.txt requirements/test/test.txt
4040
- name: Create NC database

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ traffic_stops.log
1515
traffic_stops.log.1
1616
reports
1717
env
18+
venv
1819
jmeter.log
1920
npm-debug.log
2021
.transifexrc
@@ -52,3 +53,4 @@ aws_ec2.yml
5253
deploy/roles
5354
docker-compose.override.yml
5455
htmlcov
56+
acs*.json

.pre-commit-config.yaml

+16-14
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,27 @@ repos:
55
- id: black
66
language_version: python3.8
77
exclude: migrations
8-
- repo: https://github.com/pre-commit/mirrors-isort
9-
rev: v4.3.21
8+
- repo: https://github.com/PyCQA/flake8
9+
rev: 4.0.1
10+
hooks:
11+
- id: flake8
12+
exclude: settings|migrations|tests
13+
- repo: https://github.com/pycqa/isort
14+
rev: 5.12.0
1015
hooks:
1116
- id: isort
12-
# Resolves conflict with black
13-
args: [--multi-line=3, --trailing-comma, --force-grid-wrap=0, --use-parentheses, --line-width=100]
17+
args: ["--profile", "black", "--filter-files"]
1418
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: v2.4.0
19+
rev: v4.1.0
1620
hooks:
21+
- id: trailing-whitespace
22+
- id: end-of-file-fixer
23+
- id: check-yaml
24+
exclude: '^(deployment/|deploy)'
25+
- id: check-added-large-files
26+
- id: check-json
27+
exclude: .devcontainer/devcontainer.json|.vscode/launch.json|frontend/.eslintrc.json
1728
- id: check-docstring-first
1829
- id: check-merge-conflict
19-
- id: check-json
20-
exclude: docs/dev
21-
- id: check-yaml
22-
exclude: (deploy/host_vars|deploy/stack|deploy)
23-
- id: check-xml
2430
- id: debug-statements
25-
- id: detect-aws-credentials
26-
args: [--allow-missing-credentials]
2731
- id: detect-private-key
28-
- id: flake8
29-
exclude: settings|migrations|test

Dockerfile

+88-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:16.16-alpine3.16 as static_files
1+
FROM node:16-bullseye-slim as static_files
22

33
WORKDIR /code
44
ENV PATH /code/node_modules/.bin:$PATH
@@ -24,7 +24,6 @@ RUN set -ex \
2424
mime-support \
2525
postgresql-client \
2626
vim \
27-
gdal-bin \
2827
" \
2928
&& seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \
3029
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
@@ -48,10 +47,11 @@ RUN set -ex \
4847
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
4948
&& pip install -U -q pip-tools \
5049
&& pip-sync requirements/base/base.txt requirements/deploy/deploy.txt \
51-
\
5250
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
5351
&& rm -rf /var/lib/apt/lists/*
5452

53+
FROM base AS deploy
54+
5555
# Copy your application code to the container (make sure you create a .dockerignore file if any large files or directories should be excluded)
5656
RUN mkdir /code/
5757
WORKDIR /code/
@@ -67,7 +67,6 @@ EXPOSE 8000
6767
ENV DJANGO_SETTINGS_MODULE=traffic_stops.settings.deploy
6868

6969
# Call collectstatic (customize the following line with the minimal environment variables needed for manage.py to run):
70-
RUN touch /code/.env
7170
RUN DATABASE_URL='' ENVIRONMENT='' DJANGO_SECRET_KEY='dummy' DOMAIN='' python manage.py collectstatic --noinput
7271

7372
# Tell uWSGI where to find your wsgi file (change this):
@@ -82,6 +81,8 @@ ENV UWSGI_WORKERS=2 UWSGI_THREADS=4
8281
# uWSGI static file serving configuration (customize or comment out if not needed):
8382
ENV UWSGI_STATIC_MAP="/static/=/code/static/" UWSGI_STATIC_EXPIRES_URI="/static/.*\.[a-f0-9]{12,}\.(css|js|png|jpg|jpeg|gif|ico|woff|ttf|otf|svg|scss|map|txt) 315360000"
8483

84+
RUN touch /code/.env
85+
8586
# Change to a non-root user
8687
USER ${APP_USER}:${APP_USER}
8788

@@ -90,3 +91,86 @@ ENTRYPOINT ["/code/docker-entrypoint.sh"]
9091

9192
# Start uWSGI
9293
CMD ["newrelic-admin", "run-program", "uwsgi", "--single-interpreter", "--enable-threads", "--show-config"]
94+
95+
FROM python:3.8-slim-bullseye AS dev
96+
97+
ARG USERNAME=appuser
98+
ARG USER_UID=1000
99+
ARG USER_GID=$USER_UID
100+
101+
# Create non-root user
102+
RUN groupadd --gid $USER_GID $USERNAME \
103+
&& useradd --uid $USER_UID --gid $USER_GID --create-home --shell /bin/bash $USERNAME
104+
105+
# Install packages for Dev Container development
106+
# build-essential -- for gcc to compile non-wheel packages with C dependencies
107+
# docker-ce-cli -- docker CLI
108+
# docker-compose-plugin -- docker compose CLI
109+
# git-core -- to pull, commit, and push from dev container
110+
# gnupg2 -- GNU privacy guard - a free PGP replacement
111+
# libpq-dev -- header files for PostgreSQL
112+
# openssh-client -- for git over SSH
113+
# sudo -- to run commands as superuser
114+
# vim -- enhanced vi editor for commits
115+
ENV KUBE_CLIENT_VERSION="v1.22.15"
116+
ENV HELM_VERSION="3.8.2"
117+
RUN --mount=type=cache,target=/var/cache/apt --mount=type=cache,target=/var/lib/apt \
118+
--mount=type=cache,mode=0755,target=/root/.cache/pip \
119+
set -ex \
120+
&& RUN_DEPS=" \
121+
build-essential \
122+
docker-ce-cli \
123+
docker-compose-plugin \
124+
git-core \
125+
gnupg2 \
126+
libpcre3 \
127+
libpq-dev \
128+
mime-support \
129+
nodejs \
130+
openssh-client \
131+
postgresql-client-12 \
132+
sudo \
133+
vim \
134+
" \
135+
&& apt-get update && apt-get -y install curl wget gnupg2 lsb-release \
136+
# starship.rs prompt
137+
&& curl -sS https://starship.rs/install.sh | sh -s -- -y \
138+
# kubectl
139+
&& curl --silent -L https://dl.k8s.io/release/$KUBE_CLIENT_VERSION/bin/linux/$(dpkg --print-architecture)/kubectl -o /usr/local/bin/kubectl \
140+
&& chmod +x /usr/local/bin/kubectl \
141+
# helm
142+
&& curl --silent -L https://get.helm.sh/helm-v$HELM_VERSION-linux-$(dpkg --print-architecture).tar.gz --output - | tar -xzC /tmp \
143+
&& mv /tmp/linux-$(dpkg --print-architecture)/helm /usr/local/bin/helm \
144+
&& chmod +x /usr/local/bin/helm \
145+
# docker
146+
&& curl https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor | tee /etc/apt/trusted.gpg.d/docker.gpg >/dev/null \
147+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \
148+
# nodejs
149+
&& sh -c 'echo "deb https://deb.nodesource.com/node_16.x $(lsb_release -cs) main" > /etc/apt/sources.list.d/nodesource.list' \
150+
&& wget --quiet -O- https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - \
151+
# PostgreSQL
152+
&& sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \
153+
&& curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/apt.postgresql.org.gpg >/dev/null \
154+
# dev packages
155+
&& apt-get update \
156+
&& apt-get install -y --no-install-recommends $RUN_DEPS \
157+
# sudo
158+
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
159+
&& chmod 0440 /etc/sudoers.d/$USERNAME
160+
161+
# Install Docker Buildx component for Docker v23.0.0+
162+
COPY --from=docker/buildx-bin:latest /buildx /usr/libexec/docker/cli-plugins/docker-buildx
163+
164+
COPY --chown=$USER_UID:$USER_GID . /code/
165+
166+
USER $USERNAME
167+
RUN set -ex \
168+
&& touch /code/.env \
169+
&& echo 'eval "$(starship init bash)"' >> ~/.bashrc
170+
171+
ENV DJANGO_SETTINGS_MODULE=traffic_stops.settings.dev
172+
ENV PATH=/code/venv/bin:$PATH
173+
174+
WORKDIR /code
175+
176+
CMD ["python", "/code/manage.py", "runserver", "0.0.0.0:8000"]

Makefile

+7
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ run-tests:
2626
@echo 'Checking for migrations'
2727
python manage.py makemigrations --dry-run | grep 'No changes detected' || (echo 'There are changes which require migrations.' && exit 1)
2828
python manage.py test
29+
30+
31+
dl-db-dump:
32+
@echo 'Downloading new db dump from s3'
33+
export AWS_PROFILE=copwatch
34+
inv aws.configure-eks-kubeconfig
35+
inv staging pod.get-db-dump --db-var=DATABASE_URL_NC

README.rst

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ NC CopWatch
33

44
NC CopWatch is a website to monitor and identify racial profiling
55
practices by North Carolina law enforcement agencies. This project is lead by
6-
`Forward Justice`_, a nonpartisan law, policy, and strategy center dedicated to advancing racial,
6+
`Forward Justice`_, a nonpartisan law, policy, and strategy center dedicated to advancing racial,
77
social, and economic justice in the U.S. South.
88

99
Please see the `production documentation`_ and `development documentation`_

deploy/group_vars/all.yml

+25-9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,21 @@ cloudformation_stack:
5757
tags:
5858
Environment: "{{ app_name }}"
5959

60+
# Install Descheduler to attempt to spread out pods again after node failures
61+
k8s_install_descheduler: yes
62+
# You must set the k8s_descheduler_chart_version to match the Kubernetes
63+
# node version (0.23.x -> K8s 1.23.x); see:
64+
# https://github.com/kubernetes-sigs/descheduler#compatibility-matrix
65+
k8s_descheduler_chart_version: v0.22.1
66+
# See values.yaml for options:
67+
# https://github.com/kubernetes-sigs/descheduler/blob/master/charts/descheduler/values.yaml#L63
68+
k8s_descheduler_release_values:
69+
deschedulerPolicy:
70+
strategies:
71+
# During upgrades or reboots, don't pre-emptively drain a node.
72+
RemovePodsViolatingNodeTaints:
73+
enabled: false
74+
6075
# ----------------------------------------------------------------------------
6176
# caktus.k8s-web-cluster: An Ansible role to help configure Kubernetes
6277
# clusters for web apps.
@@ -77,7 +92,7 @@ k8s_iam_users: [copelco]
7792
# Pin ingress-nginx and cert-manager to current versions so future upgrades of this
7893
# role will not upgrade these charts without your intervention:
7994
# https://github.com/kubernetes/ingress-nginx/releases
80-
k8s_ingress_nginx_chart_version: "4.0.19"
95+
k8s_ingress_nginx_chart_version: "4.4.2"
8196
# https://github.com/jetstack/cert-manager/releases
8297
k8s_cert_manager_chart_version: "v1.7.2"
8398
# AWS only:
@@ -92,13 +107,14 @@ k8s_aws_load_balancer_type: nlb
92107
k8s_papertrail_logspout_destination: "syslog+tls://logs2.papertrailapp.com:20851"
93108
k8s_papertrail_logspout_memory_limit: 128Mi
94109

95-
# New Relic Infrastructure: admin+newrelic@caktusgroup.com
96-
k8s_newrelic_chart_version: "3.5.1"
110+
# New Relic Account: forwardjustice-team@caktusgroup.com
111+
k8s_newrelic_chart_version: "5.0.4"
112+
k8s_newrelic_logging_enabled: true
97113
k8s_newrelic_license_key: !vault |
98114
$ANSIBLE_VAULT;1.1;AES256
99-
37656631623333346263383231386165666531333961373931383661366338343634333362356430
100-
3963613833663637313632373465613730383365626461630a383432346335386632303935356532
101-
61643737636132336339336332396262623362333663333130393031376338363266363430326136
102-
6131396135646236360a323766623330313365306539316263393533623063346166653433316631
103-
39356263623363653934333064376364363562303236646238666234356136663539343064383463
104-
3161356339656137373935623562366134393765346466643365
115+
66633739306132643365363862313730386239643136363637336638323066343033653466663234
116+
6663633261383536383936343939383634636530613633370a363032623332656465303231653535
117+
33303336323831303939646432313835386261646632343165373963616132343039333432386562
118+
3163313364666132340a636330353366613061306361303737303332383431336263323135393232
119+
65303530343134383464616561383139643263326661636133316534303934346438643366666663
120+
3136353834393937356364356235393236643835663965643532

0 commit comments

Comments
 (0)