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

Production

parent b92d223e
......@@ -6,4 +6,5 @@ exclude =
node_modules/*
backend/urls.py
backend/admin.py
backend/permissions/__list_user_post_permission.py
\ No newline at end of file
backend/permissions/__list_user_post_permission.py
general/settings/development.py
......@@ -4,14 +4,18 @@ stages:
- doc
- deploy
variables:
ENV: CI
POSTGRES_DB: outgoing
POSTGRES_USER: outgoing
POSTGRES_PASSWORD: ""
testing:
stage: test
image: python:3.6.5-jessie
services:
- postgres:9.6.8
script:
- export ENV=development
- export DATABASE_URL=postgres://postgres:@postgres:5432/python-test-app
- make install_backend
- make check_backend
- make test_backend_server
......@@ -51,13 +55,21 @@ pages:
tags:
- docker
preprod:
deliver_for_production:
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:
- gem install dpl
- dpl --provider=heroku --app=outgoing-preprod --api-key=$HEROKU_API_KEY
- ssh $SERVER_USER_USERNAME@$SERVER 'bash -s' < deploy.sh
only:
- production
- production
tags:
- docker
\ No newline at end of file
- docker
......@@ -7,9 +7,15 @@ install_backend:
generate_backend:
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
generate_frontend: generate_frontend_files
npm run dev
build_frontend: generate_frontend_files
npm run build
test_backend: generate_backend
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
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/
"""
import os
from os.path import dirname
import sys
import django_heroku
import dj_database_url
# 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
......@@ -34,12 +34,9 @@ INSTALLED_APPS = [
'rest_framework.authtoken',
'backend',
'frontend',
'django_extensions',
'debug_toolbar',
]
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
......@@ -50,9 +47,8 @@ MIDDLEWARE = [
'general.middleware.LoginRequiredMiddleware',
]
# If we want to activate the moderation functionnalities
MODERATION_ACTIVATED = True
TESTING = "pytest" in sys.modules
ALLOWED_PHOTOS_EXTENSION = ["jpg", "jpeg", "png", "svg"]
INTERNAL_IPS = ['127.0.0.1']
......@@ -112,7 +108,7 @@ WSGI_APPLICATION = 'general.wsgi.application'
# Database
# 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 = {
'default': None
}
......@@ -144,59 +140,11 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'fr-fr'
TIME_ZONE = 'Europe/Paris'
USE_I18N = True
USE_L10N = 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_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
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()
......@@ -3,7 +3,7 @@ import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "general.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "general.settings.development")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
......
This diff is collapsed.
......@@ -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)",
"main": "manage.py",
"scripts": {
"dev": "make generate_frontend && webpack --mode development",
"build": "make generate_frontend && webpack --mode production",
"dev": "webpack --mode development",
"build": "webpack --mode production",
"test": "echo \"Error: no test specified\" && exit 1",
"stats": "webpack --profile --json > frontend/static/frontend/stats.json",
"view-stats": "webpack-bundle-analyzer frontend/static/frontend/stats.json"
......@@ -17,21 +17,22 @@
"author": "",
"license": "ISC",
"dependencies": {
"@material-ui/core": "^3.0.1",
"@material-ui/docs": "^1.0.0-alpha.5",
"@material-ui/lab": "^3.0.0-alpha.14",
"@material-ui/core": "^3.1.0",
"@material-ui/icons": "^2.0.3",
"@material-ui/lab": "^3.0.0-alpha.16",
"babel-polyfill": "^6.26.0",
"babel-preset-stage-0": "^6.24.1",
"cross-fetch": "^2.2.2",
"date-fns": "^2.0.0-alpha.16",
"downshift": "^2.2.0",
"extract-text-webpack-plugin": "^3.0.2",
"fuzzysort": "^1.1.4",
"js-cookie": "^2.2.0",
"leaflet.markercluster": "^1.3.0",
"leaflet": "^1.3.4",
"lodash": "^4.17.11",
"material-ui-pickers": "^1.0.0-rc.14",
"react": "^16.5.1",
"react-awesome-slider": "^0.5.2",
"react-dom": "^16.5.1",
"react-leaflet": "^2.0.1",
"react-markdown": "^3.6.0",
"react-redux": "^5.0.7",
"react-router-dom": "^4.3.1",
......@@ -39,13 +40,9 @@
"redux": "^4.0.0",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.3.0",
"style-loader": "^0.23.0",
"typeface-roboto": "0.0.54"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@material-ui/icons": "^2.0.3",
"autoprefixer": "^9.1.5",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
......@@ -58,20 +55,13 @@
"eslint": "^5.4.0",
"eslint-config-google": "^0.9.1",
"file-loader": "^2.0.0",
"leaflet": "^1.3.4",
"mini-css-extract-plugin": "^0.4.2",
"node-sass": "^4.9.3",
"postcss-loader": "^3.0.0",
"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-script": "^2.0.5",
"recharts": "^1.1.0",
"redux-devtools": "^3.4.1",
"sass-loader": "^7.1.0",
"weak-key": "^1.0.1",
"webpack": "^4.17.0",
"webpack-bundle-analyzer": "^3.0.2",
"webpack-cli": "^3.1.0"
......
[pytest]
DJANGO_SETTINGS_MODULE = general.settings
DJANGO_SETTINGS_MODULE = general.settings.development
python_files = tests.py test_*.py *_tests.py
addopts = --cov --cov-config .coveragerc --cov-report term
#OutGoing_REX
Django==2.0.3
django_heroku==0.3.1
gunicorn==19.7.1
psycopg2-binary==2.7.4
git+https://github.com/mingchen/django-cas-ng.git@e9c0472e326087bfb839487f0736a4e1454cffda#egg=django-cas-ng
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
Pillow==5.0.0
django-imagekit==4.0.2
django-reversion==2.0.13
django-reversion-compare==0.8.4
reverse-geocoder==1.5.1
pytest-django==3.4.2
pytest-cov==2.5.1
pytest-xdist==1.23.0
......@@ -21,3 +14,4 @@ django-debug-toolbar==1.9.1
pandas
pyyaml
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