Skip to content

Commit 6708944

Browse files
dukebodyjbagot
andauthored
Multiple upgrades to get the system working locally with docker and Django 3 (#310)
* Update defusedxml to 0.6.0. Fixes #288. * Update isort version for pre-commit. The repo switched from "master" to "main" branch naming. * Multiple changes to make the project work easily in Docker * Upgrade to Django 3.2 * use python3.9-slim docker image to avoid issues with alpine Co-authored-by: Jordi Bagot <jbagot@kavehome.com>
1 parent 0dfb34d commit 6708944

12 files changed

Lines changed: 53 additions & 45 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ repos:
66
- id: black
77
language_version: python3
88
- repo: https://github.com/pre-commit/mirrors-isort
9-
rev: "master" # Use the revision sha / tag you want to point at
9+
rev: "main" # Use the revision sha / tag you want to point at
1010
hooks:
1111
- id: isort

Dockerfile

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
1-
FROM python:3-alpine as builder
1+
FROM python:3.9-slim
22

33
WORKDIR /home/python
44

5-
RUN apk add --no-cache zlib-dev build-base python-dev jpeg-dev
6-
RUN pip install virtualenv
7-
RUN virtualenv venv
5+
RUN apt update && apt install -y zlib1g-dev build-essential libjpeg-dev
86

9-
ADD requirements.txt /home/python/
10-
RUN venv/bin/pip install --no-cache-dir -r requirements.txt
11-
RUN virtualenv --relocatable venv/
7+
ADD requirements.txt .
8+
RUN pip install --no-cache-dir -r requirements.txt
129

13-
ADD . /home/python/
14-
RUN venv/bin/python manage.py migrate
15-
16-
FROM python:3-alpine
17-
18-
WORKDIR /home/python
19-
COPY --from=builder /home/python /home/python
20-
COPY --from=builder /lib /lib
21-
COPY --from=builder /usr/lib /usr/lib
10+
ADD . .
11+
RUN python manage.py migrate
2212

2313
STOPSIGNAL SIGINT
24-
ENTRYPOINT ["venv/bin/python", "manage.py"]
2514
ENV DJANGO_SETTINGS_MODULE=get_together.environ_settings
26-
CMD ["runserver", "0.0.0.0:8000"]
15+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
2716

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ We use the following code formatters:
144144

145145
They are included in the requirements.txt so they were installed already when you [installed dependencies](#install-dependecies-and-migrate-the-database).
146146

147-
On the first commit after installing `pre-commit`, Black and iSort it will create a new environment, which may take a few minutes. This environment will be reused for all subsequent commits.
147+
On the first commit after doing `pre-commit install`, Black and iSort it will create a new environment, which may take a few minutes. This environment will be reused for all subsequent commits.
148148

149149
### Loading City data
150150

151151
In order to make it easier to create Places and Teams without having to manually
152152
enter records for Country, SPR (State/Province/Region) and City, you can preload
153-
them using data files from <http://download.geonames.org/export/dump/>
153+
them using data files from <https://download.geonames.org/export/dump/>
154154

155155
The provided `load_spr` and `load_cities` commands will only load data if the
156156
parent country (or SPR for cities) exists in the database. This lets you choose
@@ -159,24 +159,30 @@ for select SPRs.
159159

160160
#### Countries
161161

162-
Download the [countryInfo.txt](http://download.geonames.org/export/dump/countryInfo.txt)
163-
file from GeoNames, then run:
162+
Download the [countryInfo.txt](https://download.geonames.org/export/dump/countryInfo.txt)
163+
file from GeoNames, and load it:
164164

165-
`./env/bin/python manage.py load_countries countryInfo.txt`
165+
```bash
166+
wget https://download.geonames.org/export/dump/countryInfo.txt
167+
./env/bin/python manage.py load_countries countryInfo.txt
168+
```
166169

167170
#### SPR
168171

169-
Download the [admin1CodesASCII.txt](http://download.geonames.org/export/dump/admin1CodesASCII.txt)
172+
Download the [admin1CodesASCII.txt](https://download.geonames.org/export/dump/admin1CodesASCII.txt)
170173
file from GeoNames, then run:
171174

172-
`./env/bin/python manage.py load_spr admin1CodesASCII.txt`
175+
```bash
176+
wget https://download.geonames.org/export/dump/admin1CodesASCII.txt
177+
./env/bin/python manage.py load_spr admin1CodesASCII.txt
178+
```
173179

174180
#### Cities
175181

176182
You have a few choices for City data files. GeoNames provides data files for
177-
cities with [more than 15,000](http://download.geonames.org/export/dump/cities15000.zip)
178-
residents, cities with [more than 5,000](http://download.geonames.org/export/dump/cities5000.zip)
179-
residents, and cities [with more than 1,000](http://download.geonames.org/export/dump/cities1000.zip)
183+
cities with [more than 15,000](https://download.geonames.org/export/dump/cities15000.zip)
184+
residents, cities with [more than 5,000](https://download.geonames.org/export/dump/cities5000.zip)
185+
residents, and cities [with more than 1,000](https://download.geonames.org/export/dump/cities1000.zip)
180186
residents. The smaller the number, the more cities there will be in the data
181187
file (and the longer it will take to import them all).
182188

@@ -191,14 +197,14 @@ file):
191197
```bash
192198
docker build -t get_together .
193199
docker run -e "DEBUG_MODE=True" -e "SECRET_KEY=xxxxx" -e "ALLOWED_HOSTS=localhost,127.0.0.1" -d --name get_together -p 8000:8000 get_together
194-
docker exec -it get_together venv/bin/python manage.py createsuperuser
200+
docker exec -it get_together python manage.py createsuperuser
195201
```
196202

197203
### Using docker-compose
198204

199205
```bash
200206
docker-compose up -d
201-
docker-compose exec get_together python3 manage.py createsuperuser
207+
docker-compose exec get_together python manage.py createsuperuser
202208
```
203209

204210
You can then connect to the container by going to localhost:8000

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ services:
44
build:
55
context: .
66
dockerfile: Dockerfile
7-
stdin_open: true
8-
tty: true
97
ports:
108
- "8000:8000"
119
environment:
1210
- DEBUG_MODE=True
1311
- SECRET_KEY=xxxxx
1412
- ALLOWED_HOSTS=localhost,127.0.0.1
13+
volumes:
14+
- ./:/home/python

events/models/profiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.conf import settings
66
from django.contrib.auth.models import AnonymousUser, Group, User
77
from django.contrib.sites.models import Site
8-
from django.contrib.staticfiles.templatetags.staticfiles import static
8+
from django.templatetags.static import static
99
from django.db import models
1010
from django.shortcuts import reverse
1111
from django.utils import timezone
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<table>
2-
{{ event_form }}
2+
{{ event_form }}
3+
{{ event_form.media }}
34
</table>

events/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from django.conf import settings
55
from django.core.exceptions import PermissionDenied
6-
from django.middleware.csrf import _compare_salted_tokens, _sanitize_token
6+
from django.middleware.csrf import _compare_masked_tokens, _sanitize_token
77

88
SLUG_OK = "-_~"
99

@@ -29,7 +29,7 @@ def verify_csrf(token_key="csrftoken"):
2929
def wrap_view(view_func):
3030
def check_csrf_token(request, *args, **kwargs):
3131
csrf_token = _sanitize_token(request.GET.get(token_key, ""))
32-
match = _compare_salted_tokens(
32+
match = _compare_masked_tokens(
3333
csrf_token, request.COOKIES.get(settings.CSRF_COOKIE_NAME, "")
3434
)
3535
if not match and getattr(settings, "CSRF_VERIFY_TOKEN", True):

get_together/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@
232232
"images": {"nav_logo": "img/logo_b_v1.png"},
233233
}
234234

235+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
236+
235237
# Keep this at the end of settings.py to allow overriding settings in local deployments
236238
try:
237239
from local_settings import *

get_together/templates/get_together/base.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
<meta name="theme-color" content="#ffffff">
2525
<!-- FAVICON ENDS -->
2626

27+
<script src="{% url 'jsi18n' %}"></script>
28+
2729
{% block meta %}{% endblock %}
2830

2931
{% if settings.GOOGLE_ANALYTICS_ID and not request.user.profile.do_not_track %}
@@ -120,7 +122,7 @@
120122
</div>
121123
</nav>
122124

123-
<main role="main" class="container">
125+
<main role="main" class="container" id="container">
124126

125127
{% block account_setup_alert %}
126128
{% if account_needs_setup %}

get_together/urls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@
1515
"""
1616
from django.conf import settings
1717
from django.conf.urls.static import static
18+
from django.conf.urls import url
1819
from django.contrib import admin
1920
from django.contrib.auth import views as auth_views
2021
from django.urls import include, path
22+
from django.views.i18n import JavaScriptCatalog
2123

2224
from events import feeds, views as event_views
2325

2426
from . import views
2527

28+
js_info_dict = {
29+
'packages': ('recurrence', ),
30+
}
31+
32+
2633
urlpatterns = [
2734
path("", views.home, name="home"),
2835
path("admin/", admin.site.urls),
@@ -310,6 +317,7 @@
310317
views.show_team_events_by_slug,
311318
name="show-team-events-by-slug",
312319
),
320+
path('jsi18n.js', JavaScriptCatalog.as_view(packages=['recurrence']), name='jsi18n'),
313321
]
314322
if settings.DEBUG:
315323
urlpatterns = urlpatterns + static(

0 commit comments

Comments
 (0)