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",
|
||||
multiple=True,
|
||||
)
|
||||
@click.option(
|
||||
"--install",
|
||||
help="Additional packages (e.g. plugins) to install",
|
||||
multiple=True,
|
||||
)
|
||||
@click.option("--title", help="Title for metadata")
|
||||
@click.option("--license", help="License label for metadata")
|
||||
@click.option("--license_url", help="License URL for metadata")
|
||||
|
|
@ -97,6 +102,7 @@ def publish(
|
|||
template_dir,
|
||||
plugins_dir,
|
||||
static,
|
||||
install,
|
||||
**extra_metadata
|
||||
):
|
||||
"""
|
||||
|
|
@ -140,6 +146,7 @@ def publish(
|
|||
template_dir,
|
||||
plugins_dir,
|
||||
static,
|
||||
install,
|
||||
extra_metadata,
|
||||
):
|
||||
if force:
|
||||
|
|
@ -175,6 +182,7 @@ def publish(
|
|||
template_dir,
|
||||
plugins_dir,
|
||||
static,
|
||||
install,
|
||||
extra_metadata,
|
||||
):
|
||||
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",
|
||||
multiple=True,
|
||||
)
|
||||
@click.option(
|
||||
"--install",
|
||||
help="Additional packages (e.g. plugins) to install",
|
||||
multiple=True,
|
||||
)
|
||||
@click.option("--title", help="Title for metadata")
|
||||
@click.option("--license", help="License label for metadata")
|
||||
@click.option("--license_url", help="License URL for metadata")
|
||||
|
|
@ -300,6 +313,7 @@ def package(
|
|||
template_dir,
|
||||
plugins_dir,
|
||||
static,
|
||||
install,
|
||||
**extra_metadata
|
||||
):
|
||||
"Package specified SQLite files into a new datasette Docker container"
|
||||
|
|
@ -321,6 +335,7 @@ def package(
|
|||
template_dir,
|
||||
plugins_dir,
|
||||
static,
|
||||
install,
|
||||
extra_metadata,
|
||||
):
|
||||
args = ["docker", "build"]
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ def escape_sqlite(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.append('"' + '", "'.join(files) + '"')
|
||||
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:
|
||||
for opt in extra_options.split():
|
||||
cmd.append('"{}"'.format(opt))
|
||||
|
||||
install_from = 'datasette'
|
||||
if branch:
|
||||
install_from = 'https://github.com/simonw/datasette/archive/{}.zip'.format(
|
||||
install = ['https://github.com/simonw/datasette/archive/{}.zip'.format(
|
||||
branch
|
||||
)
|
||||
)] + list(install)
|
||||
else:
|
||||
install = ['datasette'] + list(install)
|
||||
|
||||
return '''
|
||||
FROM python:3
|
||||
COPY . /app
|
||||
|
|
@ -219,12 +223,23 @@ EXPOSE 8001
|
|||
CMD [{cmd}]'''.format(
|
||||
files=' '.join(files),
|
||||
cmd=', '.join(cmd),
|
||||
install_from=install_from,
|
||||
install_from=' '.join(install),
|
||||
).strip()
|
||||
|
||||
|
||||
@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 {}
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
# 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,
|
||||
plugins_dir,
|
||||
static,
|
||||
install,
|
||||
)
|
||||
os.chdir(datasette_dir)
|
||||
if metadata_content:
|
||||
|
|
@ -281,7 +297,18 @@ def temporary_docker_directory(files, name, metadata, extra_options, branch, tem
|
|||
|
||||
|
||||
@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
|
||||
|
||||
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')
|
||||
|
||||
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
|
||||
)
|
||||
)] + list(install)
|
||||
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')
|
||||
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,
|
||||
plugins_dir=None,
|
||||
static=[],
|
||||
install=[],
|
||||
) as temp_docker:
|
||||
hello = os.path.join(temp_docker, 'hello')
|
||||
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,
|
||||
plugins_dir=None,
|
||||
static=[],
|
||||
install=[],
|
||||
) as temp_docker:
|
||||
hello = os.path.join(temp_docker, 'hello')
|
||||
assert 'world' == open(hello).read()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue