Skip to content

Migrate to Fly and get READMEs working again #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 16, 2025
Merged

Migrate to Fly and get READMEs working again #164

merged 18 commits into from
May 16, 2025

Conversation

simonw
Copy link
Owner

@simonw simonw commented May 14, 2025

I'm using this PR to document some hacks.

Comment on lines 186 to 198
# fix_repo_names = [
# row[0]
# for row in db.execute(
# """
# select full_name from repos
# where readme_html like '%camo.githubusercontent.com%'
# and readme not like '%camo.githubusercontent.com%'
# limit 3
# """
# ).fetchall()
# ]
# print("Fixing HTML for {}".format(fix_repo_names))
# repos_to_fetch.extend(fix_repo_names)
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the worst mess: because I lost the old content.db I had to build from scratch, but somewhere our build scripts had depended on the previous DB having those readme and readme_html columns - without those I couldn't bootstrap a new database.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to figure out how to rebuild those, while not getting busted by GitHub's rate limit if we need to get READMEs for hundreds of repos.

Comment on lines 10 to 14
db["tutorials"].create({
"path": str,
"title": str,
"body": str,
}, pk="path")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to explicitly create this table here, because otherwise when Datasette tried to render the /tutorials page this template fragment would throw an error:

<h3>More tutorials</h3>
<ul>
{% for row in sql("select path, title from tutorials where path != ?", [path], database="content") %}
<li><a href="{{ row.path }}">{{ row.title }}</a></li>
{% endfor %}
</ul>

Comment on lines +16 to +17
sqlite-utils drop-table content.db plugin_repos --ignore
sqlite-utils drop-table content.db tool_repos --ignore
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added --ignore because otherwise we would be dropping a table that didn't exist yet in our fresh content.db database.

Comment on lines 116 to 123
tools.description as search_1, -- || ' ' || coalesce(repos.readme, '') as search_1,
1 as is_public
from tools join repos on tools.name = repos.name
display_sql: |-
select
highlight(
tools.description || ' ' || coalesce(repos.readme_html, ''), :q
tools.description, -- || ' ' || coalesce(repos.readme_html, ''),
:q
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More hacks to deal with the missing readme and readme_html columns.

@simonw simonw marked this pull request as ready for review May 16, 2025 14:13
@simonw simonw changed the title Notes on migration to Fly Migrate to Fly and get READMEs working again May 16, 2025
@simonw
Copy link
Owner Author

simonw commented May 16, 2025

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.22/x64/bin/dogsheep-beta", line 8, in <module>
    sys.exit(cli())
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/dogsheep_beta/cli.py", line 36, in index
    run_indexer(
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/dogsheep_beta/utils.py", line 48, in run_indexer
    columns = derive_columns(other_db, sql)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/dogsheep_beta/utils.py", line 65, in derive_columns
    cursor = db.conn.execute(sql + " limit 0")
sqlite3.OperationalError: no such table: til

@simonw
Copy link
Owner Author

simonw commented May 16, 2025

Getting closer...

    [n async for n in self.root_render_func(ctx)]  # type: ignore
  File "/home/runner/work/datasette.io/datasette.io/templates/pages/plugins/{name}.html", line 17, in top-level template code
    {% set plugin = plugins[0] %}
  File "/home/runner/work/datasette.io/datasette.io/templates/page_base.html", line 9, in top-level template code
    {% block extra_head %}{% endblock %}
  File "/home/runner/work/datasette.io/datasette.io/templates/pages/plugins/{name}.html", line 22, in block 'extra_head'
    {% if plugin.usesCustomOpenGraphImage %}
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/jinja2/environment.py", line 490, in getattr
    return getattr(obj, attribute)
jinja2.exceptions.UndefinedError: list object has no element 0
Test failed to /plugins/datasette-dashboards

@simonw
Copy link
Owner Author

simonw commented May 16, 2025

  File "/home/runner/work/datasette.io/datasette.io/build_stats.py", line 32, in <module>
    cli()
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/home/runner/work/datasette.io/datasette.io/build_stats.py", line 17, in cli
    stats = json.load(stats_file)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@simonw
Copy link
Owner Author

simonw commented May 16, 2025

Urgh I bet that was a rate limit too.

@simonw
Copy link
Owner Author

simonw commented May 16, 2025

  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/datasette/database.py", line 211, in in_thread
    return fn(conn)
  File "/opt/hostedtoolcache/Python/3.9.22/x64/lib/python3.9/site-packages/datasette/database.py", line 237, in sql_operation_in_thread
    cursor.execute(sql, params if params is not None else {})
sqlite3.OperationalError: near ":q": syntax error
Test failed to /-/beta?q=datasette

@simonw
Copy link
Owner Author

simonw commented May 16, 2025

Oh the problem is:

ERROR: conn=<sqlite3.Connection object at 0x7fecbc9a73f0>, sql = "select\n highlight(\n plugins.description || ' ' || coalesce(repos.readme_html, ''), :q\n :q\n ) as snippet,\n usesCustomOpenGraphImage,\n openGraphImageUrl\nfrom\n plugins join repos on plugins.name = repos.name\nwhere\n plugins.name = :key", params = {'key': 'datasette-visible-internal-db', 'q': 'datasette'}: near ":q": syntax error

@simonw
Copy link
Owner Author

simonw commented May 16, 2025

Publishing to Fly requires flyctl to be installed and configured

Because it's in a different location:

Run '/home/runner/.fly/bin/flyctl --help' to get started

@simonw
Copy link
Owner Author

simonw commented May 16, 2025

Looks promising...

CleanShot 2025-05-16 at 11 22 39@2x

@simonw
Copy link
Owner Author

simonw commented May 16, 2025

https://datasette.io/plugins/datasette-chronicle is now showing the full README!

@simonw simonw merged commit 2bc8a69 into main May 16, 2025
1 check passed
@simonw simonw deleted the fly branch May 16, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant