Commit 00feaa02 by Nicolas Joyard

Add openshift deployment scripts

parent cd8d01be
export OPENSHIFT_PYTHON_WSGI_APPLICATION=wsgi.py
export PARLAPI_CONFIG=parlapi.config.OpenshiftConfig
#!/bin/bash
set -xe
source ${OPENSHIFT_HOMEDIR}app-root/runtime/dependencies/python/virtenv/bin/activate
pip install -U pip setuptools
pip install -Ue ${OPENSHIFT_REPO_DIR}
export PARLAPI_CONFIG=OpenshiftConfig
parlapi createdb
#!/bin/bash
export PARLAPI_CONFIG=parlapi.config.OpenshiftConfig
parlapi update_organes_an
parlapi update_acteurs_an
...@@ -41,3 +41,16 @@ $ parlapi update_organes_an ...@@ -41,3 +41,16 @@ $ parlapi update_organes_an
$ parlapi update_acteurs_an $ parlapi update_acteurs_an
$ parlapi runserver $ parlapi runserver
``` ```
### Déploiement Openshift
```bash
$ export APP=parlapi
$ rhc app-create $APP python-2.7 postgresql-9.2
$ rhc env set -a $APP OPENSHIFT_PYTHON_WSGI_APPLICATION=wsgi.py
$ rhc env set -a $APP PARLAPI_CONFIG=parlapi.config.OpenshiftConfig
$ rhc app show -a $APP | grep Git
Git URL: ssh://xxx@parlapi-xxx.rhcloud.com/~/git/parlapi.git/
$ git remote add openshift ssh://xxx@parlapi-xxx.rhcloud.com/~/git/parlapi.git/
$ git push --force openshift openshift:master
```
...@@ -6,7 +6,7 @@ import os ...@@ -6,7 +6,7 @@ import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class Config(object): class DefaultConfig(object):
DEBUG = False DEBUG = False
SECRET_KEY = 'not secret' SECRET_KEY = 'not secret'
SQLALCHEMY_DATABASE_URI = \ SQLALCHEMY_DATABASE_URI = \
...@@ -16,8 +16,33 @@ class Config(object): ...@@ -16,8 +16,33 @@ class Config(object):
API_PAGE_SIZE = 10 API_PAGE_SIZE = 10
class DebugConfig(Config): class DebugConfig(DefaultConfig):
DEBUG = True DEBUG = True
CurrentConfig = DebugConfig class OpenshiftConfig(DefaultConfig):
SQLALCHEMY_DATABASE_URI = \
'postgresql://%(user)s:%(pass)s@%(host)s:%(port)s/%(name)s' % {
'name': os.environ['OPENSHIFT_APP_NAME'],
'user': os.environ['OPENSHIFT_POSTGRESQL_DB_USERNAME'],
'pass': os.environ['OPENSHIFT_POSTGRESQL_DB_PASSWORD'],
'host': os.environ['OPENSHIFT_POSTGRESQL_DB_HOST'],
'port': os.environ['OPENSHIFT_POSTGRESQL_DB_PORT'],
}
DATA_DIR = os.environ['OPENSHIFT_DATA_DIR']
SECRET_FILE = os.path.join(DATA_DIR, 'secret.txt')
if not os.path.exists(SECRET_FILE):
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
from random import SystemRandom
rnd = SystemRandom()
key = ''.join([chars[rnd.randint(1, len(chars))-1]
for i in range(1, 50)])
with open(SECRET_FILE, 'w+') as f:
f.write(key)
with open(SECRET_FILE, 'r') as f:
SECRET_KEY = f.read()
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os
from flask import Flask from flask import Flask
...@@ -8,7 +10,9 @@ def setup_app(name): ...@@ -8,7 +10,9 @@ def setup_app(name):
app = Flask(name) app = Flask(name)
# Load config # Load config
app.config.from_object('parlapi.config.CurrentConfig') config_obj = os.environ.get('PARLAPI_CONFIG',
'parlapi.config.DefaultConfig')
app.config.from_object(config_obj)
# Setup DB # Setup DB
from .models import db from .models import db
......
...@@ -20,6 +20,7 @@ setup( ...@@ -20,6 +20,7 @@ setup(
install_requires=[ install_requires=[
'beautifulsoup4>=4.4,<5', 'beautifulsoup4>=4.4,<5',
'click>=6.6,<7', 'click>=6.6,<7',
'dateparser>=0.4,<0.5',
'flask>=0.11,<0.12', 'flask>=0.11,<0.12',
'flask-marshmallow>=0.7,<0.8', 'flask-marshmallow>=0.7,<0.8',
'flask-sqlalchemy>=2.1,<3', 'flask-sqlalchemy>=2.1,<3',
......
# -*- coding: utf-8 -*-
from parlapi.parlapi import app
application = 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 sign in to comment