Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions datasette/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ def plugins(all, requirements, plugins_dir):
"--tag",
help="Name for the resulting Docker container, can optionally use name:tag format",
)
@click.option(
"-c",
"--config",
type=click.File(mode="r"),
help="Path to JSON/YAML Datasette configuration file",
)
@click.option(
"-m",
"--metadata",
Expand Down Expand Up @@ -250,6 +256,7 @@ def plugins(all, requirements, plugins_dir):
def package(
files,
tag,
config,
metadata,
extra_options,
branch,
Expand All @@ -276,6 +283,7 @@ def package(
with temporary_docker_directory(
files,
"datasette",
config=config,
metadata=metadata,
extra_options=extra_options,
branch=branch,
Expand Down
12 changes: 12 additions & 0 deletions datasette/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def escape_sqlite(s):

def make_dockerfile(
files,
config_file,
metadata_file,
extra_options,
branch,
Expand All @@ -378,6 +379,8 @@ def make_dockerfile(
for filename in files:
cmd.extend(["-i", filename])
cmd.extend(["--cors", "--inspect-file", "inspect-data.json"])
if config_file:
cmd.extend(["--config", f"{config_file}"])
if metadata_file:
cmd.extend(["--metadata", f"{metadata_file}"])
if template_dir:
Expand Down Expand Up @@ -444,6 +447,7 @@ def make_dockerfile(
def temporary_docker_directory(
files,
name,
config,
metadata,
extra_options,
branch,
Expand All @@ -467,6 +471,10 @@ def temporary_docker_directory(
saved_cwd = os.getcwd()
file_paths = [os.path.join(saved_cwd, file_path) for file_path in files]
file_names = [os.path.split(f)[-1] for f in files]
if config:
config_content = parse_metadata(config.read())
else:
config_content = {}
if metadata:
metadata_content = parse_metadata(metadata.read())
else:
Expand All @@ -479,6 +487,7 @@ def temporary_docker_directory(
try:
dockerfile = make_dockerfile(
file_names,
config_content and "config.json",
metadata_content and "metadata.json",
extra_options,
branch,
Expand All @@ -494,6 +503,9 @@ def temporary_docker_directory(
apt_get_extras=apt_get_extras,
)
os.chdir(datasette_dir)
if config_content:
with open("config.json", "w") as fp:
fp.write(json.dumps(config_content, indent=2))
if metadata_content:
with open("metadata.json", "w") as fp:
fp.write(json.dumps(metadata_content, indent=2))
Expand Down
3 changes: 3 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def test_temporary_docker_directory_uses_hard_link():
with utils.temporary_docker_directory(
files=["hello"],
name="t",
config=None,
metadata=None,
extra_options=None,
branch=None,
Expand Down Expand Up @@ -296,6 +297,7 @@ def test_temporary_docker_directory_uses_copy_if_hard_link_fails(mock_link):
with utils.temporary_docker_directory(
files=["hello"],
name="t",
config=None,
metadata=None,
extra_options=None,
branch=None,
Expand All @@ -322,6 +324,7 @@ def test_temporary_docker_directory_quotes_args():
with utils.temporary_docker_directory(
files=["hello"],
name="t",
config=None,
metadata=None,
extra_options="--$HOME",
branch=None,
Expand Down