Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
ea15a777
Commit
ea15a777
authored
Feb 11, 2019
by
Florent Chehab
Browse files
Project dockerized
parent
5b03c824
Changes
10
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
ea15a777
stages
:
-
check
-
test
-
lint
ing
-
lint
-
documentation
-
deploy
variables
:
ENV
:
CI
POSTGRES_DB
:
outgoing
POSTGRES_USER
:
outgoing
POSTGRES_PASSWORD
:
"
"
ENV
:
DEV
SECRET_KEY
:
stupid_key_for_CI
POSTGRES_DB
:
postgres
POSTGRES_USER
:
postgres
POSTGRES_PASSWORD
:
postgres
DB_HOST
:
postgres
DB_PORT
:
5432
testing
:
check_back
:
stage
:
check
image
:
registry.gitlab.utc.fr/rex-dri/rex-dri/backend
services
:
-
postgres:10.5
script
:
-
cd backend
-
./manage.py check
tags
:
-
docker
check_front
:
stage
:
check
image
:
node:10.15.1-alpine
cache
:
paths
:
-
frontend/node_modules/
before_script
:
-
cd frontend && npm i
script
:
-
npm run build
tags
:
-
docker
test_back
:
stage
:
test
image
:
python:3.6.5-jessie
image
:
registry.gitlab.utc.fr/rex-dri/rex-dri/backend
services
:
-
postgres:
9.6.8
-
postgres:
10.5
script
:
-
make install_backend
-
make check_backend
-
make test_backend_server
-
cd backend
-
pytest base_app/ frontend_app/ backend_app/ --cov-report html
artifacts
:
paths
:
-
backend/htmlcov/
...
...
@@ -27,19 +54,23 @@ testing:
-
docker
flake8
:
stage
:
lint
ing
image
:
python:3.6.5-jessie
stage
:
lint
image
:
registry.gitlab.utc.fr/rex-dri/rex-dri/backend
script
:
-
pip install flake8
-
cd backend && flake8
tags
:
-
docker
eslint
:
stage
:
linting
image
:
pipelinecomponents/eslint:latest
stage
:
lint
image
:
node:10.15.1-alpine
cache
:
paths
:
-
frontend/node_modules/
before_script
:
-
cd frontend && npm i
script
:
-
cd frontend &&
npm run lint
-
npm run lint
tags
:
-
docker
...
...
@@ -47,7 +78,7 @@ pages:
stage
:
documentation
image
:
floawfloaw/plantuml
dependencies
:
-
test
ing
-
test
_back
script
:
-
mkdir .public
-
mv backend/htmlcov/ .public/coverage
...
...
Makefile
View file @
ea15a777
# You need to have source the env before using the makefile
.PHONY
:
docs
.PHONY
:
documentation
install_backend
:
cd
backend
&&
pip
install
-r
requirements.txt
--quiet
up
:
docker-compose up
build_frontend
:
cd
frontend
&&
npm run build
docker-pull
:
docker-compose pull
test_backen
d
:
cd
backend
&&
pytest base_app/ frontend_app/ backend_app/
up--buil
d
:
docker-compose up
--build
test_backend
_server
:
cd
backend
&&
pytest
-n
4
base_app/ frontend_app/ backend_app/
--cov-report
html
test_backend
:
docker-compose
exec
backend sh
-c
"
cd backend && pytest base_app/ frontend_app/ backend_app/
"
check_backend
:
cd
backend
&&
./manage.py check
docker-compose
exec
backend sh
-c
"cd backend && ./manage.py check"
lint_backend
:
docker-compose
exec
backend sh
-c
"cd backend && flake8"
lint_frontend
:
docker-compose
exec
frontend sh
-c
"cd frontend && npm run lint"
build_frontend
:
docker-compose
exec
frontend sh
-c
"cd frontend && npm run build"
run
_backend
:
cd
backend
&&
./manage.py runserver
shell
_backend
:
docker-compose
exec
backend sh
shell_frontend
:
docker-compose
exec
frontend sh
documentation
:
cd
documentation
&&
$(MAKE)
all
...
...
backend/Dockerfile
0 → 100644
View file @
ea15a777
# pull official base image
# Use of stretch instead of Alpine for faster install of python packages (especially pandas)
# Overall performance might be slightly better (with bigger image size obviously)
FROM
python:3.7.2-slim-stretch
# set work directory
WORKDIR
/usr/src/app
# runtime dependencies
# libpq-dev and gcc is for psycopg2-binary
RUN
apt-get update
&&
apt-get
install
-y
--no-install-recommends
\
libpq-dev
\
python3-dev
\
gcc
\
make
\
&&
rm
-rf
/var/lib/apt/lists/
*
# install dependencies
RUN
pip
install
--upgrade
pip
COPY
requirements.txt /usr/src/app/requirements.txt
RUN
pip
install
-r
requirements.txt
backend/base_app/settings
/base
.py
→
backend/base_app/settings.py
View file @
ea15a777
"""
Django settings for outgoing_rex project.
Generated by 'django-admin startproject' using Django 2.0.3.
Django settings
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
...
...
@@ -14,29 +12,10 @@ import os
from
os.path
import
dirname
import
sys
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR
=
dirname
(
dirname
(
dirname
(
os
.
path
.
abspath
(
__file__
))))
##########
# Webpack loader related
WEBPACK_LOADER
=
{
"DEFAULT"
:
{
"BUNDLE_DIR_NAME"
:
"frontend_app/bundles/"
,
"STATS_FILE"
:
os
.
path
.
join
(
BASE_DIR
,
"../frontend/webpack-stats.json"
),
}
}
STATICFILES_DIRS
=
(
os
.
path
.
join
(
BASE_DIR
,
"static/frontend_app/bundles/"
),
# We do this so that django's collectstatic copies or our bundles to the STATIC_ROOT or syncs them to whatever storage we use.
)
# End of webpack loader related
###########
SECRET_KEY
=
os
.
environ
[
"SECRET_KEY"
]
# Application definition
INSTALLED_APPS
=
[
...
...
@@ -66,15 +45,41 @@ MIDDLEWARE = [
"django.middleware.clickjacking.XFrameOptionsMiddleware"
,
"base_app.middleware.LoginRequiredMiddleware"
,
]
MODERATION_ACTIVATED
=
True
TESTING
=
"pytest"
in
sys
.
modules
if
os
.
environ
[
"ENV"
]
==
"DEV"
:
DEBUG
=
True
ALLOWED_HOSTS
=
[
"*"
]
INSTALLED_APPS
+=
[
"django_extensions"
,
"debug_toolbar"
]
MIDDLEWARE
=
[
"debug_toolbar.middleware.DebugToolbarMiddleware"
]
+
MIDDLEWARE
ALLOWED_PHOTOS_EXTENSION
=
[
"jpg"
,
"jpeg"
,
"png"
,
"svg"
]
else
:
DEBUG
=
False
##########
# Webpack loader related
WEBPACK_LOADER
=
{
"DEFAULT"
:
{
"BUNDLE_DIR_NAME"
:
"frontend_app/bundles/"
,
"STATS_FILE"
:
os
.
path
.
join
(
BASE_DIR
,
"frontend/webpack-stats.json"
),
}
}
STATICFILES_DIRS
=
(
os
.
path
.
join
(
BASE_DIR
,
"static/frontend_app/bundles/"
),
# We do this so that django's collectstatic copies or our bundles to the STATIC_ROOT or syncs them to whatever storage we use.
)
# End of webpack loader related
###########
ALLOWED_PHOTOS_EXTENSION
=
[
"jpg"
,
"jpeg"
,
"png"
,
"svg"
]
INTERNAL_IPS
=
[
"127.0.0.1"
]
LOGIN_URL
=
"/user/login"
LOGIN_EXEMPT_URLS
=
[
LOGIN_URL
,
"/admin/"
,
"api"
]
LOGIN_EXEMPT_URLS
=
[
LOGIN_URL
,
"/admin/"
]
AUTHENTICATION_BACKENDS
=
[
"django.contrib.auth.backends.ModelBackend"
,
...
...
@@ -85,6 +90,11 @@ CAS_SERVER_URL = "https://cas.utc.fr/cas/"
CAS_APPLY_ATTRIBUTES_TO_USER
=
True
CAS_RENAME_ATTRIBUTES
=
{
"mail"
:
"email"
,
"givenName"
:
"first_name"
,
"sn"
:
"last_name"
}
TESTING
=
"pytest"
in
sys
.
modules
if
TESTING
:
LOGIN_EXEMPT_URLS
.
append
(
"api"
)
REST_FRAMEWORK
=
{
# Use Django's standard `django.contrib.auth` permissions,
"DEFAULT_PERMISSION_CLASSES"
:
(
...
...
@@ -122,8 +132,25 @@ WSGI_APPLICATION = "base_app.wsgi.application"
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
# DB are set in other config files
DATABASES
=
{
"default"
:
None
}
DATABASES
=
{
"default"
:
{
"ENGINE"
:
"django.db.backends.postgresql_psycopg2"
,
"NAME"
:
os
.
environ
[
"POSTGRES_DB"
],
"USER"
:
os
.
environ
[
"POSTGRES_USER"
],
"PASSWORD"
:
os
.
environ
[
"POSTGRES_PASSWORD"
],
"HOST"
:
os
.
environ
[
"DB_HOST"
],
"PORT"
:
os
.
environ
[
"DB_PORT"
],
}
}
# To use Sqlite, uncomment below
# PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
# DATABASES = {
# "default": {
# "ENGINE": "django.db.backends.sqlite3",
# "NAME": os.path.join(PROJECT_DIR, "../database.db"),
# }
# }
# Password validation
...
...
@@ -149,5 +176,8 @@ USE_I18N = True
USE_L10N
=
True
USE_TZ
=
True
STATIC_URL
=
"/static/"
STATIC_ROOT
=
os
.
path
.
join
(
BASE_DIR
,
"static"
)
MEDIA_ROOT
=
os
.
path
.
join
(
BASE_DIR
,
"media"
)
MEDIA_URL
=
"/media/"
backend/base_app/settings/__init__.py
deleted
100644 → 0
View file @
5b03c824
backend/base_app/settings/development.py
deleted
100644 → 0
View file @
5b03c824
from
.base
import
*
INSTALLED_APPS
+=
[
"django_extensions"
,
"debug_toolbar"
]
MIDDLEWARE
=
[
"debug_toolbar.middleware.DebugToolbarMiddleware"
]
+
MIDDLEWARE
MODERATION_ACTIVATED
=
True
DEBUG
=
True
ALLOWED_HOSTS
=
[
"*"
]
SECRET_KEY
=
"0a1kbtt%as4624u*9+r+c%j1tlq&dc08==c3w604(4igc+t6tw"
# DATABASE
# After you have read the documentation, uncomment the
# block with the database system you would like to use.
# POSTGRESQL
# If bellow fails, your need to add DATABASE_URL and ENV to your virutalenv
try
:
CI_ENV
=
os
.
environ
[
"ENV"
]
==
"CI"
except
KeyError
:
CI_ENV
=
False
# Database config
if
CI_ENV
:
# Should reflect gitlab-ci.yml
DATABASES
=
{
"default"
:
{
"ENGINE"
:
"django.db.backends.postgresql_psycopg2"
,
"NAME"
:
"outgoing"
,
"USER"
:
"outgoing"
,
"PASSWORD"
:
""
,
"HOST"
:
"postgres"
,
"PORT"
:
"5432"
,
}
}
else
:
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'outgoing',
# 'USER': 'outgoing',
# 'PASSWORD': 'outgoing',
# 'HOST': '127.0.0.1',
# 'PORT': '5432',
# }
# }
# Sqlite
PROJECT_DIR
=
os
.
path
.
abspath
(
os
.
path
.
dirname
(
__file__
))
DATABASES
=
{
"default"
:
{
"ENGINE"
:
"django.db.backends.sqlite3"
,
"NAME"
:
os
.
path
.
join
(
PROJECT_DIR
,
"../database.db"
),
}
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL
=
"/static/"
STATIC_ROOT
=
os
.
path
.
join
(
BASE_DIR
,
"static"
)
backend/manage.py
View file @
ea15a777
...
...
@@ -3,7 +3,7 @@ import os
import
sys
if
__name__
==
"__main__"
:
os
.
environ
.
setdefault
(
"DJANGO_SETTINGS_MODULE"
,
"base_app.settings
.development
"
)
os
.
environ
.
setdefault
(
"DJANGO_SETTINGS_MODULE"
,
"base_app.settings"
)
try
:
from
django.core.management
import
execute_from_command_line
except
ImportError
as
exc
:
...
...
backend/pytest.ini
View file @
ea15a777
[pytest]
DJANGO_SETTINGS_MODULE
=
base_app.settings
.development
DJANGO_SETTINGS_MODULE
=
base_app.settings
python_files
=
tests.py test_*.py *_tests.py
addopts
=
--cov --cov-config .coveragerc --cov-report term
docker-compose.yml
0 → 100644
View file @
ea15a777
version
:
'
3.7'
services
:
backend
:
image
:
registry.gitlab.utc.fr/rex-dri/rex-dri/backend:latest
# build: ./backend
volumes
:
-
.:/usr/src/app/
ports
:
-
8000:8000
# Replicate the python server port
environment
:
-
ENV=DEV
-
SECRET_KEY=please_change_me
-
DB_HOST=database
-
DB_PORT=5432
-
POSTGRES_DB=postgres
-
POSTGRES_USER=postgres
-
POSTGRES_PASSWORD=postgres
command
:
/bin/sh -c "cd backend && ./manage.py runserver 0.0.0.0:8000"
depends_on
:
-
database
database
:
image
:
postgres:10.5-alpine
environment
:
-
POSTGRES_DB=postgres
-
POSTGRES_USER=postgres
-
POSTGRES_PASSWORD=postgres
volumes
:
-
postgres_data:/var/lib/postgresql/data/
frontend
:
build
:
./frontend
command
:
/bin/sh -c "cd frontend && npm i --verbose && npm run dev"
volumes
:
-
.:/usr/src/app/
ports
:
-
3000:3000
# Replicate the node server port
volumes
:
postgres_data
:
frontend/Dockerfile
0 → 100644
View file @
ea15a777
# pull official base image
FROM
node:10.15.1-alpine
WORKDIR
/usr/src/app
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment