Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Move variables around
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Apr 28, 2016
1 parent cb13062 commit 6f51c47
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 16 deletions.
42 changes: 34 additions & 8 deletions instance/models/openedx_appserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,37 @@ class OpenEdXAppConfiguration(models.Model):
class Meta:
abstract = True

email = models.EmailField(default='contact@example.com') # TODO: document me!
email = models.EmailField(default='contact@example.com', help_text=(
'The default contact email for this instance; also used as the from address for emails '
'sent by the server.'
))
protocol = models.CharField(max_length=5, default='http', choices=PROTOCOL_CHOICES)

# Ansible-specific settings:
configuration_source_repo_url = models.URLField(max_length=256, blank=False)
configuration_version = models.CharField(max_length=50, blank=False)
configuration_extra_settings = models.TextField(blank=True)

# Settings that affect ansible variables:
forum_version = models.CharField(max_length=50, default='master')
notifier_version = models.CharField(max_length=50, default='master')
xqueue_version = models.CharField(max_length=50, default='master')
certs_version = models.CharField(max_length=50, default='master')
edx_platform_repository_url = models.CharField(max_length=256, blank=False, help_text=(
'URL to the edx-platform repository to use. Leave blank for default.'
))
edx_platform_commit = models.CharField(max_length=256, blank=False, help_text=(
'edx-platform commit hash or branch or tag to use. Leave blank to use the default, '
'which is equal to the value of "openedx_release".'
))

openedx_release = models.CharField(max_length=128, blank=False, help_text=("""
Set this to a release tag like "named-release/dogwood" to build a specific release of
Open edX. The default is "{default}". This setting becomes the default value for
edx_platform_version, forum_version, notifier_version, xqueue_version, and
certs_version so it should be a git branch that exists in all of
those repositories.
Note: to build a specific branch of edx-platform, you should just override
edx_platform_commit rather than changing this setting.
Note 2: This value does not affect the default value of configuration_version.
""").format(default=settings.DEFAULT_OPENEDX_RELEASE))

s3_access_key = models.CharField(max_length=50, blank=True)
s3_secret_access_key = models.CharField(max_length=50, blank=True)
Expand All @@ -71,10 +89,16 @@ def set_field_defaults(self):
"""
Set default values.
"""
if not self.openedx_release:
self.openedx_release = settings.DEFAULT_OPENEDX_RELEASE
if not self.configuration_source_repo_url:
self.configuration_source_repo_url = settings.DEFAULT_CONFIGURATION_REPO_URL
if not self.configuration_version:
self.configuration_version = settings.DEFAULT_CONFIGURATION_VERSION
if not self.edx_platform_repository_url:
self.edx_platform_repository_url = settings.DEFAULT_EDX_PLATFORM_REPO_URL
if not self.edx_platform_commit:
self.edx_platform_commit = self.openedx_release
super().set_field_defaults()


Expand All @@ -97,6 +121,7 @@ class OpenEdXAppServer(AppServer, OpenEdXAppConfiguration):
configuration_settings = models.TextField(blank=False)

CONFIGURATION_PLAYBOOK = 'edx_sandbox'
CONFIGURATION_VARS_TEMPLATE = 'instance/ansible/vars.yml'
# Additional model fields that contain yaml vars to add the the configuration vars:
CONFIGURATION_ANSIBLE_EXTRA_FIELDS = [
'ansible_s3_settings',
Expand Down Expand Up @@ -136,9 +161,10 @@ def create_configuration_settings(self):
This is a one-time thing, because configuration_settings, like all AppServer fields, is
immutable once this AppServer is saved.
"""
template = loader.get_template('instance/ansible/vars.yml')
template = loader.get_template(self.CONFIGURATION_VARS_TEMPLATE)
vars_str = template.render({
'instance': self,
'instance': self.instance,
'appserver': self,
# This property is needed twice in the template. To avoid evaluating it twice (and
# querying the Github API twice), we pass it as a context variable.
'github_admin_username_list': self.github_admin_username_list,
Expand Down
14 changes: 7 additions & 7 deletions instance/templates/instance/ansible/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ SECURITY_UPDATE_ALL_PACKAGES: false
SECURITY_UPGRADE_ON_ANSIBLE: true

# Repositories URLs
edx_ansible_source_repo: '{{ instance.ansible_source_repo_url }}'
edx_platform_repo: '{{ instance.repository_url }}'
edx_ansible_source_repo: '{{ instance.configuration_source_repo_url }}'
edx_platform_repo: '{{ instance.edx_platform_repository_url }}'

# Pin down dependencies to specific (known to be compatible) commits.
edx_platform_version: '{{ instance.commit_id }}'
edx_platform_version: '{{ instance.edx_platform_commit }}'
configuration_version: '{{ instance.configuration_version }}'
forum_version: '{{ instance.forum_version }}'
notifier_version: '{{ instance.notifier_version }}'
xqueue_version: '{{ instance.xqueue_version }}'
certs_version: '{{ instance.certs_version }}'
forum_version: '{{ instance.openedx_release }}'
notifier_version: '{{ instance.openedx_release }}'
xqueue_version: '{{ instance.openedx_release }}'
certs_version: '{{ instance.openedx_release }}'

# Features
EDXAPP_FEATURES:
Expand Down
9 changes: 8 additions & 1 deletion opencraft/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,14 @@
DEFAULT_CONFIGURATION_REPO_URL = env(
'DEFAULT_CONFIGURATION_REPO_URL', default='https://github.com/edx/configuration.git'
)
DEFAULT_CONFIGURATION_VERSION = env('DEFAULT_CONFIGURATION_VERSION', default='master')

DEFAULT_EDX_PLATFORM_REPO_URL = env(
'DEFAULT_EDX_PLATFORM_REPO_URL', default='https://github.com/edx/edx-platform.git'
)

DEFAULT_OPENEDX_RELEASE = env('DEFAULT_OPENEDX_RELEASE', default='master')

DEFAULT_CONFIGURATION_VERSION = env('DEFAULT_CONFIGURATION_VERSION', default=DEFAULT_OPENEDX_RELEASE)

# Ansible #####################################################################

Expand Down

0 comments on commit 6f51c47

Please sign in to comment.