Skip to content
Snippets Groups Projects
Verified Commit f8ae14c8 authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

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
{
parent cfc948de
No related branches found
No related tags found
1 merge request!19Whitenoise
Pipeline #
...@@ -3,13 +3,13 @@ ...@@ -3,13 +3,13 @@
Dockerfile Dockerfile
# Django # Django
*/db.sqlite3 */db.sqlite3
*/__pycache__* */__pycache__*
*.pyc *.pyc
*.pyo *.pyo
*.pyd *.pyd
*/env* */env*
*/.venv*
pip-log.txt pip-log.txt
pip-delete-this-directory.txt pip-delete-this-directory.txt
.tox .tox
...@@ -19,6 +19,8 @@ pip-delete-this-directory.txt ...@@ -19,6 +19,8 @@ pip-delete-this-directory.txt
coverage.xml coverage.xml
*,cover *,cover
*.log *.log
static/
public/
# node # node
......
...@@ -21,6 +21,8 @@ build_backend: ...@@ -21,6 +21,8 @@ build_backend:
.test_template_backend: &test_definition_backend .test_template_backend: &test_definition_backend
stage: test stage: test
image: $IMAGE_TAG image: $IMAGE_TAG
before_script:
- pip install -r requirements.dev.txt
test_pytest: test_pytest:
<<: *test_definition_backend <<: *test_definition_backend
......
# Build Python files # Build Vue 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
FROM node:carbon as node FROM node:carbon as node
WORKDIR /app/ WORKDIR /app/
...@@ -19,19 +14,18 @@ ENV PYTHONUNBUFFERED 1 ...@@ -19,19 +14,18 @@ ENV PYTHONUNBUFFERED 1
# This set is need otherwise the postgres driver wont work # This set is need otherwise the postgres driver wont work
RUN apk update \ RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \ && apk add --virtual build-deps gcc python3-dev musl-dev curl \
&& apk add --no-cache postgresql-dev \ && apk add --no-cache postgresql-dev
&& pip install psycopg2 \
&& apk del build-deps
RUN mkdir -p /usr/share/dict RUN mkdir -p /usr/share/dict
RUN curl -s https://gitlab.gwdg.de/snippets/51/raw --output /usr/share/dict/words
WORKDIR /code WORKDIR /code
COPY . /code COPY . /code
COPY --from=python /root/.cache /root/.cache COPY --from=node /app/dist /code/frontend/dist
COPY --from=python /words /usr/share/dict/words COPY --from=node /app/dist/index.html /code/core/templates/index.html
COPY --from=node /app/dist /code/static
COPY --from=node /app/dist/index.html /code/core/templates
RUN pip install -r requirements.txt && rm -rf /root/.cache RUN pip install -r requirements.txt && rm -rf /root/.cache
RUN python manage.py collectstatic --noinput RUN python manage.py collectstatic --noinput
RUN apk del build-deps
...@@ -24,13 +24,14 @@ migrate: ...@@ -24,13 +24,14 @@ migrate:
install: install:
pip install -r requirements.txt pip install -r requirements.txt
pip install -r requirements.dev.txt
test: test:
DJANGO_SETTINGS_MODULE=grady.settings pytest DJANGO_SETTINGS_MODULE=grady.settings pytest
coverage: coverage:
coverage run manage.py test DJANGO_SETTINGS_MODULE=grady.settings pytest --cov
coverage report coverage html
db: db:
docker run --rm --name $(DB_NAME) -p 5432:5432 postgres:9.5 docker run --rm --name $(DB_NAME) -p 5432:5432 postgres:9.5
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
<title>Grady Frontend placeholder</title> <title>Grady Frontend placeholder</title>
</head> </head>
<body> <body>
This is just a placeholder and will be replaced in production. This will be replaced in production.
</body> </body>
</html> </html>
...@@ -16,10 +16,10 @@ router.register(r'student-page', views.StudentSelfApiViewSet, ...@@ -16,10 +16,10 @@ router.register(r'student-page', views.StudentSelfApiViewSet,
base_name='student_page') base_name='student_page')
urlpatterns = [ urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='index.html'), name="home"),
url(r'^api/', include(router.urls)), url(r'^api/', include(router.urls)),
url(r'^api-token-auth/', obtain_jwt_token), url(r'^api-token-auth/', obtain_jwt_token),
url(r'^api-token-refresh', refresh_jwt_token), url(r'^api-token-refresh', refresh_jwt_token),
url(r'^$', TemplateView.as_view(template_name='index.html')),
] ]
urlpatterns += staticfiles_urlpatterns() urlpatterns += staticfiles_urlpatterns()
...@@ -7,15 +7,18 @@ services: ...@@ -7,15 +7,18 @@ services:
restart: always restart: always
grady: grady:
image: docker.gitlab.gwdg.de/j.michal/grady:whitenoise build: .
command: command:
- /bin/sh - /bin/sh
- -c - -c
- | - |
sleep 5 sleep 5
python manage.py collectstatic --noinput
python manage.py migrate --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: depends_on:
- postgres - postgres
restart: always restart: always
......
...@@ -108,11 +108,13 @@ USE_TZ = True ...@@ -108,11 +108,13 @@ USE_TZ = True
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static') STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATICFILES_FINDERS = ( STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
) )
STATICFILES_DIRS = (
'frontend/dist/static',
)
GRAPH_MODELS = { GRAPH_MODELS = {
'all_applications': True, 'all_applications': True,
......
pytest-cov~=2.5.1
pytest-django~=3.1.2
prospector~=0.12.7
...@@ -4,9 +4,7 @@ djangorestframework~=3.6.3 ...@@ -4,9 +4,7 @@ djangorestframework~=3.6.3
djangorestframework-jwt~=1.11.0 djangorestframework-jwt~=1.11.0
django-cors-headers~=2.1.0 django-cors-headers~=2.1.0
gunicorn~=19.7.0 gunicorn~=19.7.0
gevent~=1.2.2
whitenoise~=3.3.1
psycopg2~=2.7.1 psycopg2~=2.7.1
xlrd~=1.0.0 xlrd~=1.0.0
pytest-cov~=2.5.1
pytest-django~=3.1.2
prospector~=0.12.7
whitenoise~=3.3.1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment