mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-09 18:08:00 +00:00
Fix running via docker
This commit is contained in:
parent
65b6c0a5ad
commit
437075e512
|
@ -5,7 +5,7 @@ ENV DOCKER_RUNNING=true
|
||||||
|
|
||||||
# setup various container properties
|
# setup various container properties
|
||||||
VOLUME ["/data"]
|
VOLUME ["/data"]
|
||||||
CMD ["python3", "-m", "relay"]
|
CMD ["python3", "-m", "relay", "run"]
|
||||||
EXPOSE 8080/tcp
|
EXPOSE 8080/tcp
|
||||||
WORKDIR /opt/activityrelay
|
WORKDIR /opt/activityrelay
|
||||||
|
|
||||||
|
|
23
docker.sh
23
docker.sh
|
@ -2,9 +2,21 @@
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
install)
|
install)
|
||||||
|
if [[ -z ${2#$} ]]; then
|
||||||
|
host=127.0.0.1
|
||||||
|
else
|
||||||
|
host=$2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z ${3#$} ]]; then
|
||||||
|
port=8080
|
||||||
|
else
|
||||||
|
port=$3
|
||||||
|
fi
|
||||||
|
|
||||||
docker build -f Dockerfile -t activityrelay . && \
|
docker build -f Dockerfile -t activityrelay . && \
|
||||||
docker volume create activityrelay-data && \
|
docker volume create activityrelay-data && \
|
||||||
docker run -it -p 8080:8080 -v activityrelay-data:/data --name activityrelay activityrelay
|
docker run -it -p target=8080,published=${host}:${port} -v activityrelay-data:/data --name activityrelay activityrelay
|
||||||
;;
|
;;
|
||||||
|
|
||||||
uninstall)
|
uninstall)
|
||||||
|
@ -22,6 +34,10 @@ case $1 in
|
||||||
docker stop activityrelay
|
docker stop activityrelay
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
restart)
|
||||||
|
docker restart activityrelay
|
||||||
|
;;
|
||||||
|
|
||||||
manage)
|
manage)
|
||||||
shift
|
shift
|
||||||
docker exec -it activityrelay python3 -m relay "$@"
|
docker exec -it activityrelay python3 -m relay "$@"
|
||||||
|
@ -61,10 +77,7 @@ case $1 in
|
||||||
printf "$COLS" "- edit" "Edit the relay's config in \$EDITOR"
|
printf "$COLS" "- edit" "Edit the relay's config in \$EDITOR"
|
||||||
printf "$COLS" "- shell" "Drop into a bash shell on the running container"
|
printf "$COLS" "- shell" "Drop into a bash shell on the running container"
|
||||||
printf "$COLS" "- rescue" "Drop into a bash shell on a temp container with the data volume mounted"
|
printf "$COLS" "- rescue" "Drop into a bash shell on a temp container with the data volume mounted"
|
||||||
printf "$COLS" "- install" "Build the image, create a new container and volume, and run relay setup"
|
printf "$COLS" "- install [address] [port]" "Build the image, create a new container and volume, and run relay setup"
|
||||||
printf "$COLS" "- uninstall" "Delete the relay image, container, and volume"
|
printf "$COLS" "- uninstall" "Delete the relay image, container, and volume"
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Note: This script may not work. It is recommended to manually install and manage the container if you know what you're doing."
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -55,7 +55,7 @@ class Application(web.Application):
|
||||||
DEFAULT: Application | None = None
|
DEFAULT: Application | None = None
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, cfgpath: str | None, dev: bool = False):
|
def __init__(self, cfgpath: Path | None, dev: bool = False):
|
||||||
web.Application.__init__(self,
|
web.Application.__init__(self,
|
||||||
middlewares = [
|
middlewares = [
|
||||||
handle_api_path,
|
handle_api_path,
|
||||||
|
|
|
@ -33,7 +33,7 @@ else:
|
||||||
DOCKER_VALUES = {
|
DOCKER_VALUES = {
|
||||||
'listen': '0.0.0.0',
|
'listen': '0.0.0.0',
|
||||||
'port': 8080,
|
'port': 8080,
|
||||||
'sq_path': '/data/relay.jsonld'
|
'sq_path': '/data/relay.sqlite3'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ class Config:
|
||||||
rd_prefix: str = 'activityrelay'
|
rd_prefix: str = 'activityrelay'
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, path: str | None = None, load: bool = False):
|
def __init__(self, path: Path | None = None, load: bool = False):
|
||||||
self.path = Config.get_config_dir(path)
|
self.path = Config.get_config_dir(path)
|
||||||
self.reset()
|
self.reset()
|
||||||
|
|
||||||
|
@ -92,9 +92,12 @@ class Config:
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_config_dir(path: str | None = None) -> Path:
|
def get_config_dir(path: Path | str | None = None) -> Path:
|
||||||
if path:
|
if isinstance(path, str):
|
||||||
return Path(path).expanduser().resolve()
|
path = Path(path)
|
||||||
|
|
||||||
|
if path is not None:
|
||||||
|
return path.expanduser().resolve()
|
||||||
|
|
||||||
paths = (
|
paths = (
|
||||||
Path("relay.yaml").resolve(),
|
Path("relay.yaml").resolve(),
|
||||||
|
|
|
@ -32,25 +32,16 @@ def check_alphanumeric(text: str) -> str:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
@click.group('cli', context_settings={'show_default': True}, invoke_without_command=True)
|
@click.group('cli', context_settings = {'show_default': True})
|
||||||
@click.option('--config', '-c', help='path to the relay\'s config')
|
@click.option('--config', '-c', type = Path, help = 'path to the relay\'s config')
|
||||||
@click.version_option(version=__version__, prog_name='ActivityRelay')
|
@click.version_option(version = __version__, prog_name = 'ActivityRelay')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def cli(ctx: click.Context, config: str | None) -> None:
|
def cli(ctx: click.Context, config: Path | None) -> None:
|
||||||
|
if IS_DOCKER:
|
||||||
|
config = Path("/data/relay.yaml")
|
||||||
|
|
||||||
ctx.obj = Application(config)
|
ctx.obj = Application(config)
|
||||||
|
|
||||||
if not ctx.invoked_subcommand:
|
|
||||||
if ctx.obj.config.domain.endswith('example.com'):
|
|
||||||
cli_setup.callback() # type: ignore
|
|
||||||
|
|
||||||
else:
|
|
||||||
click.echo(
|
|
||||||
'[DEPRECATED] Running the relay without the "run" command will be removed in the ' +
|
|
||||||
'future.'
|
|
||||||
)
|
|
||||||
|
|
||||||
cli_run.callback() # type: ignore
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command('setup')
|
@cli.command('setup')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
|
@ -86,7 +77,7 @@ def cli_setup(ctx: click.Context) -> None:
|
||||||
type = click.Choice(['postgres', 'sqlite'], case_sensitive = False)
|
type = click.Choice(['postgres', 'sqlite'], case_sensitive = False)
|
||||||
)
|
)
|
||||||
|
|
||||||
if ctx.obj.config.db_type == 'sqlite':
|
if ctx.obj.config.db_type == 'sqlite' and not IS_DOCKER:
|
||||||
ctx.obj.config.sq_path = click.prompt(
|
ctx.obj.config.sq_path = click.prompt(
|
||||||
'Where should the database be stored?',
|
'Where should the database be stored?',
|
||||||
default = ctx.obj.config.sq_path
|
default = ctx.obj.config.sq_path
|
||||||
|
@ -174,7 +165,11 @@ def cli_setup(ctx: click.Context) -> None:
|
||||||
for key, value in config.items():
|
for key, value in config.items():
|
||||||
conn.put_config(key, value)
|
conn.put_config(key, value)
|
||||||
|
|
||||||
if not IS_DOCKER and click.confirm('Relay all setup! Would you like to run it now?'):
|
if IS_DOCKER:
|
||||||
|
click.echo("Relay all setup! Start the container to run the relay.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if click.confirm('Relay all setup! Would you like to run it now?'):
|
||||||
cli_run.callback() # type: ignore
|
cli_run.callback() # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,10 +180,14 @@ def cli_run(ctx: click.Context, dev: bool = False) -> None:
|
||||||
'Run the relay'
|
'Run the relay'
|
||||||
|
|
||||||
if ctx.obj.config.domain.endswith('example.com') or not ctx.obj.signer:
|
if ctx.obj.config.domain.endswith('example.com') or not ctx.obj.signer:
|
||||||
click.echo(
|
if not IS_DOCKER:
|
||||||
'Relay is not set up. Please edit your relay config or run "activityrelay setup".'
|
click.echo(
|
||||||
)
|
'Relay is not set up. Please edit your relay config or run "activityrelay setup".'
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
cli_setup.callback() # type: ignore
|
||||||
return
|
return
|
||||||
|
|
||||||
vers_split = platform.python_version().split('.')
|
vers_split = platform.python_version().split('.')
|
||||||
|
|
Loading…
Reference in a new issue