Commit 42b8f916 authored by Florent Chehab's avatar Florent Chehab
Browse files

Production

parent b92d223e
...@@ -6,4 +6,5 @@ exclude = ...@@ -6,4 +6,5 @@ exclude =
node_modules/* node_modules/*
backend/urls.py backend/urls.py
backend/admin.py backend/admin.py
backend/permissions/__list_user_post_permission.py backend/permissions/__list_user_post_permission.py
\ No newline at end of file general/settings/development.py
...@@ -4,14 +4,18 @@ stages: ...@@ -4,14 +4,18 @@ stages:
- doc - doc
- deploy - deploy
variables:
ENV: CI
POSTGRES_DB: outgoing
POSTGRES_USER: outgoing
POSTGRES_PASSWORD: ""
testing: testing:
stage: test stage: test
image: python:3.6.5-jessie image: python:3.6.5-jessie
services: services:
- postgres:9.6.8 - postgres:9.6.8
script: script:
- export ENV=development
- export DATABASE_URL=postgres://postgres:@postgres:5432/python-test-app
- make install_backend - make install_backend
- make check_backend - make check_backend
- make test_backend_server - make test_backend_server
...@@ -51,13 +55,21 @@ pages: ...@@ -51,13 +55,21 @@ pages:
tags: tags:
- docker - docker
preprod: deliver_for_production:
type: deploy type: deploy
image: ruby before_script:
## look here for info : https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
- 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "$SSH_KNOWN_HOSTS" > ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script: script:
- gem install dpl - ssh $SERVER_USER_USERNAME@$SERVER 'bash -s' < deploy.sh
- dpl --provider=heroku --app=outgoing-preprod --api-key=$HEROKU_API_KEY
only: only:
- production - production
tags: tags:
- docker - docker
\ No newline at end of file
...@@ -7,9 +7,15 @@ install_backend: ...@@ -7,9 +7,15 @@ install_backend:
generate_backend: generate_backend:
export PYTHONPATH=$$PWD ; python ./backend/generate/generate_backend_files.py export PYTHONPATH=$$PWD ; python ./backend/generate/generate_backend_files.py
generate_frontend: generate_frontend_files:
export PYTHONPATH=$$PWD ; python ./frontend/generate/generate_frontend_files.py export PYTHONPATH=$$PWD ; python ./frontend/generate/generate_frontend_files.py
generate_frontend: generate_frontend_files
npm run dev
build_frontend: generate_frontend_files
npm run build
test_backend: generate_backend test_backend: generate_backend
pytest pytest
......
release: python manage.py migrate && python manage.py createinitialrevisions
web: gunicorn general.wsgi
#!/bin/bash
set -e
cd outgoing_rex
git pull || { echo "Failed on 'git pull'"; exit 1; }
source ./env/bin/activate
make install_backend || { echo "Failed on 'make install_backend'"; exit 2; }
npm install || { echo "Failed on 'npm install'"; exit 3; }
make build_frontend || { echo "Failed on 'make build_frontend '"; exit 4; }
./manage.py migrate --settings general.settings.production || { echo "Failed on django migrate" exit 5; }
./manage.py createinitialrevisions --settings general.settings.production || { echo "Failed on django migrate" exit 6; }
./manage.py collectstatic --noinput --settings general.settings.production || { echo "Failed on django migrate" exit 7; }
#OutGoing_REX_dev #OutGoing_REX_dev
requests ipython
\ No newline at end of file
production.py
\ No newline at end of file
...@@ -11,12 +11,12 @@ https://docs.djangoproject.com/en/2.0/ref/settings/ ...@@ -11,12 +11,12 @@ https://docs.djangoproject.com/en/2.0/ref/settings/
""" """
import os import os
from os.path import dirname
import sys import sys
import django_heroku
import dj_database_url
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
# Application definition # Application definition
...@@ -34,12 +34,9 @@ INSTALLED_APPS = [ ...@@ -34,12 +34,9 @@ INSTALLED_APPS = [
'rest_framework.authtoken', 'rest_framework.authtoken',
'backend', 'backend',
'frontend', 'frontend',
'django_extensions',
'debug_toolbar',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware', 'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
...@@ -50,9 +47,8 @@ MIDDLEWARE = [ ...@@ -50,9 +47,8 @@ MIDDLEWARE = [
'general.middleware.LoginRequiredMiddleware', 'general.middleware.LoginRequiredMiddleware',
] ]
# If we want to activate the moderation functionnalities
MODERATION_ACTIVATED = True
TESTING = "pytest" in sys.modules TESTING = "pytest" in sys.modules
ALLOWED_PHOTOS_EXTENSION = ["jpg", "jpeg", "png", "svg"] ALLOWED_PHOTOS_EXTENSION = ["jpg", "jpeg", "png", "svg"]
INTERNAL_IPS = ['127.0.0.1'] INTERNAL_IPS = ['127.0.0.1']
...@@ -112,7 +108,7 @@ WSGI_APPLICATION = 'general.wsgi.application' ...@@ -112,7 +108,7 @@ WSGI_APPLICATION = 'general.wsgi.application'
# Database # Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases # https://docs.djangoproject.com/en/2.0/ref/settings/#databases
# DB are set at the end of the file # DB are set in other config files
DATABASES = { DATABASES = {
'default': None 'default': None
} }
...@@ -144,59 +140,11 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -144,59 +140,11 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/ # https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'Europe/Paris' TIME_ZONE = 'Europe/Paris'
USE_I18N = True USE_I18N = True
USE_L10N = True USE_L10N = True
USE_TZ = True USE_TZ = True
# override DATABASE_URL set by django_heroku because it forces SSL mode locally
try:
dev_env = os.environ['ENV'] == 'development'
except KeyError:
dev_env = False
if dev_env:
print("You are running in development mode")
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
locals()['DATABASES']['default'] = dj_database_url.config(
conn_max_age=django_heroku.MAX_CONN_AGE, ssl_require=not dev_env)
# # 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')
else:
# We should be on heroku server
print("You are running in production mode")
django_heroku.settings(locals())
DEBUG = True # TODO CHANGE TO FALSE BEFORE GOING IN REAL PRODUCTION
MEDIA_ROOT = os.path.join(BASE_DIR, 'media') MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/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')
from .base import *
# Debug shouldn't be activated in production
DEBUG = False
# Is moderation activated (model moderation level is set to 1)
MODERATION_ACTIVATED = False
# Database config
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'DB_DATABASE_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_USER_PASSWORD',
'HOST': 'localhost',
'PORT': '',
}
}
SECRET_KEY = 'a_random_string'
ALLOWED_HOSTS = ['your_production_domain_or_ip', 'your_local_domain']
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
...@@ -11,6 +11,6 @@ import os ...@@ -11,6 +11,6 @@ import os
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "general.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "general.settings.production")
application = get_wsgi_application() application = get_wsgi_application()
...@@ -3,7 +3,7 @@ import os ...@@ -3,7 +3,7 @@ import os
import sys import sys
if __name__ == "__main__": if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "general.settings") os.environ.setdefault("DJANGO_SETTINGS_MODULE", "general.settings.development")
try: try:
from django.core.management import execute_from_command_line from django.core.management import execute_from_command_line
except ImportError as exc: except ImportError as exc:
......
This diff is collapsed.
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
"description": "[![build](/../badges/master/build.svg)](https://gitlab.utc.fr/chehabfl/outgoing_rex/pipelines) [![coverage](/../badges/master/coverage.svg)](https://chehabfl.gitlab.utc.fr/outgoing_rex/) [![License](https://img.shields.io/badge/License-BSD%202--Clause-green.svg)](https://opensource.org/licenses/BSD-2-Clause)", "description": "[![build](/../badges/master/build.svg)](https://gitlab.utc.fr/chehabfl/outgoing_rex/pipelines) [![coverage](/../badges/master/coverage.svg)](https://chehabfl.gitlab.utc.fr/outgoing_rex/) [![License](https://img.shields.io/badge/License-BSD%202--Clause-green.svg)](https://opensource.org/licenses/BSD-2-Clause)",
"main": "manage.py", "main": "manage.py",
"scripts": { "scripts": {
"dev": "make generate_frontend && webpack --mode development", "dev": "webpack --mode development",
"build": "make generate_frontend && webpack --mode production", "build": "webpack --mode production",
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"stats": "webpack --profile --json > frontend/static/frontend/stats.json", "stats": "webpack --profile --json > frontend/static/frontend/stats.json",
"view-stats": "webpack-bundle-analyzer frontend/static/frontend/stats.json" "view-stats": "webpack-bundle-analyzer frontend/static/frontend/stats.json"
...@@ -17,21 +17,22 @@ ...@@ -17,21 +17,22 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"@material-ui/core": "^3.0.1", "@material-ui/core": "^3.1.0",
"@material-ui/docs": "^1.0.0-alpha.5", "@material-ui/icons": "^2.0.3",
"@material-ui/lab": "^3.0.0-alpha.14", "@material-ui/lab": "^3.0.0-alpha.16",
"babel-polyfill": "^6.26.0", "babel-polyfill": "^6.26.0",
"babel-preset-stage-0": "^6.24.1", "babel-preset-stage-0": "^6.24.1",
"cross-fetch": "^2.2.2",
"date-fns": "^2.0.0-alpha.16", "date-fns": "^2.0.0-alpha.16",
"downshift": "^2.2.0", "downshift": "^2.2.0",
"extract-text-webpack-plugin": "^3.0.2",
"fuzzysort": "^1.1.4", "fuzzysort": "^1.1.4",
"js-cookie": "^2.2.0", "js-cookie": "^2.2.0",
"leaflet.markercluster": "^1.3.0", "leaflet": "^1.3.4",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"material-ui-pickers": "^1.0.0-rc.14", "material-ui-pickers": "^1.0.0-rc.14",
"react": "^16.5.1",
"react-awesome-slider": "^0.5.2", "react-awesome-slider": "^0.5.2",
"react-dom": "^16.5.1",
"react-leaflet": "^2.0.1",
"react-markdown": "^3.6.0", "react-markdown": "^3.6.0",
"react-redux": "^5.0.7", "react-redux": "^5.0.7",
"react-router-dom": "^4.3.1", "react-router-dom": "^4.3.1",
...@@ -39,13 +40,9 @@ ...@@ -39,13 +40,9 @@
"redux": "^4.0.0", "redux": "^4.0.0",
"redux-logger": "^3.0.6", "redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0", "redux-thunk": "^2.3.0",
"style-loader": "^0.23.0",
"typeface-roboto": "0.0.54" "typeface-roboto": "0.0.54"
}, },
"devDependencies": { "devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@material-ui/icons": "^2.0.3",
"autoprefixer": "^9.1.5", "autoprefixer": "^9.1.5",
"babel-core": "^6.26.3", "babel-core": "^6.26.3",
"babel-loader": "^7.1.5", "babel-loader": "^7.1.5",
...@@ -58,20 +55,13 @@ ...@@ -58,20 +55,13 @@
"eslint": "^5.4.0", "eslint": "^5.4.0",
"eslint-config-google": "^0.9.1", "eslint-config-google": "^0.9.1",
"file-loader": "^2.0.0", "file-loader": "^2.0.0",
"leaflet": "^1.3.4",
"mini-css-extract-plugin": "^0.4.2", "mini-css-extract-plugin": "^0.4.2",
"node-sass": "^4.9.3", "node-sass": "^4.9.3",
"postcss-loader": "^3.0.0", "postcss-loader": "^3.0.0",
"prop-types": "^15.6.2", "prop-types": "^15.6.2",
"react": "^16.4.2",
"react-dom": "^16.4.2",
"react-leaflet": "^2.0.1",
"react-lorem-component": "^0.13.0", "react-lorem-component": "^0.13.0",
"react-script": "^2.0.5", "react-script": "^2.0.5",
"recharts": "^1.1.0",
"redux-devtools": "^3.4.1",
"sass-loader": "^7.1.0", "sass-loader": "^7.1.0",
"weak-key": "^1.0.1",
"webpack": "^4.17.0", "webpack": "^4.17.0",
"webpack-bundle-analyzer": "^3.0.2", "webpack-bundle-analyzer": "^3.0.2",
"webpack-cli": "^3.1.0" "webpack-cli": "^3.1.0"
......
[pytest] [pytest]
DJANGO_SETTINGS_MODULE = general.settings DJANGO_SETTINGS_MODULE = general.settings.development
python_files = tests.py test_*.py *_tests.py python_files = tests.py test_*.py *_tests.py
addopts = --cov --cov-config .coveragerc --cov-report term addopts = --cov --cov-config .coveragerc --cov-report term
#OutGoing_REX #OutGoing_REX
Django==2.0.3 Django==2.0.3
django_heroku==0.3.1
gunicorn==19.7.1
psycopg2-binary==2.7.4 psycopg2-binary==2.7.4
git+https://github.com/mingchen/django-cas-ng.git@e9c0472e326087bfb839487f0736a4e1454cffda#egg=django-cas-ng git+https://github.com/mingchen/django-cas-ng.git@e9c0472e326087bfb839487f0736a4e1454cffda#egg=django-cas-ng
djangorestframework==3.8.2 # Django REST Framework djangorestframework==3.8.2 # Django REST Framework
markdown==2.6.11 # Complement for Django REST framework
django-filter==1.1.0 # Support filter in REST API
coreapi==2.3.3 # Automatic API doc generation coreapi==2.3.3 # Automatic API doc generation
Pillow==5.0.0
django-imagekit==4.0.2
django-reversion==2.0.13 django-reversion==2.0.13
django-reversion-compare==0.8.4 django-reversion-compare==0.8.4
reverse-geocoder==1.5.1
pytest-django==3.4.2 pytest-django==3.4.2
pytest-cov==2.5.1 pytest-cov==2.5.1
pytest-xdist==1.23.0 pytest-xdist==1.23.0
...@@ -21,3 +14,4 @@ django-debug-toolbar==1.9.1 ...@@ -21,3 +14,4 @@ django-debug-toolbar==1.9.1
pandas pandas
pyyaml pyyaml
git+https://github.com/FloChehab/django-extensions.git@30c1a807aeb985739358d70907496e98d1857abb#egg=django-extensions git+https://github.com/FloChehab/django-extensions.git@30c1a807aeb985739358d70907496e98d1857abb#egg=django-extensions
uwsgi
\ No newline at end of file
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