diff --git a/data/nodes/ats.yaml b/data/nodes/ats.yaml new file mode 100644 index 0000000..f0e834b --- /dev/null +++ b/data/nodes/ats.yaml @@ -0,0 +1,3 @@ +--- + classes: + - role::ats diff --git a/site-modules/profile/files/ats/requirements.txt b/site-modules/profile/files/ats/requirements.txt new file mode 100644 index 0000000..c422531 --- /dev/null +++ b/site-modules/profile/files/ats/requirements.txt @@ -0,0 +1,21 @@ +certifi==2018.1.18 +chardet==3.0.4 +click==6.7 +dateparser==0.7.0 +Flask==0.12.2 +Flask-SQLAlchemy==2.3.2 +idna==2.6 +itsdangerous==0.24 +Jinja2==2.10 +MarkupSafe==1.0 +python-dateutil==2.7.1 +pytz==2018.3 +regex==2018.2.21 +requests==2.18.4 +six==1.11.0 +SQLAlchemy==1.2.5 +tzlocal==1.5.1 +urllib3==1.22 +Werkzeug==0.14.1 +flask-cors==3.0.3 +gunicorn==19.4.5 diff --git a/site-modules/profile/manifests/ats.pp b/site-modules/profile/manifests/ats.pp new file mode 100644 index 0000000..e5b67a0 --- /dev/null +++ b/site-modules/profile/manifests/ats.pp @@ -0,0 +1,99 @@ +class profile::ats { + include profile::ssl + include profile::python3 + + $app_root = '/usr/local/alpheios-translation-service' + $repos = 'https://github.com/alpheios-project/alpheios-translation-service' + + vcsrepo { $app_root: + ensure => latest, + revision => 'master', + provider => git, + source => $repos, + notify => Python::Virtualenv[$app_root], + } + + file { "/etc/gunicorn.d": + ensure => directory, + } + + file { "${app_root}/requirements.txt": + ensure => file, + source => 'puppet:///modules/profile/ats/requirements.txt', + require => Vcsrepo[$app_root], + notify => Python::Virtualenv[$app_root], + } + + + file { "${app_root}/app.py": + ensure => file, + content => epp('profile/ats/app.py.epp', { + }), + require => Vcsrepo[$app_root], + notify => Python::Virtualenv[$app_root], + } + + python::virtualenv { $app_root: + ensure => present, + version => '3', + requirements => "${app_root}/requirements.txt", + venv_dir => "${app_root}/venv", + cwd => $app_root, + notify => Exec['restart-ats-gunicorn'], + require => File['/etc/gunicorn.d'], + } + + python::gunicorn { 'ats-vhost': + ensure => present, + virtualenv => "${app_root}/venv", + dir => $app_root, + timeout => 120, + bind => 'localhost:5000', + appmodule => 'app:app', + owner => 'www-data', + group => 'www-data', + } + + exec { 'restart-ats-gunicorn': + command => '/usr/sbin/service gunicorn restart', + refreshonly => true, + require => Python::Gunicorn['ats-vhost'], + } + + $proxy_pass = { + 'path' => '/', + 'url' => 'http://localhost:5000/', + } + + $headers = [ + "set Access-Control-Allow-Origin '*'", + "set Access-Control-Allow-Methods 'GET, POST, OPTIONS'" + ] + + apache::vhost { 'ats': + servername => 'ats.alpheios.net', + port => '80', + docroot => '/var/www/vhost', + proxy_pass => [ $proxy_pass ], + headers => $headers, + } + + apache::vhost { 'ats-ssl': + servername => 'ats.alpheios.net', + port => '443', + docroot => '/var/www/vhost', + proxy_pass => [ $proxy_pass ], + headers => $headers, + ssl => true, + ssl_cert => '/etc/ssl/certs/STAR_alpheios.net.crt', + ssl_key => '/etc/ssl/private/Alpheios.key', + ssl_chain => '/etc/ssl/certs/ca-bundle-client.crt', + } + + firewall { '100 ATS Service Access': + proto => 'tcp', + dport => ['80','443'], + action => 'accept', + } + +} diff --git a/site-modules/profile/templates/ats/app.py.epp b/site-modules/profile/templates/ats/app.py.epp new file mode 100644 index 0000000..1fb0c64 --- /dev/null +++ b/site-modules/profile/templates/ats/app.py.epp @@ -0,0 +1,6 @@ +#!/usr/bin/env python +from flask import Flask +from atservices import create_app + +app,db = create_app() + diff --git a/site-modules/role/manifests/ats.pp b/site-modules/role/manifests/ats.pp new file mode 100644 index 0000000..e23fecf --- /dev/null +++ b/site-modules/role/manifests/ats.pp @@ -0,0 +1,4 @@ +class role::ats { + include profile::common + include profile::ats +}