Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile all the things! #10

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM pypy:2-2.5.0
MAINTAINER Simon de Haan <[email protected]>
COPY . /var/springboard/
WORKDIR /var/springboard/
RUN pip install -e .
WORKDIR /var/
RUN springboard startapp myapp
VOLUME /var/myapp
EXPOSE 6543
CMD pserve development.ini --reload
19 changes: 13 additions & 6 deletions springboard/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ def test_create_index(self):
verbose=True,
clobber=False,
repo_dir=self.workspace.working_dir,
repo_name=self.mk_workspace_name(self.workspace))
repo_name=self.mk_workspace_name(self.workspace),
es_hosts=['http://localhost:9200'])
output = tool.stdout.getvalue()
self.assertTrue(output.endswith('Index already exists, skipping.\n'))

Expand All @@ -106,7 +107,8 @@ def test_create_index(self):
verbose=True,
clobber=True,
repo_dir=self.workspace.working_dir,
repo_name=self.mk_workspace_name(self.workspace))
repo_name=self.mk_workspace_name(self.workspace),
es_hosts=['http://localhost:9200'])
output = tool.stdout.getvalue()
self.assertTrue(
output.endswith('Clobbering existing index.\nIndex created.\n'))
Expand Down Expand Up @@ -138,7 +140,8 @@ def test_create_mapping(self):
verbose=True,
clobber=False,
repo_dir=self.workspace.working_dir,
repo_name=self.mk_workspace_name(self.workspace))
repo_name=self.mk_workspace_name(self.workspace),
es_hosts=['http://localhost:9200'])
self.assertEqual(
tool.stdout.getvalue(),
'Creating mapping for elasticgit.tests.base.TestPerson.\n'
Expand Down Expand Up @@ -171,7 +174,8 @@ def test_sync_data(self):
verbose=True,
clobber=False,
repo_dir=self.workspace.working_dir,
repo_name=self.mk_workspace_name(self.workspace))
repo_name=self.mk_workspace_name(self.workspace),
es_hosts=['http://localhost:9200'])
self.assertEqual(
tool.stdout.getvalue(),
'Syncing data for elasticgit.tests.base.TestPerson.\n'
Expand Down Expand Up @@ -202,7 +206,8 @@ def test_bootstrap(self):
tool.run(config=('springboard.yaml', config),
verbose=True,
clobber=False,
repo_dir=self.working_dir)
repo_dir=self.working_dir,
es_hosts=['http://localhost:9200'])

lines = tool.stdout.getvalue().split('\n')
self.assertTrue(lines[0].startswith('Cloning'))
Expand Down Expand Up @@ -250,7 +255,9 @@ def test_import(self):
ini_config=ini_config,
ini_section='app:main',
update_config=True,
repo_name=None)
repo_name=None,
es_hosts=['http://localhost:9200']
)

cp = ConfigParser()
cp.read(ini_config)
Expand Down
2 changes: 1 addition & 1 deletion springboard/tools/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SpringboardToolCommand(ToolCommand):
CommandArgument(
'-c', '--config',
dest='config',
help='The configuration file to load',
help='The configuration file to load.',
default='springboard.yaml',
type=YAMLFile(),
),
Expand Down
22 changes: 17 additions & 5 deletions springboard/tools/commands/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from springboard.tools.commands.index import CreateIndexTool
from springboard.tools.commands.mapping import CreateMappingTool
from springboard.tools.commands.sync import SyncDataTool
from springboard.tools.commands.base import SpringboardToolCommand
from springboard.tools.commands.base import (
SpringboardToolCommand, CommandArgument)


class BootstrapTool(CloneRepoTool,
Expand All @@ -14,9 +15,17 @@ class BootstrapTool(CloneRepoTool,

command_name = 'bootstrap'
command_help_text = 'Tools for bootstrapping a new content repository.'
command_arguments = SpringboardToolCommand.command_arguments
command_arguments = SpringboardToolCommand.command_arguments + (
CommandArgument(
'-eh', '--es-host',
dest='es_hosts',
help='The Elasticsearch host.',
default=['http://localhost:9200/'],
nargs='+'
),
)

def run(self, config, verbose, clobber, repo_dir):
def run(self, config, verbose, clobber, repo_dir, es_hosts):
config_file, config_data = config
repos = [self.clone_repo(repo_name=repo_name,
repo_url=repo_url,
Expand All @@ -28,10 +37,13 @@ def run(self, config, verbose, clobber, repo_dir):
for workdir, _ in repos:
self.bootstrap(workdir,
models=config_data.get('models', {}).items(),
clobber=clobber, verbose=verbose)
clobber=clobber, es={'urls': es_hosts},
verbose=verbose)

def bootstrap(self, workdir, models=(), clobber=False, verbose=False):
def bootstrap(self, workdir, models=(), clobber=False,
es={}, verbose=False):
index_created = self.create_index(workdir,
es=es,
clobber=clobber,
verbose=verbose)
for model_name, mapping in models:
Expand Down
10 changes: 9 additions & 1 deletion springboard/tools/commands/import_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ class ImportContentTool(BootstrapTool):
'-n', '--name',
dest='repo_name',
help='Give the repository a custom name on disk.'),
CommandArgument(
'-eh', '--es-host',
dest='es_hosts',
help='The Elasticsearch host.',
default=['http://localhost:9200/'],
nargs='+'),
)

def run(self, config, verbose, clobber, repo_dir, repo_url,
ini_config, ini_section, update_config, repo_name):
ini_config, ini_section, update_config, repo_name,
es_hosts):
config_file, config_data = config
repo_name = repo_name or parse_repo_name(repo_url)
workdir, _ = self.clone_repo(repo_name=repo_name,
Expand All @@ -51,6 +58,7 @@ def run(self, config, verbose, clobber, repo_dir, repo_url,
self.bootstrap(
workdir,
config_data.get('models', {}).items(),
es={'urls': es_hosts},
clobber=clobber,
verbose=verbose)

Expand Down
17 changes: 13 additions & 4 deletions springboard/tools/commands/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,29 @@ class CreateIndexTool(SpringboardToolCommand):
command_help_text = (
'Create a search index for models stored in elastic-git')
command_arguments = SpringboardToolCommand.command_arguments + (
CommandArgument(
'-eh', '--es-host',
dest='es_hosts',
help='The Elasticsearch host.',
default=['http://localhost:9200/'],
nargs='+'
),
CommandArgument(
'repo_name',
metavar='repo_name',
help='The repository name'),
)

def run(self, config, verbose, clobber, repo_dir, repo_name):
def run(self, config, verbose, clobber, repo_dir, es_hosts, repo_name):
return self.create_index(os.path.join(repo_dir, repo_name),
verbose=verbose, clobber=clobber)
verbose=verbose, clobber=clobber,
es={'urls': es_hosts})

def create_index(self, workdir, verbose=False, clobber=False):
def create_index(self, workdir, verbose=False, clobber=False,
es={}):
self.verbose = verbose
workspace = EG.workspace(
workdir, index_prefix=slugify(os.path.basename(workdir)))
workdir, es=es, index_prefix=slugify(os.path.basename(workdir)))
branch = workspace.repo.active_branch
self.emit('Creating index for %s.' % (branch.name,))
if workspace.im.index_exists(branch.name) and not clobber:
Expand Down
16 changes: 12 additions & 4 deletions springboard/tools/commands/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,32 @@ class CreateMappingTool(SpringboardToolCommand):
command_name = 'create-mapping'
command_help_text = 'Upload a mapping for models stored in elastic-git'
command_arguments = SpringboardToolCommand.command_arguments + (
CommandArgument(
'-eh', '--es-host',
dest='es_hosts',
help='The Elasticsearch host.',
default=['http://localhost:9200/'],
nargs='+'
),
CommandArgument(
'repo_name',
metavar='repo_name',
help='The repository name'),
)

def run(self, config, verbose, clobber, repo_dir, repo_name):
def run(self, config, verbose, clobber, repo_dir, es_hosts, repo_name):
config_file, config_data = config
for model_name, mapping in config_data.get('models', {}).items():
model_class = load_class(model_name)
self.create_mapping(os.path.join(repo_dir, repo_name),
model_class, mapping, verbose=verbose)
model_class, mapping,
es={'urls': es_hosts}, verbose=verbose)

def create_mapping(self, repo_dir, model_class, mapping,
verbose=False):
es={}, verbose=False):
self.verbose = verbose
workspace = EG.workspace(
repo_dir, index_prefix=slugify(os.path.basename(repo_dir)))
repo_dir, es=es, index_prefix=slugify(os.path.basename(repo_dir)))
self.emit('Creating mapping for %s.' % (fqcn(model_class),))
workspace.setup_custom_mapping(model_class, mapping)
self.emit('Mapping created.')
16 changes: 12 additions & 4 deletions springboard/tools/commands/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,32 @@ class SyncDataTool(SpringboardToolCommand):
command_name = 'sync-data'
command_help_text = 'Sync data from a repo with elastic-git'
command_arguments = SpringboardToolCommand.command_arguments + (
CommandArgument(
'-eh', '--es-host',
dest='es_hosts',
help='The Elasticsearch host.',
default=['http://localhost:9200/'],
nargs='+'
),
CommandArgument(
'repo_name',
metavar='repo_name',
help='The repository name'),
)

def run(self, config, verbose, clobber, repo_dir, repo_name):
def run(self, config, verbose, clobber, repo_dir, es_hosts, repo_name):
config_file, config_data = config
for model_name, mapping in config_data.get('models', {}).items():
model_class = load_class(model_name)
self.sync_data(os.path.join(repo_dir, repo_name), model_class,
verbose=verbose,
es={'urls': es_hosts}, verbose=verbose,
clobber=clobber)

def sync_data(self, workdir, model_class, verbose=False, clobber=False):
def sync_data(self, workdir, model_class, es={}, verbose=False,
clobber=False):
self.verbose = verbose
workdir = EG.workspace(
workdir, index_prefix=slugify(os.path.basename(workdir)))
workdir, es=es, index_prefix=slugify(os.path.basename(workdir)))
self.emit('Syncing data for %s.' % (fqcn(model_class),))
workdir.sync(model_class)
self.emit('Data synced.')
5 changes: 4 additions & 1 deletion springboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ def __init__(self, request):
self.request = request
self.language = request.locale_name
self.settings = request.registry.settings
self.es_host = self.settings.get('es.host', 'http://localhost:9200/')

repo_name = parse_repo_name(self.settings['unicore.content_repo_url'])
repo_path = os.path.join(
self.settings.get('unicore.repos_dir', 'repos'), repo_name)
index_prefix = slugify(repo_name)
self.workspace = EG.workspace(
repo_path, index_prefix=index_prefix)
repo_path,
es={'urls': [self.es_host]},
index_prefix=index_prefix)
self.all_categories = self.workspace.S(Category)
self.all_pages = self.workspace.S(Page)

Expand Down