Commit dbf54e57 by Edward Zarecor Committed by Feanil Patel

Initial version

parent bd9193b9
...@@ -7,3 +7,4 @@ ...@@ -7,3 +7,4 @@
jinja2_extensions=jinja2.ext.do jinja2_extensions=jinja2.ext.do
host_key_checking = False host_key_checking = False
roles_path=../../ansible-roles/roles:../../ansible-private/roles:../../ansible-roles/ roles_path=../../ansible-roles/roles:../../ansible-private/roles:../../ansible-roles/
ansible_managed=This file is created and updated by ansible, edit at your peril
\ No newline at end of file
...@@ -7,3 +7,4 @@ ...@@ -7,3 +7,4 @@
jinja2_extensions=jinja2.ext.do jinja2_extensions=jinja2.ext.do
host_key_checking=False host_key_checking=False
roles_path=../../../ansible-roles/roles:../../../ansible-private/roles:../../../ansible-roles/ roles_path=../../../ansible-roles/roles:../../../ansible-private/roles:../../../ansible-roles/
ansible_managed=This file is created and updated by ansible, edit at your peril
- name: Deploy edX Ecommerce
hosts: all
sudo: True
gather_facts: True
vars:
ENABLE_DATADOG: False
ENABLE_SPLUNKFORWARDER: False
ENABLE_NEWRELIC: False
roles:
- role: nginx
nginx_sites:
- edx_ecommerce
- aws
- edx_ecommerce
- role: datadog
when: COMMON_ENABLE_DATADOG
- role: splunkforwarder
when: COMMON_ENABLE_SPLUNKFORWARDER
- role: newrelic
when: COMMON_ENABLE_NEWRELIC
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
##
# Defaults for role edx_ecommerce
#
EDX_ECOMMERCE_GIT_IDENTITY: !!null
# depends upon Newrelic being enabled via COMMON_ENABLE_NEWRELIC
# and a key being provided via NEWRELIC_LICENSE_KEY
EDX_ECOMMERCE_NEWRELIC_APPNAME: "{{ COMMON_ENVIRONMENT }}-{{ COMMON_DEPLOYMENT }}-{{ edx_ecommerce_service_name }}"
EDX_ECOMMERCE_PIP_EXTRA_ARGS: "-i {{ COMMON_PYPI_MIRROR_URL }}"
EDX_ECOMMERCE_NGINX_PORT: "18130"
EDX_ECOMMERCE_DATABASES:
# rw user
default:
ENGINE: 'django.db.backends.mysql'
NAME: 'edx_ecommerce'
USER: 'ecomm001'
PASSWORD: 'password'
HOST: 'localhost'
PORT: '3306'
# read-only user
reports:
ENGINE: 'django.db.backends.mysql'
NAME: 'edx_ecommerce'
USER: 'ecomm001'
PASSWORD: 'password'
HOST: 'localhost'
PORT: '3306'
EDX_ECOMMERCE_VERSION: "master"
# Default dummy user, override this!!
EDX_ECOMMERCE_USERS:
"dummy-api-user": "changeme"
EDX_ECOMMERCE_SECRET_KEY: 'Your secret key here'
EDX_ECOMMERCE_TIME_ZONE: 'UTC'
EDX_ECOMMERCE_LANGUAGE_CODE: 'en-us'
EDX_ECOMMERCE_EMAIL_HOST: 'localhost'
EDX_ECOMMERCE_EMAIL_HOST_USER: 'mail_user'
EDX_ECOMMERCE_EMAIL_HOST_PASSWORD: 'mail_password'
EDX_ECOMMERCE_EMAIL_PORT: 587
EDX_ECOMMERCE_AUTH_TOKEN: 'put-your-api-token-here'
EDX_ECOMMERCE_SERVICE_CONFIG:
EDX_ECOMMERCE_DATABASE: 'reports'
SECRET_KEY: '{{ EDX_ECOMMERCE_SECRET_KEY }}'
TIME_ZONE: '{{ EDX_ECOMMERCE_TIME_ZONE }}'
LANGUAGE_CODE: '{{EDX_ECOMMERCE_LANGUAGE_CODE }}'
# email config
EMAIL_HOST: '{{ EDX_ECOMMERCE_EMAIL_HOST }}'
EMAIL_HOST_PASSWORD: '{{ EDX_ECOMMERCE_EMAIL_HOST_PASSWORD }}'
EMAIL_HOST_USER: '{{ EDX_ECOMMERCE_EMAIL_HOST_USER }}'
EMAIL_PORT: $EDX_ECOMMERCE_EMAIL_PORT
API_AUTH_TOKEN: '{{ EDX_ECOMMERCE_AUTH_TOKEN }}'
STATICFILES_DIRS: ['static']
STATIC_ROOT: "{{ COMMON_DATA_DIR }}/{{ edx_ecommerce_service_name }}/staticfiles"
# db config
DATABASE_OPTIONS:
connect_timeout: 10
DATABASES: '{{ EDX_ECOMMERCE_DATABASES }}'
EDX_ECOMMERCE_REPOS:
- PROTOCOL: "{{ COMMON_GIT_PROTOCOL }}"
DOMAIN: "{{ COMMON_GIT_MIRROR }}"
PATH: "{{ COMMON_GIT_PATH }}"
REPO: edx-ecommerce.git
VERSION: "{{ EDX_ECOMMERCE_VERSION }}"
DESTINATION: "{{ edx_ecommerce_code_dir }}"
SSH_KEY: "{{ EDX_ECOMMERCE_GIT_IDENTITY }}"
- PROTOCOL: "{{ COMMON_GIT_PROTOCOL }}"
DOMAIN: "{{ COMMON_GIT_MIRROR }}"
PATH: "{{ COMMON_GIT_PATH }}"
REPO: django-oscar.git
VERSION: "{{ EDX_ECOMMERCE_VERSION }}"
DESTINATION: "{{ edx_ecommerce_home }}/depends/django-oscar"
SSH_KEY: "{{ EDX_ECOMMERCE_GIT_IDENTITY }}"
- PROTOCOL: "{{ COMMON_GIT_PROTOCOL }}"
DOMAIN: "{{ COMMON_GIT_MIRROR }}"
PATH: "{{ COMMON_GIT_PATH }}"
REPO: django-oscar-extensions.git
VERSION: "{{ EDX_ECOMMERCE_VERSION }}"
DESTINATION: "{{ edx_ecommerce_home }}/depends/django-oscar-extensions"
SSH_KEY: "{{ EDX_ECOMMERCE_GIT_IDENTITY }}"
EDX_ECOMMERCE_GUNICORN_WORKERS: "2"
EDX_ECOMMERCE_GUNICORN_EXTRA: ""
EDX_ECOMMERCE_GUNICORN_EXTRA_CONF: ""
#
# vars are namespace with the module name.
#
edx_ecommerce_environment:
DJANGO_SETTINGS_MODULE: "settings.production"
EDX_ECOMMERCE_SERVICE_CONFIG: "{{ COMMON_CFG_DIR }}/{{ edx_ecommerce_service_name }}.yml"
edx_ecommerce_service_name: "edx_ecommerce"
edx_ecommerce_user: "{{ edx_ecommerce_service_name }}"
edx_ecommerce_home: "{{ COMMON_APP_DIR }}/{{ edx_ecommerce_service_name }}"
edx_ecommerce_code_dir: "{{ edx_ecommerce_home }}/{{ edx_ecommerce_service_name }}"
edx_ecommerce_conf_dir: "{{ edx_ecommerce_home }}"
edx_ecommerce_gunicorn_host: "127.0.0.1"
edx_ecommerce_gunicorn_port: "8130"
edx_ecommerce_gunicorn_timeout: "300"
edx_ecommerce_django_settings: "production"
edx_ecommerce_log_dir: "{{ COMMON_LOG_DIR }}/{{ edx_ecommerce_service_name }}"
edx_ecommerce_requirements_base: "{{ edx_ecommerce_code_dir }}/requirements"
edx_ecommerce_requirements:
- base.txt
- production.txt
#- optional.txt
#
# OS packages
#
edx_ecommerce_debian_pkgs:
- 'libmysqlclient-dev'
- 'libjpeg-dev'
edx_ecommerce_redhat_pkgs: []
\ No newline at end of file
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Handlers for role edx_ecommerce
#
# Overview:
#
#
- name: notify me
debug: msg="stub handler"
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
##
# Role includes for role edx_ecommerce
#
dependencies:
- role: edx_service
edx_service_name: "{{ edx_ecommerce_service_name }}"
edx_service_config: "{{ EDX_ECOMMERCE_SERVICE_CONFIG }}"
edx_service_repos: "{{ EDX_ECOMMERCE_REPOS }}"
edx_service_user: "{{ edx_ecommerce_user }}"
edx_service_home: "{{ edx_ecommerce_home }}"
- supervisor
---
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://github.com/edx/configuration/wiki
# code style: https://github.com/edx/configuration/wiki/Ansible-Coding-Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
#
#
# Tasks for role edx_ecommerce
#
# Overview:
#
#
# Dependencies:
#
#
# Example play:
#
#
- name: "add gunicorn configuration file"
template: >
src=edx/app/edx_ecommerce/edx_ecommerce_gunicorn.py.j2
dest={{ edx_ecommerce_home }}/edx_ecommerce_gunicorn.py
sudo_user: "{{ edx_ecommerce_user }}"
- name: install application requirements
pip: >
requirements="{{ edx_ecommerce_requirements_base }}/{{ item }}"
virtualenv="{{ edx_ecommerce_home }}/venvs/{{ edx_ecommerce_service_name }}"
state=present
sudo_user: "{{ edx_ecommerce_user }}"
with_items: edx_ecommerce_requirements
- name: migrate
shell: >
chdir={{ edx_ecommerce_code_dir }}
DB_MIGRATION_USER={{ COMMON_MYSQL_MIGRATE_USER }}
DB_MIGRATION_PASS={{ COMMON_MYSQL_MIGRATE_PASS }}
{{ edx_ecommerce_home }}/venvs/{{ edx_ecommerce_service_name }}/bin/python ./manage.py migrate --noinput
sudo_user: "{{ edx_ecommerce_user }}"
environment: "{{ edx_ecommerce_environment }}"
when: migrate_db is defined and migrate_db|lower == "yes"
# - name: run collectstatic
# shell: >
# chdir={{ edx_ecommerce_code_dir }}
# {{ edx_ecommerce_home }}/venvs/{{ edx_ecommerce_service_name }}/bin/python manage.py collectstatic --noinput
# sudo_user: "{{ edx_ecommerce_user }}"
# environment: "{{ edx_ecommerce_environment }}"
- name: write out the supervisor wrapper
template: >
src=edx/app/edx_ecommerce/edx_ecommerce.sh.j2
dest={{ edx_ecommerce_home }}/{{ edx_ecommerce_service_name }}.sh
mode=0650 owner={{ supervisor_user }} group={{ common_web_user }}
- name: write supervisord config
template: >
src=edx/app/supervisor/conf.d.available/edx_ecommerce.conf.j2
dest="{{ supervisor_available_dir }}/{{ edx_ecommerce_service_name }}.conf"
owner={{ supervisor_user }} group={{ common_web_user }} mode=0644
- name: enable supervisor script
file: >
src={{ supervisor_available_dir }}/{{ edx_ecommerce_service_name }}.conf
dest={{ supervisor_cfg_dir }}/{{ edx_ecommerce_service_name }}.conf
state=link
force=yes
when: not disable_edx_services
- name: update supervisor configuration
shell: "{{ supervisor_ctl }} -c {{ supervisor_cfg }} update"
when: not disable_edx_services
- name: create symlinks from the-er venv bin dir
file: >
src="{{ edx_ecommerce_home }}/venvs/{{ edx_ecommerce_service_name }}/bin/{{ item }}"
dest="{{ COMMON_BIN_DIR }}/{{ item.split('.')[0] }}.edx_ecommerce"
state=link
with_items:
- python
- pip
- django-admin.py
- name: create symlinks from the repo dir
file: >
src="{{ edx_ecommerce_code_dir }}/{{ item }}"
dest="{{ COMMON_BIN_DIR }}/{{ item.split('.')[0] }}.edx_ecommerce"
state=link
with_items:
- manage.py
- name: restart the applicaton
supervisorctl_local: >
state=restarted
supervisorctl_path={{ supervisor_ctl }}
config={{ supervisor_cfg }}
name={{ edx_ecommerce_service_name }}
when: not disable_edx_services
sudo_user: "{{ supervisor_service_user }}"
#!/usr/bin/env bash
{% set edx_ecommerce_venv_bin = edx_ecommerce_home + "/venvs/" + edx_ecommerce_service_name + "/bin/" %}
{% if COMMON_ENABLE_NEWRELIC_APP %}
{% set executable = edx_ecommerce_venv_bin + '/newrelic-admin run-program ' + edx_ecommerce_venv_bin + '/gunicorn' %}
{% else %}
{% set executable = edx_ecommerce_venv_bin + '/gunicorn' %}
{% endif %}
{% if COMMON_ENABLE_NEWRELIC_APP %}
export NEW_RELIC_APP_NAME="{{ EDX_ECOMMERCE_NEWRELIC_APPNAME }}"
export NEW_RELIC_LICENSE_KEY="{{ NEWRELIC_LICENSE_KEY }}"
{% endif -%}
source {{ edx_ecommerce_home }}/edx_ecommerce_env
# TODO fix application
{{ executable }} -c {{ edx_ecommerce_home }}/edx_ecommerce_gunicorn.py {{ EDX_ECOMMERCE_GUNICORN_EXTRA }} wsgi:application
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
{{ ansible_managed }}
"""
timeout = {{ edx_ecommerce_gunicorn_timeout }}
bind = "{{ edx_ecommerce_gunicorn_host }}:{{ edx_ecommerce_gunicorn_port }}"
pythonpath = "{{ edx_ecommerce_code_dir }}"
workers = {{ EDX_ECOMMERCE_GUNICORN_WORKERS }}
{{ EDX_ECOMMERCE_GUNICORN_EXTRA_CONF }}
#
# {{ ansible_managed }}
#
[program:{{ edx_ecommerce_service_name }}]
command={{ edx_ecommerce_home }}/{{ edx_ecommerce_service_name }}.sh
user={{ common_web_user }}
directory={{ edx_ecommerce_code_dir }}
stdout_logfile={{ supervisor_log_dir }}/%(program_name)-stdout.log
stderr_logfile={{ supervisor_log_dir }}/%(program_name)-stderr.log
killasgroup=true
stopasgroup=true
...@@ -93,6 +93,8 @@ nginx_gitreload_gunicorn_hosts: ...@@ -93,6 +93,8 @@ nginx_gitreload_gunicorn_hosts:
- 127.0.0.1 - 127.0.0.1
nginx_edx_notes_api_gunicorn_hosts: nginx_edx_notes_api_gunicorn_hosts:
- 127.0.0.1 - 127.0.0.1
nginx_edx_ecommerce_gunicorn_hosts:
- 127.0.0.1
nginx_cfg: nginx_cfg:
# - link - turn on # - link - turn on
......
#
# {{ ansible_managed }}
#
upstream edx_ecommerce_app_server {
{% for host in nginx_edx_ecommerce_gunicorn_hosts %}
server {{ host }}:{{ edx_ecommerce_gunicorn_port }} fail_timeout=0;
{% endfor %}
}
server {
listen {{ EDX_ECOMMERCE_NGINX_PORT }} default_server;
location ~ ^/static/(?P<file>.*) {
root {{ COMMON_DATA_DIR }}/{{ edx_ecommerce_service_name }};
try_files /staticfiles/$file =404;
}
location / {
try_files $uri @proxy_to_app;
}
{% include "robots.j2" %}
location @proxy_to_app {
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Forwarded-Port $http_x_forwarded_port;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://edx_ecommerce_app_server;
}
}
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