Skip to content

Commit

Permalink
Multiple upgrades to get the system working locally with docker and D…
Browse files Browse the repository at this point in the history
…jango 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 <[email protected]>
  • Loading branch information
dukebody and jbagot authored Apr 18, 2022
1 parent 0dfb34d commit 6708944
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ repos:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-isort
rev: "master" # Use the revision sha / tag you want to point at
rev: "main" # Use the revision sha / tag you want to point at
hooks:
- id: isort
25 changes: 7 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
FROM python:3-alpine as builder
FROM python:3.9-slim

WORKDIR /home/python

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

ADD requirements.txt /home/python/
RUN venv/bin/pip install --no-cache-dir -r requirements.txt
RUN virtualenv --relocatable venv/
ADD requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

ADD . /home/python/
RUN venv/bin/python manage.py migrate

FROM python:3-alpine

WORKDIR /home/python
COPY --from=builder /home/python /home/python
COPY --from=builder /lib /lib
COPY --from=builder /usr/lib /usr/lib
ADD . .
RUN python manage.py migrate

STOPSIGNAL SIGINT
ENTRYPOINT ["venv/bin/python", "manage.py"]
ENV DJANGO_SETTINGS_MODULE=get_together.environ_settings
CMD ["runserver", "0.0.0.0:8000"]
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ We use the following code formatters:

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

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.
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.

### Loading City data

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

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

#### Countries

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

`./env/bin/python manage.py load_countries countryInfo.txt`
```bash
wget https://download.geonames.org/export/dump/countryInfo.txt
./env/bin/python manage.py load_countries countryInfo.txt
```

#### SPR

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

`./env/bin/python manage.py load_spr admin1CodesASCII.txt`
```bash
wget https://download.geonames.org/export/dump/admin1CodesASCII.txt
./env/bin/python manage.py load_spr admin1CodesASCII.txt
```

#### Cities

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

Expand All @@ -191,14 +197,14 @@ file):
```bash
docker build -t get_together .
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
docker exec -it get_together venv/bin/python manage.py createsuperuser
docker exec -it get_together python manage.py createsuperuser
```

### Using docker-compose

```bash
docker-compose up -d
docker-compose exec get_together python3 manage.py createsuperuser
docker-compose exec get_together python manage.py createsuperuser
```

You can then connect to the container by going to localhost:8000
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ services:
build:
context: .
dockerfile: Dockerfile
stdin_open: true
tty: true
ports:
- "8000:8000"
environment:
- DEBUG_MODE=True
- SECRET_KEY=xxxxx
- ALLOWED_HOSTS=localhost,127.0.0.1
volumes:
- ./:/home/python
2 changes: 1 addition & 1 deletion events/models/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf import settings
from django.contrib.auth.models import AnonymousUser, Group, User
from django.contrib.sites.models import Site
from django.contrib.staticfiles.templatetags.staticfiles import static
from django.templatetags.static import static
from django.db import models
from django.shortcuts import reverse
from django.utils import timezone
Expand Down
3 changes: 2 additions & 1 deletion events/templates/events/event_form.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<table>
{{ event_form }}
{{ event_form }}
{{ event_form.media }}
</table>
4 changes: 2 additions & 2 deletions events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from django.conf import settings
from django.core.exceptions import PermissionDenied
from django.middleware.csrf import _compare_salted_tokens, _sanitize_token
from django.middleware.csrf import _compare_masked_tokens, _sanitize_token

SLUG_OK = "-_~"

Expand All @@ -29,7 +29,7 @@ def verify_csrf(token_key="csrftoken"):
def wrap_view(view_func):
def check_csrf_token(request, *args, **kwargs):
csrf_token = _sanitize_token(request.GET.get(token_key, ""))
match = _compare_salted_tokens(
match = _compare_masked_tokens(
csrf_token, request.COOKIES.get(settings.CSRF_COOKIE_NAME, "")
)
if not match and getattr(settings, "CSRF_VERIFY_TOKEN", True):
Expand Down
2 changes: 2 additions & 0 deletions get_together/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
"images": {"nav_logo": "img/logo_b_v1.png"},
}

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"

# Keep this at the end of settings.py to allow overriding settings in local deployments
try:
from local_settings import *
Expand Down
4 changes: 3 additions & 1 deletion get_together/templates/get_together/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<meta name="theme-color" content="#ffffff">
<!-- FAVICON ENDS -->

<script src="{% url 'jsi18n' %}"></script>

{% block meta %}{% endblock %}

{% if settings.GOOGLE_ANALYTICS_ID and not request.user.profile.do_not_track %}
Expand Down Expand Up @@ -120,7 +122,7 @@
</div>
</nav>

<main role="main" class="container">
<main role="main" class="container" id="container">

{% block account_setup_alert %}
{% if account_needs_setup %}
Expand Down
8 changes: 8 additions & 0 deletions get_together/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@
"""
from django.conf import settings
from django.conf.urls.static import static
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth import views as auth_views
from django.urls import include, path
from django.views.i18n import JavaScriptCatalog

from events import feeds, views as event_views

from . import views

js_info_dict = {
'packages': ('recurrence', ),
}


urlpatterns = [
path("", views.home, name="home"),
path("admin/", admin.site.urls),
Expand Down Expand Up @@ -310,6 +317,7 @@
views.show_team_events_by_slug,
name="show-team-events-by-slug",
),
path('jsi18n.js', JavaScriptCatalog.as_view(packages=['recurrence']), name='jsi18n'),
]
if settings.DEBUG:
urlpatterns = urlpatterns + static(
Expand Down
12 changes: 6 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ certifi==2017.11.5
chardet==3.0.4
click==6.7
decorator==4.2.1
defusedxml==0.5.0
defusedxml==0.6.0
dj-database-url==0.4.2
Django==2.0.12
django-appconf==1.0.2
Django==3.2.13
django-appconf==1.0.5
django-ical==1.4
django-imagekit==4.0.2
django-imagekit-cropper==1.16
django-js-asset==1.0.0
django-mptt==0.9.0
https://github.com/GetTogetherComm/django-recurrence/releases/download/1.5.0/django-recurrence_1.5.0.tar.gz
django-mptt==0.13.4
django-recurrence==1.11.1
django-settings-export==1.2.1
djangorestframework==3.9.1
djangorestframework==3.13.1
future==0.16.0
geocoder==1.36.0
icalendar==4.0.1
Expand Down
2 changes: 1 addition & 1 deletion resume/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class ResumeConfig(AppConfig):
name = "Resume"
name = "resume"

0 comments on commit 6708944

Please sign in to comment.