Skip to content

Commit

Permalink
Update docs / clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
jdangerx committed Jun 13, 2024
1 parent f644c4d commit 635384a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion devtools/datasette/fly/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ mv all_dbs.tar.zst /data
zstd -f -d /data/all_dbs.tar.zst -o /data/all_dbs.tar
tar -xf /data/all_dbs.tar --directory /data
datasette serve --host 0.0.0.0 ${DATABASES} --cors --inspect-file inspect-data.json --metadata metadata.yml --setting sql_time_limit_ms 5000 --port $DATASETTE_PORT > /dev/null &
nginx -c nginx.conf # -g 'daemon off;'
nginx -c nginx.conf
22 changes: 12 additions & 10 deletions devtools/datasette/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
RUN apt-get install -y zstd nginx
RUN pip install -U datasette datasette-cluster-map datasette-vega datasette-block-robots
# set up nginx + enable real IP module
COPY nginx.conf /usr/share/nginx/nginx.conf
COPY 50-mod-http-realip.conf /etc/nginx/modules-enabled/
# the two symlinks allow nginx logs to get written out to stdout/stderr
RUN mkdir /data \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
Expand Down Expand Up @@ -115,7 +117,8 @@ def inspect_data(datasets: list[str], pudl_output: Path) -> str:
"-l",
"deploy",
flag_value="local",
help="Deploy Datasette locally for testing or debugging purposes.",
help="Deploy Datasette locally for testing or debugging purposes. Note that"
"you have to stop the docker instance manually to terminate this server.",
)
@click.option(
"--metadata",
Expand Down Expand Up @@ -150,9 +153,6 @@ def deploy_datasette(
logging.info(f"Deploying to {deploy.upper()}...")
pudl_output = PudlPaths().pudl_output

pudl_output = PudlPaths().pudl_output
metadata_yml = DatasetteMetadata.from_data_source_ids(pudl_output).to_yaml()

all_databases = (
["pudl.sqlite"]
+ sorted(str(p.name) for p in pudl_output.glob("ferc*.sqlite"))
Expand All @@ -164,20 +164,20 @@ def deploy_datasette(
docker_path = fly_dir / "Dockerfile"
inspect_path = fly_dir / "inspect-data.json"
metadata_path = fly_dir / "metadata.yml"

logging.info(f"Inspecting DBs for datasette: {databases}...")
inspect_output = inspect_data(databases, pudl_output)
with inspect_path.open("w") as f:
f.write(json.dumps(inspect_output))
metadata_yml = DatasetteMetadata.from_data_source_ids(pudl_output).to_yaml()

logging.info(f"Writing Datasette metadata to: {metadata_path}")
with metadata_path.open("w") as f:
f.write(metadata_yml)
check_tables_have_metadata(metadata_yml, databases)

if deploy == "metadata":
logging.info("Only writing metadata. Aborting now.")

check_tables_have_metadata(metadata_yml, databases)
logging.info(f"Inspecting DBs for datasette: {databases}...")
inspect_output = inspect_data(databases, pudl_output)
with inspect_path.open("w") as f:
f.write(json.dumps(inspect_output))

logging.info("Writing Dockerfile...")
with docker_path.open("w") as f:
Expand All @@ -189,6 +189,8 @@ def deploy_datasette(
cwd=pudl_output,
)

# OK, now we have a Dockerfile + the right context. Time to run the dang
# container somehwere.
if deploy in {"production", "staging"}:
logging.info("Running fly deploy...")
cmd = ["/usr/bin/env", "flyctl", "deploy", "-c", fly_dir / f"{deploy}.toml"]
Expand Down
2 changes: 1 addition & 1 deletion src/pudl/metadata/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2216,7 +2216,7 @@ def from_data_source_ids(
xbrl_resources=xbrl_resources,
)

def to_yaml(self) -> None:
def to_yaml(self) -> str:
"""Output database, table, and column metadata to YAML file."""
template = _get_jinja_environment().get_template("datasette-metadata.yml.jinja")

Expand Down

0 comments on commit 635384a

Please sign in to comment.