mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
datasette publish/package --install option, closes #223
Allows you to specify one or more additional packages to be installed, useful for deploying plugins.
This commit is contained in:
parent
2b344f6a34
commit
404fa2252b
3 changed files with 54 additions and 10 deletions
|
|
@ -81,6 +81,11 @@ def inspect(files, inspect_file, sqlite_extensions):
|
||||||
help="mountpoint:path-to-directory for serving static files",
|
help="mountpoint:path-to-directory for serving static files",
|
||||||
multiple=True,
|
multiple=True,
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--install",
|
||||||
|
help="Additional packages (e.g. plugins) to install",
|
||||||
|
multiple=True,
|
||||||
|
)
|
||||||
@click.option("--title", help="Title for metadata")
|
@click.option("--title", help="Title for metadata")
|
||||||
@click.option("--license", help="License label for metadata")
|
@click.option("--license", help="License label for metadata")
|
||||||
@click.option("--license_url", help="License URL for metadata")
|
@click.option("--license_url", help="License URL for metadata")
|
||||||
|
|
@ -97,6 +102,7 @@ def publish(
|
||||||
template_dir,
|
template_dir,
|
||||||
plugins_dir,
|
plugins_dir,
|
||||||
static,
|
static,
|
||||||
|
install,
|
||||||
**extra_metadata
|
**extra_metadata
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
@ -140,6 +146,7 @@ def publish(
|
||||||
template_dir,
|
template_dir,
|
||||||
plugins_dir,
|
plugins_dir,
|
||||||
static,
|
static,
|
||||||
|
install,
|
||||||
extra_metadata,
|
extra_metadata,
|
||||||
):
|
):
|
||||||
if force:
|
if force:
|
||||||
|
|
@ -175,6 +182,7 @@ def publish(
|
||||||
template_dir,
|
template_dir,
|
||||||
plugins_dir,
|
plugins_dir,
|
||||||
static,
|
static,
|
||||||
|
install,
|
||||||
extra_metadata,
|
extra_metadata,
|
||||||
):
|
):
|
||||||
create_output = check_output(["heroku", "apps:create", "--json"]).decode(
|
create_output = check_output(["heroku", "apps:create", "--json"]).decode(
|
||||||
|
|
@ -286,6 +294,11 @@ def skeleton(files, metadata, sqlite_extensions):
|
||||||
help="mountpoint:path-to-directory for serving static files",
|
help="mountpoint:path-to-directory for serving static files",
|
||||||
multiple=True,
|
multiple=True,
|
||||||
)
|
)
|
||||||
|
@click.option(
|
||||||
|
"--install",
|
||||||
|
help="Additional packages (e.g. plugins) to install",
|
||||||
|
multiple=True,
|
||||||
|
)
|
||||||
@click.option("--title", help="Title for metadata")
|
@click.option("--title", help="Title for metadata")
|
||||||
@click.option("--license", help="License label for metadata")
|
@click.option("--license", help="License label for metadata")
|
||||||
@click.option("--license_url", help="License URL for metadata")
|
@click.option("--license_url", help="License URL for metadata")
|
||||||
|
|
@ -300,6 +313,7 @@ def package(
|
||||||
template_dir,
|
template_dir,
|
||||||
plugins_dir,
|
plugins_dir,
|
||||||
static,
|
static,
|
||||||
|
install,
|
||||||
**extra_metadata
|
**extra_metadata
|
||||||
):
|
):
|
||||||
"Package specified SQLite files into a new datasette Docker container"
|
"Package specified SQLite files into a new datasette Docker container"
|
||||||
|
|
@ -321,6 +335,7 @@ def package(
|
||||||
template_dir,
|
template_dir,
|
||||||
plugins_dir,
|
plugins_dir,
|
||||||
static,
|
static,
|
||||||
|
install,
|
||||||
extra_metadata,
|
extra_metadata,
|
||||||
):
|
):
|
||||||
args = ["docker", "build"]
|
args = ["docker", "build"]
|
||||||
|
|
|
||||||
|
|
@ -188,7 +188,7 @@ def escape_sqlite(s):
|
||||||
return '[{}]'.format(s)
|
return '[{}]'.format(s)
|
||||||
|
|
||||||
|
|
||||||
def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, plugins_dir, static):
|
def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, plugins_dir, static, install):
|
||||||
cmd = ['"datasette"', '"serve"', '"--host"', '"0.0.0.0"']
|
cmd = ['"datasette"', '"serve"', '"--host"', '"0.0.0.0"']
|
||||||
cmd.append('"' + '", "'.join(files) + '"')
|
cmd.append('"' + '", "'.join(files) + '"')
|
||||||
cmd.extend(['"--cors"', '"--port"', '"8001"', '"--inspect-file"', '"inspect-data.json"'])
|
cmd.extend(['"--cors"', '"--port"', '"8001"', '"--inspect-file"', '"inspect-data.json"'])
|
||||||
|
|
@ -204,11 +204,15 @@ def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, p
|
||||||
if extra_options:
|
if extra_options:
|
||||||
for opt in extra_options.split():
|
for opt in extra_options.split():
|
||||||
cmd.append('"{}"'.format(opt))
|
cmd.append('"{}"'.format(opt))
|
||||||
|
|
||||||
install_from = 'datasette'
|
install_from = 'datasette'
|
||||||
if branch:
|
if branch:
|
||||||
install_from = 'https://github.com/simonw/datasette/archive/{}.zip'.format(
|
install = ['https://github.com/simonw/datasette/archive/{}.zip'.format(
|
||||||
branch
|
branch
|
||||||
)
|
)] + list(install)
|
||||||
|
else:
|
||||||
|
install = ['datasette'] + list(install)
|
||||||
|
|
||||||
return '''
|
return '''
|
||||||
FROM python:3
|
FROM python:3
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
@ -219,12 +223,23 @@ EXPOSE 8001
|
||||||
CMD [{cmd}]'''.format(
|
CMD [{cmd}]'''.format(
|
||||||
files=' '.join(files),
|
files=' '.join(files),
|
||||||
cmd=', '.join(cmd),
|
cmd=', '.join(cmd),
|
||||||
install_from=install_from,
|
install_from=' '.join(install),
|
||||||
).strip()
|
).strip()
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def temporary_docker_directory(files, name, metadata, extra_options, branch, template_dir, plugins_dir, static, extra_metadata=None):
|
def temporary_docker_directory(
|
||||||
|
files,
|
||||||
|
name,
|
||||||
|
metadata,
|
||||||
|
extra_options,
|
||||||
|
branch,
|
||||||
|
template_dir,
|
||||||
|
plugins_dir,
|
||||||
|
static,
|
||||||
|
install,
|
||||||
|
extra_metadata=None
|
||||||
|
):
|
||||||
extra_metadata = extra_metadata or {}
|
extra_metadata = extra_metadata or {}
|
||||||
tmp = tempfile.TemporaryDirectory()
|
tmp = tempfile.TemporaryDirectory()
|
||||||
# We create a datasette folder in there to get a nicer now deploy name
|
# We create a datasette folder in there to get a nicer now deploy name
|
||||||
|
|
@ -252,6 +267,7 @@ def temporary_docker_directory(files, name, metadata, extra_options, branch, tem
|
||||||
template_dir,
|
template_dir,
|
||||||
plugins_dir,
|
plugins_dir,
|
||||||
static,
|
static,
|
||||||
|
install,
|
||||||
)
|
)
|
||||||
os.chdir(datasette_dir)
|
os.chdir(datasette_dir)
|
||||||
if metadata_content:
|
if metadata_content:
|
||||||
|
|
@ -281,7 +297,18 @@ def temporary_docker_directory(files, name, metadata, extra_options, branch, tem
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def temporary_heroku_directory(files, name, metadata, extra_options, branch, template_dir, plugins_dir, static, extra_metadata=None):
|
def temporary_heroku_directory(
|
||||||
|
files,
|
||||||
|
name,
|
||||||
|
metadata,
|
||||||
|
extra_options,
|
||||||
|
branch,
|
||||||
|
template_dir,
|
||||||
|
plugins_dir,
|
||||||
|
static,
|
||||||
|
install,
|
||||||
|
extra_metadata=None
|
||||||
|
):
|
||||||
# FIXME: lots of duplicated code from above
|
# FIXME: lots of duplicated code from above
|
||||||
|
|
||||||
extra_metadata = extra_metadata or {}
|
extra_metadata = extra_metadata or {}
|
||||||
|
|
@ -311,13 +338,13 @@ def temporary_heroku_directory(files, name, metadata, extra_options, branch, tem
|
||||||
open('runtime.txt', 'w').write('python-3.6.3')
|
open('runtime.txt', 'w').write('python-3.6.3')
|
||||||
|
|
||||||
if branch:
|
if branch:
|
||||||
install_from = 'https://github.com/simonw/datasette/archive/{branch}.zip'.format(
|
install = ['https://github.com/simonw/datasette/archive/{branch}.zip'.format(
|
||||||
branch=branch
|
branch=branch
|
||||||
)
|
)] + list(install)
|
||||||
else:
|
else:
|
||||||
install_from = 'datasette'
|
install = ['datasette'] + list(install)
|
||||||
|
|
||||||
open('requirements.txt', 'w').write(install_from)
|
open('requirements.txt', 'w').write('\n'.join(install))
|
||||||
os.mkdir('bin')
|
os.mkdir('bin')
|
||||||
open('bin/post_compile', 'w').write('datasette inspect --inspect-file inspect-data.json')
|
open('bin/post_compile', 'w').write('datasette inspect --inspect-file inspect-data.json')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,7 @@ def test_temporary_docker_directory_uses_hard_link():
|
||||||
template_dir=None,
|
template_dir=None,
|
||||||
plugins_dir=None,
|
plugins_dir=None,
|
||||||
static=[],
|
static=[],
|
||||||
|
install=[],
|
||||||
) as temp_docker:
|
) as temp_docker:
|
||||||
hello = os.path.join(temp_docker, 'hello')
|
hello = os.path.join(temp_docker, 'hello')
|
||||||
assert 'world' == open(hello).read()
|
assert 'world' == open(hello).read()
|
||||||
|
|
@ -221,6 +222,7 @@ def test_temporary_docker_directory_uses_copy_if_hard_link_fails(mock_link):
|
||||||
template_dir=None,
|
template_dir=None,
|
||||||
plugins_dir=None,
|
plugins_dir=None,
|
||||||
static=[],
|
static=[],
|
||||||
|
install=[],
|
||||||
) as temp_docker:
|
) as temp_docker:
|
||||||
hello = os.path.join(temp_docker, 'hello')
|
hello = os.path.join(temp_docker, 'hello')
|
||||||
assert 'world' == open(hello).read()
|
assert 'world' == open(hello).read()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue