Anchor can now be installed and invoked as simply "anchor"

This installs stuff in the right places to run anchor from the
included startup scripts. The config is installed into /etc/anchor

This will work from within a venv or without.

The anchor config.py file has been moved into the project package
so that it will install with the other stuff. Eventually we should
strip it out as much as possible and move the details into the JSON
file.

Change-Id: Iffaa7669ce8118fbd41011f9e965704c2ad51b44
This commit is contained in:
Tim Kelsey 2016-03-01 11:17:37 +00:00 committed by Eric Brown
parent 36520b9f59
commit ef2160e82e
7 changed files with 53 additions and 13 deletions

View File

@ -198,7 +198,8 @@ def load_config():
user_config_path = os.path.join(
os.environ['HOME'], '.config', 'anchor', 'config.json')
sys_config_path = os.path.join(os.sep, 'etc', 'anchor', 'config.json')
prefix = os.environ.get('VIRTUAL_ENV', os.sep)
sys_config_path = os.path.join(prefix, 'etc', 'anchor', 'config.json')
if 'registration_authority' not in jsonloader.conf.config:
config_path = ""

View File

@ -1,6 +1,6 @@
server = {
'port': '5016',
'host': '0.0.0.0'
'host': '0.0.0.0' # nosec
}
# Pecan Application Configurations

43
bin/anchor Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
if [ "$1" = "-h" -o "$1" = "--help" ] ; then
echo "Usage: [PY=optional/path/python] $0"
echo
echo "Run Anchor with default uwsgi settings. It will spawn 4 workers"
echo "and use either the default reachable 'python' or one defined in the"
echo "\$PY variable."
echo
exit 0
fi
if ! which uwsgi > /dev/null ; then
echo "You need to install uwsgi to run anchor using this script."
exit 1
fi
PY=${PY:-python}
if ! [ -x "$PY" ] ; then
if ! [ -x "$(which "$PY")" ] ; then
echo "Python interpreter not found (use PY variable to specify)."
exit 1
fi
fi
STR="import pkg_resources; print(pkg_resources.get_distribution('anchor').location)"
PKG_PATH=$("$PY" -c "$STR")
if ! [ -d "$PKG_PATH" ] ; then
echo "Cannot find installed anchor package."
exit 1
fi
if [ -z "$VIRTUAL_ENV" ]; then
OPTS="-p 4"
else
OPTS="--venv ""${VIRTUAL_ENV}"" -p 4"
fi
uwsgi --http-socket :5016 \
--pecan "${PKG_PATH}/anchor/config.py" \
${OPTS}

View File

@ -1,6 +0,0 @@
#!/bin/sh
VENV=$1
[ -n "$VENV" ] || ( echo "provide virtual env path as parameter" && exit 1 )
"$VENV/bin/uwsgi" --http-socket :5000 --venv "$VENV" --pecan config.py -p 4

View File

@ -57,9 +57,8 @@ anchor.fixups =
data_files =
etc/anchor =
config.json
config.py
packages =
anchor
scripts =
bin/anchor_production
bin/anchor
bin/anchor_debug

View File

@ -16,6 +16,7 @@
import json
import os
import stat
import unittest
@ -247,7 +248,9 @@ class TestApp(tests.DefaultConfigMixin, unittest.TestCase):
@mock.patch('anchor.jsonloader.conf.load_file_data')
def test_config_paths_system(self, conf):
ret = lambda x: True if x == '/etc/anchor/config.json' else False
path = os.path.join(os.environ.get('VIRTUAL_ENV', os.sep),
'etc/anchor/config.json')
ret = lambda x: x == path
with mock.patch('os.path.isfile', ret):
app.load_config()
conf.assert_called_with('/etc/anchor/config.json')
conf.assert_called_with(path)

View File

@ -26,9 +26,9 @@ import pecan
from pecan import testing as pecan_testing
import stevedore
from anchor import config
from anchor import jsonloader
from anchor.X509 import certificate as X509_cert
import config
import tests