Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit 13d8f27

Browse files
committed
wip serving quasar application from templates for cypress testing in gitlab ci
1 parent 1d1397d commit 13d8f27

File tree

11 files changed

+143
-14
lines changed

11 files changed

+143
-14
lines changed

backend/backend/settings/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
TEMPLATES = [
117117
{
118118
'BACKEND': 'django.template.backends.django.DjangoTemplates',
119-
'DIRS': [],
119+
'DIRS': [os.path.join(BASE_DIR, 'templates')],
120120
'APP_DIRS': True,
121121
'OPTIONS': {
122122
'context_processors': [

backend/backend/settings/gitlab-ci.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@
1919
},
2020
}
2121

22-
STATIC_URL = '/static/'
22+
MIDDLEWARE = [
23+
'corsheaders.middleware.CorsMiddleware',
24+
'django.middleware.security.SecurityMiddleware',
25+
'django.contrib.sessions.middleware.SessionMiddleware',
26+
'social_django.middleware.SocialAuthExceptionMiddleware',
27+
'django.middleware.common.CommonMiddleware',
28+
# disabled to simplify testing
29+
# 'django.middleware.csrf.CsrfViewMiddleware',
30+
'django.contrib.auth.middleware.AuthenticationMiddleware',
31+
'django.contrib.messages.middleware.MessageMiddleware',
32+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
33+
'core.middleware.SubdomainMiddleware',
34+
]
35+
36+
37+
STATIC_URL = '/'
2338

2439
STATIC_ROOT = '/static/'

backend/backend/urls.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
1515
"""
1616
from django.conf import settings
17+
from django.conf.urls.static import static
1718
from django.contrib import admin
1819
from django.urls import include, path
1920

21+
from core.views import index_view
22+
2023
urlpatterns = [
21-
path('', include('core.urls',)),
2224
path('admin/', admin.site.urls),
2325
path('api/', include('accounts.urls')),
2426
path('api/', include('core.urls'))
@@ -27,6 +29,7 @@
2729

2830
if settings.DEBUG:
2931
import debug_toolbar # noqa
30-
urlpatterns = [
32+
urlpatterns = urlpatterns + [
33+
path('', index_view, name='index'),
3134
path('admin/__debug__/', include(debug_toolbar.urls)),
32-
] + urlpatterns
35+
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

backend/core/views.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
from core.tasks import debug_task, send_test_email_task
88

9+
10+
from django.views.generic import TemplateView
11+
from django.views.decorators.cache import never_cache
12+
13+
# Serve Vue Application via template for GitLab CI
14+
index_view = never_cache(TemplateView.as_view(template_name='index.html'))
15+
916
r = settings.REDIS
1017

1118

backend/scripts/dev/start_ci.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
python3 manage.py collectstatic --no-input
3+
# python3 manage.py collectstatic --no-input
44
python3 manage.py makemigrations
55
python3 manage.py migrate --no-input
66
python3 manage.py create_default_user

backend/scripts/prod/Dockerfile

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
FROM python:3.7
1+
# build stage that generates quasar assets
2+
FROM node:10-alpine as build-stage
3+
ENV HTTP_PROTOCOL http
4+
ENV WS_PROTOCOL ws
5+
ENV DOMAIN_NAME localhost:8000
6+
WORKDIR /app/
7+
COPY quasar/package.json /app/
8+
RUN npm cache verify
9+
RUN npm install -g @quasar/cli
10+
RUN npm install --progress=false
11+
COPY quasar /app/
12+
RUN quasar build -m pwa
13+
14+
# this image is tagged and pushed to the production registry (such as ECR)
15+
FROM python:3.7 as production
216
ENV PYTHONUNBUFFERED 1
317
ENV PYTHONDONTWRITEBYTECODE 1
418
RUN mkdir /code
519
WORKDIR /code
6-
COPY requirements/base.txt /code/requirements/
20+
COPY backend/requirements/base.txt /code/requirements/
721
RUN python3 -m pip install --upgrade pip
822
RUN pip install -r requirements/base.txt
9-
COPY scripts/prod/start_prod.sh scripts/dev/start_ci.sh scripts/dev/start_asgi.sh /
10-
ADD . /code/
23+
COPY backend/scripts/prod/start_prod.sh \
24+
backend/scripts/dev/start_ci.sh \
25+
backend/scripts/dev/start_asgi.sh \
26+
/
27+
ADD backend /code/
28+
29+
# this stage is used for integration testing
30+
FROM production as gitlab-ci
31+
# cypress dependencies
32+
# RUN apt-get -qq update
33+
# RUN apt-get -qq install -y xvfb libgtk-3-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2
34+
# add static files from build
35+
COPY --from=build-stage /app/dist/pwa/index.html /code/templates/
36+
# COPY --from=build-stage /app/dist/pwa /code/static
37+
COPY --from=build-stage /app/dist/pwa /static
38+
# index.html is listed here
39+
RUN ls /code/templates/ -al
40+
# also tried this, but still nothing in the templates directory when the container is started
41+
RUN cp /static/index.html /code/templates/index.html

backend/templates/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

compose/test.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
version: '3.7'
2+
3+
services:
4+
postgres:
5+
container_name: postgres
6+
image: postgres
7+
networks:
8+
- main
9+
ports:
10+
- "5432:5432"
11+
volumes:
12+
- pg-data:/var/lib/postgresql/data
13+
environment:
14+
- POSTGRES_PASSWORD=${RDS_PASSWORD}
15+
- POSTGRES_USER=${RDS_USERNAME}
16+
- POSTGRES_DB=${RDS_DB_NAME}
17+
18+
redis:
19+
image: redis:alpine
20+
volumes:
21+
- redis-data:/data
22+
container_name: redis
23+
networks:
24+
- main
25+
26+
27+
backend: &backend
28+
container_name: backend
29+
build:
30+
context: ../
31+
dockerfile: backend/scripts/prod/Dockerfile
32+
ports:
33+
- "8000:8000"
34+
command: /start_ci.sh
35+
volumes:
36+
- django-static:/code/static
37+
networks:
38+
- main
39+
environment:
40+
- SECRET_KEY=${SECRET_KEY}
41+
- DEBUG=True
42+
- DJANGO_EMAIL_HOST=${DJANGO_EMAIL_HOST}
43+
- DJANGO_EMAIL_PORT=${DJANGO_EMAIL_PORT}
44+
- RDS_PASSWORD=${RDS_PASSWORD}
45+
- RDS_USERNAME=${RDS_USERNAME}
46+
- RDS_DB_NAME=${RDS_DB_NAME}
47+
- CELERY_BROKER_URL=${CELERY_BROKER_URL}
48+
- CELERY_RESULT_BACKEND=${CELERY_RESULT_BACKEND}
49+
- DJANGO_SETTINGS_MODULE=backend.settings.gitlab-ci
50+
- GITHUB_KEY=${GITHUB_KEY}
51+
- GITHUB_SECRET=${GITHUB_SECRET}
52+
- GOOGLE_OAUTH2_KEY=${GOOGLE_OAUTH2_KEY}
53+
- GOOGLE_OAUTH2_SECRET=${GOOGLE_OAUTH2_SECRET}
54+
55+
# # for Quasar
56+
# - HTTP_PROTOCOL=http
57+
# - WS_PROTOCOL=ws
58+
# - DOMAIN_NAME=${DOMAIN_NAME}
59+
depends_on:
60+
- postgres
61+
- redis
62+
63+
64+
volumes:
65+
pg-data:
66+
django-static:
67+
redis-data:
68+
69+
networks:
70+
main:
71+
driver: bridge

quasar/quasar.conf.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ module.exports = function(ctx) {
77
// --> boot files are part of "main.js"
88
boot: ["i18n", "axios", "components", "websockets"],
99
css: ["app.styl"],
10-
1110
extras: [
1211
// "ionicons-v4",
1312
// "mdi-v3",
@@ -73,7 +72,7 @@ module.exports = function(ctx) {
7372
),
7473
WS_PING_PONG: JSON.stringify(
7574
`${process.env.WS_PROTOCOL}://${
76-
process.env.LOCAL_IP_ADDRESS
75+
process.env.DOMAIN_NAME
7776
}/ws/ping-pong/`
7877
),
7978
GITHUB_KEY: JSON.stringify(process.env.GITHUB_KEY),
@@ -82,6 +81,7 @@ module.exports = function(ctx) {
8281
scopeHoisting: true,
8382
useNotifier: false,
8483
vueRouterMode: "history",
84+
// comments
8585
// vueCompiler: true,
8686
// gzip: true,
8787
// analyze: true,

quasar/src/pages/About.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<h4>About this site...</h4>
55
<p>
66
This site is built with Django, Vue, Postgres, nginx, docker, and other
7-
technologies.
7+
technologies...
88
</p>
99
</q-page>
1010
</q-page-container>

0 commit comments

Comments
 (0)