fix running via docker
This commit is contained in:
parent
b85b4ab80b
commit
15b314922c
|
@ -21,8 +21,7 @@ class Application(web.Application):
|
||||||
|
|
||||||
self['starttime'] = None
|
self['starttime'] = None
|
||||||
self['running'] = False
|
self['running'] = False
|
||||||
self['is_docker'] = bool(os.environ.get('DOCKER_RUNNING'))
|
self['config'] = RelayConfig(cfgpath)
|
||||||
self['config'] = RelayConfig(cfgpath, self['is_docker'])
|
|
||||||
|
|
||||||
if not self['config'].load():
|
if not self['config'].load():
|
||||||
self['config'].save()
|
self['config'].save()
|
||||||
|
@ -59,11 +58,6 @@ class Application(web.Application):
|
||||||
return self['database']
|
return self['database']
|
||||||
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_docker(self):
|
|
||||||
return self['is_docker']
|
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def semaphore(self):
|
def semaphore(self):
|
||||||
return self['semaphore']
|
return self['semaphore']
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from functools import cached_property
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
@ -25,22 +27,17 @@ class RelayConfig(DotDict):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, path, is_docker):
|
def __init__(self, path):
|
||||||
DotDict.__init__(self, {})
|
DotDict.__init__(self, {})
|
||||||
|
|
||||||
if is_docker:
|
if self.is_docker:
|
||||||
path = '/data/relay.yaml'
|
path = '/data/config.yaml'
|
||||||
|
|
||||||
self._isdocker = is_docker
|
|
||||||
self._path = Path(path).expanduser()
|
self._path = Path(path).expanduser()
|
||||||
|
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
|
||||||
def __setitem__(self, key, value):
|
def __setitem__(self, key, value):
|
||||||
if self._isdocker and key in ['db', 'listen', 'port']:
|
|
||||||
return
|
|
||||||
|
|
||||||
if key in ['blocked_instances', 'blocked_software', 'whitelist']:
|
if key in ['blocked_instances', 'blocked_software', 'whitelist']:
|
||||||
assert isinstance(value, (list, set, tuple))
|
assert isinstance(value, (list, set, tuple))
|
||||||
|
|
||||||
|
@ -80,6 +77,11 @@ class RelayConfig(DotDict):
|
||||||
return f'{self.actor}#main-key'
|
return f'{self.actor}#main-key'
|
||||||
|
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def is_docker(self):
|
||||||
|
return bool(os.environ.get('DOCKER_RUNNING'))
|
||||||
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
self.update({
|
self.update({
|
||||||
|
@ -98,6 +100,13 @@ class RelayConfig(DotDict):
|
||||||
'whitelist': []
|
'whitelist': []
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if self.is_docker:
|
||||||
|
self.update({
|
||||||
|
'db': Path('/data/relay.jsonld'),
|
||||||
|
'listen': '127.0.0.1'
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def ban_instance(self, instance):
|
def ban_instance(self, instance):
|
||||||
if instance.startswith('http'):
|
if instance.startswith('http'):
|
||||||
instance = urlparse(instance).hostname
|
instance = urlparse(instance).hostname
|
||||||
|
|
|
@ -51,7 +51,7 @@ def cli_setup():
|
||||||
|
|
||||||
app.config.save()
|
app.config.save()
|
||||||
|
|
||||||
if not app['is_docker'] and click.confirm('Relay all setup! Would you like to run it now?'):
|
if not app.config.is_docker and click.confirm('Relay all setup! Would you like to run it now?'):
|
||||||
cli_run.callback()
|
cli_run.callback()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue