diff --git a/README.md b/README.md index 89fa2c78..c8e4793e 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,11 @@ This will create a docker image containing both the datasette application and th -m, --metadata FILENAME Path to JSON file containing metadata to publish --extra-options TEXT Extra options to pass to datasette serve --force Pass --force option to now + --title TEXT Title for metadata + --license TEXT License label for metadata + --license_url TEXT License URL for metadata + --source TEXT Source label for metadata + --source_url TEXT Source URL for metadata --help Show this message and exit. ## datasette package @@ -155,6 +160,11 @@ If you have docker installed you can use `datasette package` to create a new Doc optionally use name:tag format -m, --metadata FILENAME Path to JSON file containing metadata to publish --extra-options TEXT Extra options to pass to datasette serve + --title TEXT Title for metadata + --license TEXT License label for metadata + --license_url TEXT License URL for metadata + --source TEXT Source label for metadata + --source_url TEXT Source URL for metadata --help Show this message and exit. Both publish and package accept an `extra_options` argument option, which will affect how the resulting application is executed. For example, say you want to increase the SQL time limit for a particular container: diff --git a/datasette/cli.py b/datasette/cli.py index eafde872..b034be48 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -38,7 +38,12 @@ def build(files, inspect_file): ) @click.option('--extra-options', help='Extra options to pass to datasette serve') @click.option('--force', is_flag=True, help='Pass --force option to now') -def publish(publisher, files, name, metadata, extra_options, force): +@click.option('--title', help='Title for metadata') +@click.option('--license', help='License label for metadata') +@click.option('--license_url', help='License URL for metadata') +@click.option('--source', help='Source label for metadata') +@click.option('--source_url', help='Source URL for metadata') +def publish(publisher, files, name, metadata, extra_options, force, **extra_metadata): """ Publish specified SQLite database files to the internet along with a datasette API. @@ -58,7 +63,7 @@ def publish(publisher, files, name, metadata, extra_options, force): click.echo('Follow the instructions at https://zeit.co/now#whats-now', err=True) sys.exit(1) - with temporary_docker_directory(files, name, metadata, extra_options): + with temporary_docker_directory(files, name, metadata, extra_options, extra_metadata): if force: call(['now', '--force']) else: @@ -76,7 +81,12 @@ def publish(publisher, files, name, metadata, extra_options, force): help='Path to JSON file containing metadata to publish' ) @click.option('--extra-options', help='Extra options to pass to datasette serve') -def package(files, tag, metadata, extra_options): +@click.option('--title', help='Title for metadata') +@click.option('--license', help='License label for metadata') +@click.option('--license_url', help='License URL for metadata') +@click.option('--source', help='Source label for metadata') +@click.option('--source_url', help='Source URL for metadata') +def package(files, tag, metadata, extra_options, **extra_metadata): "Package specified SQLite files into a new datasette Docker container" if not shutil.which('docker'): click.secho( @@ -87,7 +97,7 @@ def package(files, tag, metadata, extra_options): err=True, ) sys.exit(1) - with temporary_docker_directory(files, 'datasette', metadata, extra_options): + with temporary_docker_directory(files, 'datasette', metadata, extra_options, extra_metadata): args = ['docker', 'build'] if tag: args.append('-t') diff --git a/datasette/utils.py b/datasette/utils.py index c41d9f42..4d296838 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -166,7 +166,8 @@ CMD [{}]'''.format( @contextmanager -def temporary_docker_directory(files, name, metadata, extra_options): +def temporary_docker_directory(files, name, metadata, extra_options, 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 datasette_dir = os.path.join(tmp.name, name) @@ -177,12 +178,19 @@ def temporary_docker_directory(files, name, metadata, extra_options): for name in files ] file_names = [os.path.split(f)[-1] for f in files] + if metadata: + metadata_content = json.load(open(metadata)) + else: + metadata_content = {} + for key, value in extra_metadata.items(): + if value: + metadata_content[key] = value try: - dockerfile = make_dockerfile(file_names, metadata and 'metadata.json', extra_options) + dockerfile = make_dockerfile(file_names, metadata_content and 'metadata.json', extra_options) os.chdir(datasette_dir) + if metadata_content: + open('metadata.json', 'w').write(json.dumps(metadata_content, indent=2)) open('Dockerfile', 'w').write(dockerfile) - if metadata: - open('metadata.json', 'w').write(metadata.read()) for path, filename in zip(file_paths, file_names): os.link(path, os.path.join(datasette_dir, filename)) yield