Skip to content

Commit

Permalink
Merge pull request #3 from hotosm/feature/add-custom-user-model
Browse files Browse the repository at this point in the history
Creating a custom user model for extensibility
  • Loading branch information
katporks authored Nov 28, 2023
2 parents 75256c2 + 7e0820f commit 260ebda
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 50 deletions.
25 changes: 14 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN pip install --no-cache-dir --upgrade pip \
poetry==1.7.1 poetry-plugin-export==1.6.0 \
&& poetry config warnings.export false
RUN poetry export --without dev --output requirements.txt
RUN poetry export --only dev --output requirements-dev.txt
RUN poetry export --with dev --output requirements-dev.txt


# Define build stage (install deps)
Expand Down Expand Up @@ -102,28 +102,31 @@ USER wagtail
ENTRYPOINT ["/container-entrypoint.sh"]


# Define dev-deps stage (install requirements-dev)
FROM runtime as dev-deps
COPY --from=extract-deps --chown=wagtail \
/opt/python/requirements-dev.txt /home/wagtail/
RUN pip install --user --no-warn-script-location \
--no-cache-dir -r /home/wagtail/requirements-dev.txt \
&& rm -r /home/wagtail/requirements-dev.txt


# Define test (ci) stage
FROM runtime as test
FROM dev-deps as test
USER root
ARG PYTHON_IMG_TAG
COPY --from=extract-deps \
/opt/python/requirements-dev.txt /opt/python/
# Copy packages from user to root dirs (run ci as root)
# && install dev dependencies (pytest)
RUN mv /home/wagtail/.local/bin/* /usr/local/bin/ \
&& mv /home/wagtail/.local/lib/python${PYTHON_IMG_TAG}/site-packages/* \
&& cp -R /home/wagtail/.local/lib/python${PYTHON_IMG_TAG}/site-packages/* \
/usr/local/lib/python${PYTHON_IMG_TAG}/site-packages/ \
&& pip install --upgrade --no-warn-script-location \
--no-cache-dir -r \
/opt/python/requirements-dev.txt \
&& rm -r /opt/python \
&& rm -rf /home/wagtail/.local/ \
# Pre-compile packages to .pyc (init speed gains)
&& python -c "import compileall; compileall.compile_path(maxlevels=10, quiet=1)"
CMD ["pytest"]


# Define debug (development) stage
FROM runtime as debug
FROM dev-deps as debug
# Add Healthcheck
HEALTHCHECK --start-period=10s --interval=5s --retries=20 --timeout=5s \
CMD curl --fail http://localhost:8000 || exit 1
Expand Down
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: build-dev build-prod test up-dev up-prod down-dev down-prod

build-dev:
build:
@docker compose -f docker-compose.dev.yml build
@docker compose -f docker-compose.dev.yml up -d

Expand All @@ -9,17 +9,15 @@ build-prod:
@docker compose -f docker-compose.prod.yml up -d

test:
@docker build --target test -t myproject:test -f Dockerfile .
@docker run --rm myproject:test
@docker rmi myproject:test
@docker compose -f docker-compose.dev.yml run --rm web pytest

up-dev:
up:
@docker compose -f docker-compose.dev.yml up -d

up-prod:
@docker compose -f docker-compose.prod.yml up

down-dev:
down:
@docker compose -f docker-compose.dev.yml down

down-prod:
Expand Down
15 changes: 12 additions & 3 deletions hot_osm/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
INSTALLED_APPS = [
"home",
"search",
"users",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",
Expand Down Expand Up @@ -130,8 +131,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand All @@ -150,7 +149,15 @@
# ManifestStaticFilesStorage is recommended in production, to prevent outdated
# JavaScript / CSS assets being served from cache (e.g. after a Wagtail upgrade).
# See https://docs.djangoproject.com/en/4.2/ref/contrib/staticfiles/#manifeststaticfilesstorage
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
"LOCATION": os.path.join(BASE_DIR, "media"),
},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
},
}

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
Expand All @@ -174,3 +181,5 @@
# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
WAGTAILADMIN_BASE_URL = "http://example.com"

AUTH_USER_MODEL = "users.User"
146 changes: 117 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 260ebda

Please sign in to comment.