From f8ae14c80139a7aff84e95c18801efcda86df4d9 Mon Sep 17 00:00:00 2001 From: janmax <j.michal@stud.uni-goettingen.de> Date: Thu, 30 Nov 2017 18:27:16 +0100 Subject: [PATCH] Restructured parts of the build process * using gevnts for async requests handling of gunicorn * serving the static frontend via gunicorn * split requirements into dev and general { --- .dockerignore | 4 +++- .gitlab-ci.yml | 2 ++ Dockerfile | 22 ++++++++-------------- Makefile | 5 +++-- core/templates/index.html | 2 +- core/urls.py | 2 +- docker-compose.yml | 9 ++++++--- grady/settings/default.py | 4 +++- requirements.dev.txt | 3 +++ requirements.txt | 6 ++---- 10 files changed, 32 insertions(+), 27 deletions(-) create mode 100644 requirements.dev.txt diff --git a/.dockerignore b/.dockerignore index fb00b3c0..5ea37856 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,13 +3,13 @@ Dockerfile # Django - */db.sqlite3 */__pycache__* *.pyc *.pyo *.pyd */env* +*/.venv* pip-log.txt pip-delete-this-directory.txt .tox @@ -19,6 +19,8 @@ pip-delete-this-directory.txt coverage.xml *,cover *.log +static/ +public/ # node diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7519a7a0..eca8a569 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,6 +21,8 @@ build_backend: .test_template_backend: &test_definition_backend stage: test image: $IMAGE_TAG + before_script: + - pip install -r requirements.dev.txt test_pytest: <<: *test_definition_backend diff --git a/Dockerfile b/Dockerfile index 32f12199..bbb5fbb5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,4 @@ -# Build Python files -FROM python:3.6 as python -COPY requirements.txt . -RUN pip install -r requirements.txt -RUN curl -s https://gitlab.gwdg.de/snippets/51/raw --output words - +# Build Vue files FROM node:carbon as node WORKDIR /app/ @@ -19,19 +14,18 @@ ENV PYTHONUNBUFFERED 1 # This set is need otherwise the postgres driver wont work RUN apk update \ - && apk add --virtual build-deps gcc python3-dev musl-dev \ - && apk add --no-cache postgresql-dev \ - && pip install psycopg2 \ - && apk del build-deps + && apk add --virtual build-deps gcc python3-dev musl-dev curl \ + && apk add --no-cache postgresql-dev RUN mkdir -p /usr/share/dict +RUN curl -s https://gitlab.gwdg.de/snippets/51/raw --output /usr/share/dict/words + WORKDIR /code COPY . /code -COPY --from=python /root/.cache /root/.cache -COPY --from=python /words /usr/share/dict/words -COPY --from=node /app/dist /code/static -COPY --from=node /app/dist/index.html /code/core/templates +COPY --from=node /app/dist /code/frontend/dist +COPY --from=node /app/dist/index.html /code/core/templates/index.html RUN pip install -r requirements.txt && rm -rf /root/.cache RUN python manage.py collectstatic --noinput +RUN apk del build-deps diff --git a/Makefile b/Makefile index 6a431b39..f8eb9cff 100644 --- a/Makefile +++ b/Makefile @@ -24,13 +24,14 @@ migrate: install: pip install -r requirements.txt + pip install -r requirements.dev.txt test: DJANGO_SETTINGS_MODULE=grady.settings pytest coverage: - coverage run manage.py test - coverage report + DJANGO_SETTINGS_MODULE=grady.settings pytest --cov + coverage html db: docker run --rm --name $(DB_NAME) -p 5432:5432 postgres:9.5 diff --git a/core/templates/index.html b/core/templates/index.html index 2377f17c..5f3e8da1 100644 --- a/core/templates/index.html +++ b/core/templates/index.html @@ -4,6 +4,6 @@ <title>Grady Frontend placeholder</title> </head> <body> -This is just a placeholder and will be replaced in production. +This will be replaced in production. </body> </html> diff --git a/core/urls.py b/core/urls.py index c431ec74..84557822 100644 --- a/core/urls.py +++ b/core/urls.py @@ -16,10 +16,10 @@ router.register(r'student-page', views.StudentSelfApiViewSet, base_name='student_page') urlpatterns = [ - url(r'^$', TemplateView.as_view(template_name='index.html'), name="home"), url(r'^api/', include(router.urls)), url(r'^api-token-auth/', obtain_jwt_token), url(r'^api-token-refresh', refresh_jwt_token), + url(r'^$', TemplateView.as_view(template_name='index.html')), ] urlpatterns += staticfiles_urlpatterns() diff --git a/docker-compose.yml b/docker-compose.yml index 662743d9..a35059a0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,15 +7,18 @@ services: restart: always grady: - image: docker.gitlab.gwdg.de/j.michal/grady:whitenoise + build: . command: - /bin/sh - -c - | sleep 5 - python manage.py collectstatic --noinput python manage.py migrate --noinput - gunicorn --bind 0.0.0.0:8000 grady.wsgi:application + gunicorn \ + --bind 0.0.0.0:8000 \ + --workers=2 \ + --worker-class=gevent \ + grady.wsgi:application depends_on: - postgres restart: always diff --git a/grady/settings/default.py b/grady/settings/default.py index d69a9b30..9b1b6e81 100644 --- a/grady/settings/default.py +++ b/grady/settings/default.py @@ -108,11 +108,13 @@ USE_TZ = True STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' - STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ) +STATICFILES_DIRS = ( + 'frontend/dist/static', +) GRAPH_MODELS = { 'all_applications': True, diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 00000000..ec236675 --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1,3 @@ +pytest-cov~=2.5.1 +pytest-django~=3.1.2 +prospector~=0.12.7 diff --git a/requirements.txt b/requirements.txt index e367d256..a74179a8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,9 +4,7 @@ djangorestframework~=3.6.3 djangorestframework-jwt~=1.11.0 django-cors-headers~=2.1.0 gunicorn~=19.7.0 +gevent~=1.2.2 +whitenoise~=3.3.1 psycopg2~=2.7.1 xlrd~=1.0.0 -pytest-cov~=2.5.1 -pytest-django~=3.1.2 -prospector~=0.12.7 -whitenoise~=3.3.1 -- GitLab