MT#12487 add deploy environment and configs for uwsgi

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#emperor-mode

Change-Id: I9c00f30c93fe2ad3fe8d37c98bef3616e0ae7fd6
changes/70/1770/4
Victor Seva 10 years ago
parent 710439fd11
commit e7bdd7505f

@ -1,5 +1,7 @@
# do nothing by default
all:
# virtual environments #############
.ONESHELL:
SHELL = /bin/bash
venv_test: requirements/test.txt
@ -14,20 +16,43 @@ venv_dev: requirements/dev.txt
source ./venv_dev/bin/activate && \
pip install -r ./requirements/dev.txt > install.log
.ONESHELL:
SHELL = /bin/bash
venv_prod: requirements/prod.txt
virtualenv --python=python2.7 venv_prod
source ./venv_prod/bin/activate && \
pip install -r ./requirements/prod.txt > install.log
###################################
test: venv_test
source ./venv_test/bin/activate && \
DJANGO_SETTINGS_MODULE="repoapi.settings.dev" ./manage.py jenkins
deploy: venv_prod
mkdir -p ./venv_prod/etc/uwsgi/vassals/
[ -L ./venv_prod/etc/uwsgi/vassals/repoapi_uwsgi.ini ] || \
ln -s $(shell pwd)/repoapi/repoapi_uwsgi.ini \
./venv_prod/etc/uwsgi/vassals/
###################################
run_dev: venv_dev
source ./venv_dev/bin/activate && \
DJANGO_SETTINGS_MODULE="repoapi.settings.dev" ./manage.py runserver_plus
run: deploy
source ./venv_prod/bin/activate && \
DJANGO_SETTINGS_MODULE="repoapi.settings.prod" \
uwsgi --emperor ./venv_prod/etc/uwsgi/vassals/ \
--uid www-data --gid www-data
###################################
# get rid of test files
clean:
rm -rf reports install.log
# also get rid of pip environment
# also get rid of virtual environments
dist-clean: clean
rm -rf venv*

@ -0,0 +1,17 @@
---
- hosts: all
connection: local
sudo: True
sudo_user: root
tasks:
- name: install Debian package requirements
apt: name=libyaml-dev state=present
apt: name=python2.7-dev state=present
apt: name=python-virtualenv state=present
- hosts: all
connection: local
tasks:
- name: deploy
shell: |
make deploy

@ -0,0 +1,21 @@
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /srv/repoapi
# Django's wsgi file
module = repoapi.wsgi
# the virtualenv (full path)
home = /srv/repoapi/venv_prod
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /srv/repoapi/repoapi.sock
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true

@ -0,0 +1,142 @@
# Copyright (C) 2015 The Sipwise Team - http://sipwise.com
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
# read it from external file
SECRET_KEY = os.path.join(BASE_DIR, '.secret_key').read().strip()
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = []
# Application definition
# django-jenkins
PROJECT_APPS = [
'repoapi',
]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework_swagger',
'django_extensions',
]
INSTALLED_APPS.extend(PROJECT_APPS)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
ROOT_URLCONF = 'repoapi.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'repoapi.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django_assets.finders.AssetsFinder',
)
STATIC_ROOT= os.path.join(BASE_DIR,'static_media/')
TEMPLATE_DIRS = (
'repoapi/templates',
)
REST_FRAMEWORK = {
'PAGE_SIZE': 10,
'DEFAULT_FILTER_BACKENDS': (
'rest_framework.filters.DjangoFilterBackend',
)
}
SWAGGER_SETTINGS = {
'api_version': '0.1',
'info': {
'contact': 'dev@sipwise.com',
'description': 'repoapi, one ring to rule them all',
'license': 'GPL 3.0',
'title': 'RepoApi',
},
}

@ -0,0 +1,2 @@
-r common.txt
uwsgi
Loading…
Cancel
Save