From 4451df5001c4565e36368c8839ff31dd53c234f2 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Tue, 30 Jun 2020 11:38:58 +0100 Subject: [PATCH] Use Wagtail master --- .gitmodules | 3 ++ Dockerfile | 96 ++++++++++++++++++++++++------------- app.json | 16 +------ bakerydemo/api.py | 12 ++--- heroku.yml | 7 +++ requirements/base.txt | 2 +- requirements/production.txt | 2 +- wagtail | 1 + 8 files changed, 85 insertions(+), 54 deletions(-) create mode 100644 heroku.yml create mode 160000 wagtail diff --git a/.gitmodules b/.gitmodules index 0a9c226..08c0bd8 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "wagtail-localize-pontoon"] path = wagtail-localize-pontoon url = https://github.com/wagtail/wagtail-localize-pontoon.git +[submodule "wagtail"] + path = wagtail + url = https://github.com/kaedroho/wagtail.git diff --git a/Dockerfile b/Dockerfile index 761632b..ef5f8b3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,50 +1,82 @@ -FROM python:3.5-alpine +FROM node:14 as frontend -ADD requirements/ /requirements/ +RUN mkdir /code/ +WORKDIR /code/ + +# Compile static files +COPY ./wagtail ./wagtail +RUN cd ./wagtail && npm install --no-optional --no-audit --progress=false +RUN cd ./wagtail && npm run dist + +FROM python:3.7-slim + +# Install packages needed to run your application (not build deps): +# We need to recreate the /usr/share/man/man{1..8} directories first because +# they were clobbered by a parent image. RUN set -ex \ - && apk add --no-cache --virtual .build-deps \ - gcc \ - g++ \ - make \ - libc-dev \ - musl-dev \ - linux-headers \ - pcre-dev \ - postgresql-dev \ - libjpeg-turbo-dev \ - zlib-dev \ - git \ - && pyvenv /venv \ - && /venv/bin/pip install -U pip \ - && LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "/venv/bin/pip install -r /requirements/production.txt" \ - && runDeps="$( \ - scanelf --needed --nobanner --recursive /venv \ - | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ - | sort -u \ - | xargs -r apk info --installed \ - | sort -u \ - )" \ - && apk add --virtual .python-rundeps $runDeps \ - && apk del .build-deps \ - && apk add libjpeg-turbo pcre -RUN apk add --no-cache postgresql-client + && RUN_DEPS=" \ + libexpat1 \ + libjpeg62-turbo \ + libpcre3 \ + libpq5 \ + mime-support \ + postgresql-client \ + procps \ + zlib1g \ + " \ + && seq 1 8 | xargs -I{} mkdir -p /usr/share/man/man{} \ + && rm -rf /var/lib/apt/lists/* + +RUN set -ex \ + && BUILD_DEPS=" \ + build-essential \ + git \ + libexpat1-dev \ + libjpeg62-turbo-dev \ + libpcre3-dev \ + libpq-dev \ + zlib1g-dev \ + " \ + && apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \ + && python3.7 -m venv /venv \ + && rm -rf /var/lib/apt/lists/* + RUN mkdir /code/ WORKDIR /code/ ADD . /code/ +COPY --from=frontend /code/wagtail /code/wagtail + +RUN /venv/bin/pip install -U pip \ + && /venv/bin/pip install --no-cache-dir -r ./requirements/production.txt + EXPOSE 8000 # Add custom environment variables needed by Django or your settings file here: ENV DJANGO_SETTINGS_MODULE=bakerydemo.settings.production DJANGO_DEBUG=off -# uWSGI configuration (customize as needed): -ENV UWSGI_VIRTUALENV=/venv UWSGI_WSGI_FILE=bakerydemo/wsgi_production.py UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_WORKERS=2 UWSGI_THREADS=8 UWSGI_UID=1000 UWSGI_GID=2000 +# Tell uWSGI where to find your wsgi file: +ENV UWSGI_WSGI_FILE=bakerydemo/wsgi.py + +# Base uWSGI configuration (you shouldn't need to change these): +ENV UWSGI_VIRTUALENV=/venv UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_HTTP_AUTO_CHUNKED=1 UWSGI_HTTP_KEEPALIVE=1 UWSGI_UID=1000 UWSGI_GID=2000 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy + +# Number of uWSGI workers and threads per worker (customize as needed): +ENV UWSGI_WORKERS=2 UWSGI_THREADS=4 + +# uWSGI uploaded media file serving configuration: +ENV UWSGI_STATIC_MAP="/media/=/code/bakerydemo/media/" # Call collectstatic with dummy environment variables: RUN DATABASE_URL=postgres://none REDIS_URL=none /venv/bin/python manage.py collectstatic --noinput # make sure static files are writable by uWSGI process -RUN chown -R 1000:2000 /code/bakerydemo/media +RUN mkdir -p /code/bakerydemo/media/images && chown -R 1000:2000 /code/bakerydemo/media + +# mark the destination for images as a volume +VOLUME ["/code/bakerydemo/media/images/"] # start uWSGI, using a wrapper script to allow us to easily add more commands to container startup: ENTRYPOINT ["/code/docker-entrypoint.sh"] -CMD ["/venv/bin/uwsgi", "--http-auto-chunked", "--http-keepalive", "--static-map", "/media/=/code/bakerydemo/media/"] + +# Start uWSGI +CMD ["/venv/bin/uwsgi", "--show-config"] diff --git a/app.json b/app.json index 0b7bf3b..5f3d7af 100644 --- a/app.json +++ b/app.json @@ -1,17 +1,5 @@ { - "name": "WagtailBakeryDemo", - "description": "WagtailBakeryDemo", - "repository": "https://github.com/wagtail/bakerydemo", - "keywords": ["wagtail", "django"], - "env": { - "DJANGO_DEBUG": "off", - "DJANGO_SETTINGS_MODULE": "bakerydemo.settings.production", - "DJANGO_SECURE_SSL_REDIRECT": "on" - }, "scripts": { - "postdeploy": "django-admin.py migrate && django-admin.py load_initial_data && echo 'from wagtail.images.models import Rendition; Rendition.objects.all().delete()' | django-admin.py shell" - }, - "addons": [ - "heroku-postgresql:hobby-dev" - ] + "postdeploy": "django-admin.py migrate" + } } diff --git a/bakerydemo/api.py b/bakerydemo/api.py index 8d09d7e..2d9bc94 100644 --- a/bakerydemo/api.py +++ b/bakerydemo/api.py @@ -1,7 +1,7 @@ -from wagtail.api.v2.endpoints import PagesAPIEndpoint +from wagtail.api.v2.views import PagesAPIViewSet from wagtail.api.v2.router import WagtailAPIRouter -from wagtail.images.api.v2.endpoints import ImagesAPIEndpoint -from wagtail.documents.api.v2.endpoints import DocumentsAPIEndpoint +from wagtail.images.api.v2.views import ImagesAPIViewSet +from wagtail.documents.api.v2.views import DocumentsAPIViewSet # Create the router. "wagtailapi" is the URL namespace api_router = WagtailAPIRouter('wagtailapi') @@ -10,6 +10,6 @@ api_router = WagtailAPIRouter('wagtailapi') # The first parameter is the name of the endpoint (eg. pages, images). This # is used in the URL of the endpoint # The second parameter is the endpoint class that handles the requests -api_router.register_endpoint('pages', PagesAPIEndpoint) -api_router.register_endpoint('images', ImagesAPIEndpoint) -api_router.register_endpoint('documents', DocumentsAPIEndpoint) +api_router.register_endpoint('pages', PagesAPIViewSet) +api_router.register_endpoint('images', ImagesAPIViewSet) +api_router.register_endpoint('documents', DocumentsAPIViewSet) diff --git a/heroku.yml b/heroku.yml new file mode 100644 index 0000000..8ffc51f --- /dev/null +++ b/heroku.yml @@ -0,0 +1,7 @@ +build: + docker: + web: Dockerfile +release: + image: web + command: + - django-admin migrate --noinput diff --git a/requirements/base.txt b/requirements/base.txt index 4281f6e..70a8b52 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -1,6 +1,6 @@ Django>=2.1,<2.2 django-dotenv==1.4.1 -Wagtail==2.7 +-e ./wagtail wagtailfontawesome>=1.1.3,<1.2 Pillow==4.0.0 diff --git a/requirements/production.txt b/requirements/production.txt index 267c41b..34ded07 100644 --- a/requirements/production.txt +++ b/requirements/production.txt @@ -5,7 +5,7 @@ elasticsearch==2.4.1 # Additional dependencies for Heroku deployment dj-database-url==0.4.1 uwsgi==2.0.18 -psycopg2==2.8.4 +psycopg2==2.8.5 whitenoise==3.2.2 boto==2.45.0 django-storages==1.6.5 diff --git a/wagtail b/wagtail new file mode 160000 index 0000000..80f7db7 --- /dev/null +++ b/wagtail @@ -0,0 +1 @@ +Subproject commit 80f7db750aceead11ab3f4c9d410bd227d203495