-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from simon-dube/develop
Executions and CLI
- Loading branch information
Showing
60 changed files
with
1,933 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.pytest_cache/* | ||
*.db | ||
/carmin-server/.coverage | ||
/CONFIG.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
sudo: required | ||
|
||
language: python | ||
|
||
services: | ||
- docker | ||
|
||
python: | ||
- 3.4 | ||
- 3.5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
"""CARMIN-Server | ||
A lightweight server for the execution of remote pipelines. | ||
Usage: | ||
carmin-server [--help] [--version] COMMAND [OPTIONS...] | ||
Options: | ||
-h, --help Print help page and quit | ||
-v, --version Print version information and quit | ||
Commands: | ||
setup Install and configure the server | ||
run Launch the server | ||
""" | ||
|
||
from subprocess import call | ||
from pathlib import Path | ||
from docopt import docopt | ||
from cli_helper import project_root | ||
|
||
|
||
def get_version(): | ||
root_path = project_root() | ||
version_file = open(Path(root_path, 'VERSION')) | ||
return version_file.read().strip() | ||
|
||
|
||
if __name__ == '__main__': | ||
args = docopt(__doc__, options_first=True, version=get_version()) | ||
|
||
argv = [args['COMMAND']] + args['OPTIONS'] | ||
|
||
if args['COMMAND'] == 'setup': | ||
import carmin_server_setup | ||
try: | ||
exit(call(['python3', 'carmin_server_setup.py'] + argv)) | ||
except KeyboardInterrupt: | ||
exit() | ||
elif args['COMMAND'] == 'run': | ||
import carmin_server_run | ||
try: | ||
exit(call(['python3', 'carmin_server_run.py'] + argv)) | ||
except KeyboardInterrupt: | ||
pass | ||
elif args['COMMAND'] in ['help', None]: | ||
exit(call(['python3', 'carmin_server.py', '--help'])) | ||
else: | ||
exit("{} is not a carmin-server command. See 'carmin-server --help.'". | ||
format(args['COMMAND'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Usage: carmin-server run [options] | ||
Launches the server | ||
Options: | ||
-p <port>, --port <port> The server will listen on this port | ||
-c, --container Launch the server inside a Docker container | ||
""" | ||
|
||
import json | ||
from subprocess import call | ||
from pathlib import Path | ||
from docopt import docopt | ||
|
||
from cli_helper import project_root | ||
|
||
|
||
def config_dict(): | ||
root_dir = Path(__file__).resolve().parent.parent | ||
config_file = Path(root_dir, 'CONFIG.json') | ||
try: | ||
with open(config_file) as f: | ||
return json.load(f) | ||
except FileNotFoundError: | ||
return {} | ||
except TypeError: | ||
return {} | ||
|
||
|
||
CONFIG = config_dict() | ||
|
||
if __name__ == '__main__': | ||
args = docopt(__doc__) | ||
port = args.get('--port') or '8080' | ||
try: | ||
port = int(port) | ||
except ValueError: | ||
print("Invalid port number. Port must be an integer.") | ||
exit(1) | ||
if args.get('--container'): | ||
call(['docker', 'build', '-t=carmin-server', '..']) | ||
call([ | ||
'docker', 'run', '-p', '{}:8080'.format(port), '-e', | ||
'DATABASE_URI="sqlite:////carmin-db/app.db"', '-v', | ||
'{}:/carmin-assets/pipelines'.format( | ||
CONFIG.get('PIPELINE_DIRECTORY')), | ||
'-v', '{}:/carmin-assets/data'.format( | ||
CONFIG.get('DATA_DIRECTORY')), 'carmin-server' | ||
]) | ||
else: | ||
call(['python3', '-m', 'server', str(port)], cwd=project_root()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Usage: carmin-server setup [options] | ||
Options: | ||
-p <path>, --pipeline-directory <path> Specify path for pipeline directory | ||
-d <path>, --data-directory <path> Specify path for data directory | ||
-w <path>, --database <path> Specify path for database | ||
""" | ||
|
||
import json | ||
from pathlib import Path | ||
from docopt import docopt | ||
|
||
|
||
def is_interactive(invocation_list): | ||
return not (invocation_list.get('--database') | ||
and invocation_list.get('--pipeline-directory') | ||
and invocation_list.get('--data-directory')) | ||
|
||
|
||
def write_to_config_file(config): | ||
root_dir = Path(__file__).resolve().parent.parent | ||
config_file = Path(root_dir, 'CONFIG.json') | ||
with open(config_file, 'w') as f: | ||
json.dump(config, f) | ||
|
||
|
||
def print_install_banner(): | ||
width = 50 | ||
delimiter = '-' * width | ||
print('{0}\nCARMIN-Server Setup (Press CTRL-C to quit)\n{0}'.format( | ||
delimiter)) | ||
|
||
|
||
ask_pipeline = "Enter path to pipeline directory: " | ||
ask_data = "Enter path to data directory: " | ||
ask_database = "Enter path or URI to the database (to use the default sqlite database, leave blank): " | ||
|
||
if __name__ == '__main__': | ||
args = docopt(__doc__) | ||
try: | ||
if is_interactive(args): | ||
print_install_banner() | ||
step_count = 1 | ||
if not args.get('--pipeline-directory'): | ||
pipeline_path = input('{}. {}'.format(step_count, | ||
ask_pipeline)) | ||
step_count += 1 | ||
if not args.get('--data-directory'): | ||
data_path = input('{}. {}'.format(step_count, ask_data)) | ||
step_count += 1 | ||
if not args.get('--database'): | ||
database_path = input('{}. {}'.format(step_count, | ||
ask_database)) | ||
config_dict = { | ||
"PIPELINE_DIRECTORY": pipeline_path, | ||
"DATA_DIRECTORY": data_path, | ||
"DATABASE_URL": database_path | ||
} | ||
write_to_config_file(config_dict) | ||
exit("\nCARMIN-Server was successfully configured.") | ||
except KeyboardInterrupt: | ||
exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from pathlib import Path | ||
|
||
|
||
def project_root(): | ||
return Path(__file__).resolve().parent.parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
import sys | ||
from server.server_helper import create_app | ||
from server.api import declare_api | ||
|
||
app = create_app() | ||
|
||
from server.logging.setup import log_response, log_exception | ||
from server.resources.post_processors import * | ||
|
||
|
||
def main(): | ||
declare_api(app) | ||
start_up() | ||
app.run(host='0.0.0.0', port=int(8080)) | ||
if len(sys.argv) > 1: | ||
port = sys.argv[1] | ||
try: | ||
port = int(port) | ||
except ValueError: | ||
print("Invalid port number. Port must be an integer.") | ||
exit(1) | ||
else: | ||
port = 8080 | ||
app.run(host='0.0.0.0', port=port) | ||
|
||
|
||
from server.startup_validation import start_up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.