Commit ea15a777 authored by Florent Chehab's avatar Florent Chehab

Project dockerized

parent 5b03c824
stages:
- check
- test
- linting
- 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: linting
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:
- testing
- test_back
script:
- mkdir .public
- mv backend/htmlcov/ .public/coverage
......
# 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_backend:
cd backend && pytest base_app/ frontend_app/ backend_app/
up--build:
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
......
# 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
"""
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/"
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")
......@@ -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:
......
[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
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:
# pull official base image
FROM node:10.15.1-alpine
WORKDIR /usr/src/app
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment