From 287ac27e068e12e932ab2ef52d3cadddd2b06ebe Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 12:36:11 -0700 Subject: [PATCH 01/10] First attempt at publish now deploy --- .travis.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.travis.yml b/.travis.yml index fc01da26..c417c89f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,15 @@ python: - 3.5 - 3.6 +# Executed for 3.5 AND 3.5 as the first "test" stage: script: - python setup.py test + +# This defines further stages that execute after the tests +jobs: + include: + - stage: deploy latest.datesette.io + script: + - python tests/fixtures.py fixtures.db fixtures.json + - datasette publish now fixtures.db -m fixtures.json --name datasette-latest + on: travis-deploy-now From c32889d3cd3abd7dfab5911f1b618e3c10895fb0 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 12:46:52 -0700 Subject: [PATCH 02/10] datasette publish now --token=X argument --- datasette/cli.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/datasette/cli.py b/datasette/cli.py index 2f61559a..04bf2dfa 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -111,6 +111,7 @@ def inspect(files, inspect_file, sqlite_extensions): @click.option("--extra-options", help="Extra options to pass to datasette serve") @click.option("--force", is_flag=True, help="Pass --force option to now") @click.option("--branch", help="Install datasette from a GitHub branch e.g. master") +@click.option("--token", help="Auth token to use for deploy (Now only)") @click.option( "--template-dir", type=click.Path(exists=True, file_okay=False, dir_okay=True), @@ -148,6 +149,7 @@ def publish( extra_options, force, branch, + token, template_dir, plugins_dir, static, @@ -200,8 +202,13 @@ def publish( spatialite, extra_metadata, ): + args = [] if force: - call(["now", "--force"]) + args.append("--force") + if token: + args.append("--token={}".format(token)) + if args: + call(["now"] + args) else: call("now") From 18b2902bc3bd2060a42d07cf08a7496608fbf910 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 12:47:13 -0700 Subject: [PATCH 03/10] Use new --token= argument in Travis --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c417c89f..b3d879e1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ jobs: include: - stage: deploy latest.datesette.io script: + - pip install . - python tests/fixtures.py fixtures.db fixtures.json - - datasette publish now fixtures.db -m fixtures.json --name datasette-latest + - datasette publish now fixtures.db -m fixtures.json --name datasette-latest --token=$NOW_TOKEN on: travis-deploy-now From 6d1c3559b41f867b269a67df454876998ae45331 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 12:57:22 -0700 Subject: [PATCH 04/10] npm install now --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b3d879e1..d54622f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,10 @@ script: # This defines further stages that execute after the tests jobs: include: - - stage: deploy latest.datesette.io + - stage: deploy latest.datasette.io script: - pip install . + - npm install -g now - python tests/fixtures.py fixtures.db fixtures.json - datasette publish now fixtures.db -m fixtures.json --name datasette-latest --token=$NOW_TOKEN on: travis-deploy-now From ea0069ef44473be8ecef088b8fe2d7f814884fd6 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 13:14:55 -0700 Subject: [PATCH 05/10] datasette and datasette publish --version-note --- datasette/app.py | 8 ++++++-- datasette/cli.py | 6 ++++++ datasette/utils.py | 6 +++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/datasette/app.py b/datasette/app.py index 871a4bf1..70f2a93f 100644 --- a/datasette/app.py +++ b/datasette/app.py @@ -119,6 +119,7 @@ class Datasette: plugins_dir=None, static_mounts=None, config=None, + version_note=None, ): self.files = files self.cache_headers = cache_headers @@ -131,6 +132,7 @@ class Datasette: self.plugins_dir = plugins_dir self.static_mounts = static_mounts or [] self.config = dict(DEFAULT_CONFIG, **(config or {})) + self.version_note = version_note self.executor = futures.ThreadPoolExecutor( max_workers=self.config["num_sql_threads"] ) @@ -298,12 +300,14 @@ class Datasette: fts_versions.append(fts) except sqlite3.OperationalError: continue - + datasette_version = {"version": __version__} + if self.version_note: + datasette_version["note"] = self.version_note return { "python": { "version": ".".join(map(str, sys.version_info[:3])), "full": sys.version }, - "datasette": {"version": __version__}, + "datasette": datasette_version, "sqlite": { "version": sqlite_version, "fts_versions": fts_versions, diff --git a/datasette/cli.py b/datasette/cli.py index 04bf2dfa..ddb8d4ca 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -136,6 +136,7 @@ def inspect(files, inspect_file, sqlite_extensions): @click.option( "--spatialite", is_flag=True, help="Enable SpatialLite extension" ) +@click.option("--version-note", help="Additional note to show on /-/versions") @click.option("--title", help="Title for metadata") @click.option("--license", help="License label for metadata") @click.option("--license_url", help="License URL for metadata") @@ -155,6 +156,7 @@ def publish( static, install, spatialite, + version_note, **extra_metadata ): """ @@ -200,6 +202,7 @@ def publish( static, install, spatialite, + version_note, extra_metadata, ): args = [] @@ -478,6 +481,7 @@ def package( help="Set config option using configname:value datasette.readthedocs.io/en/latest/config.html", multiple=True, ) +@click.option("--version-note", help="Additional note to show on /-/versions") @click.option( "--help-config", is_flag=True, @@ -497,6 +501,7 @@ def serve( plugins_dir, static, config, + version_note, help_config, ): """Serve up specified SQLite database files with a web UI""" @@ -538,6 +543,7 @@ def serve( plugins_dir=plugins_dir, static_mounts=static, config=dict(config), + version_note=version_note, ) # Force initial hashing/table counting ds.inspect() diff --git a/datasette/utils.py b/datasette/utils.py index 033f2c22..a179eddf 100644 --- a/datasette/utils.py +++ b/datasette/utils.py @@ -241,7 +241,7 @@ def escape_sqlite(s): return '[{}]'.format(s) -def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, plugins_dir, static, install, spatialite): +def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, plugins_dir, static, install, spatialite, version_note): cmd = ['"datasette"', '"serve"', '"--host"', '"0.0.0.0"'] cmd.append('"' + '", "'.join(files) + '"') cmd.extend(['"--cors"', '"--port"', '"8001"', '"--inspect-file"', '"inspect-data.json"']) @@ -251,6 +251,8 @@ def make_dockerfile(files, metadata_file, extra_options, branch, template_dir, p cmd.extend(['"--template-dir"', '"templates/"']) if plugins_dir: cmd.extend(['"--plugins-dir"', '"plugins/"']) + if version_note: + cmd.extend(['"--version-note"', '"{}"'.format(version_note)]) if static: for mount_point, _ in static: cmd.extend(['"--static"', '"{}:{}"'.format(mount_point, mount_point)]) @@ -293,6 +295,7 @@ def temporary_docker_directory( static, install, spatialite, + version_note, extra_metadata=None ): extra_metadata = extra_metadata or {} @@ -324,6 +327,7 @@ def temporary_docker_directory( static, install, spatialite, + version_note, ) os.chdir(datasette_dir) if metadata_content: From b454d61e9f341e632c24b6d56934e7521c3efbbc Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 13:24:38 -0700 Subject: [PATCH 06/10] Alias deploy to latest.datasette.io AND commithash.datasette.io --- .travis.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d54622f5..ce21590f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: python python: - - 3.5 - 3.6 + - 3.5 # Executed for 3.5 AND 3.5 as the first "test" stage: script: @@ -16,5 +16,9 @@ jobs: - pip install . - npm install -g now - python tests/fixtures.py fixtures.db fixtures.json - - datasette publish now fixtures.db -m fixtures.json --name datasette-latest --token=$NOW_TOKEN + - echo '{"name":"datasette-latest","alias":"latest.datasette.io"}' > now.json + - datasette publish now fixtures.db -m fixtures.json --token=$NOW_TOKEN --branch=$TRAVIS_COMMIT --version-note=$TRAVIS_COMMIT + - now alias + - echo "{\"name\":\"datasette-latest\",\"alias\":\"$TRAVIS_COMMIT.datasette.io\"}" > now.json + - now alias on: travis-deploy-now From 38ef2e5943d7de33e761a428c03ab9201a186153 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 13:27:40 -0700 Subject: [PATCH 07/10] Fixed failing tests caused by version_note --- tests/test_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_utils.py b/tests/test_utils.py index d12bf927..e168c3f2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -252,6 +252,7 @@ def test_temporary_docker_directory_uses_hard_link(): static=[], install=[], spatialite=False, + version_note=None, ) as temp_docker: hello = os.path.join(temp_docker, 'hello') assert 'world' == open(hello).read() @@ -278,6 +279,7 @@ def test_temporary_docker_directory_uses_copy_if_hard_link_fails(mock_link): static=[], install=[], spatialite=False, + version_note=None, ) as temp_docker: hello = os.path.join(temp_docker, 'hello') assert 'world' == open(hello).read() From 9fd1ffb613c83204b12cf1d410c206cd77913ac4 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 13:33:02 -0700 Subject: [PATCH 08/10] Include --token in calls to now alias --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index ce21590f..7eb511d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python +# 3.6 is listed first so it gets used for the later build stages python: - 3.6 - 3.5 @@ -18,7 +19,7 @@ jobs: - python tests/fixtures.py fixtures.db fixtures.json - echo '{"name":"datasette-latest","alias":"latest.datasette.io"}' > now.json - datasette publish now fixtures.db -m fixtures.json --token=$NOW_TOKEN --branch=$TRAVIS_COMMIT --version-note=$TRAVIS_COMMIT - - now alias + - now alias --token=$NOW_TOKEN - echo "{\"name\":\"datasette-latest\",\"alias\":\"$TRAVIS_COMMIT.datasette.io\"}" > now.json - - now alias + - now alias --token=$NOW_TOKEN on: travis-deploy-now From d2c873ab8c974dbd6f1558cd102917abbb0e0fd2 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 13:45:21 -0700 Subject: [PATCH 09/10] Alias is now 7 char truncated commit hash --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7eb511d8..b4a1e034 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,7 @@ jobs: - echo '{"name":"datasette-latest","alias":"latest.datasette.io"}' > now.json - datasette publish now fixtures.db -m fixtures.json --token=$NOW_TOKEN --branch=$TRAVIS_COMMIT --version-note=$TRAVIS_COMMIT - now alias --token=$NOW_TOKEN - - echo "{\"name\":\"datasette-latest\",\"alias\":\"$TRAVIS_COMMIT.datasette.io\"}" > now.json + - export ALIAS=`echo $TRAVIS_COMMIT | cut -c 1-7` + - echo "{\"name\":\"datasette-latest\",\"alias\":\"$ALIAS.datasette.io\"}" > now.json - now alias --token=$NOW_TOKEN on: travis-deploy-now From bbb874237702772210ce55eee4fb6942ca952fbc Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 17 Jun 2018 14:13:09 -0700 Subject: [PATCH 10/10] datasette package --version-note --- datasette/cli.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/datasette/cli.py b/datasette/cli.py index ddb8d4ca..ebba0244 100644 --- a/datasette/cli.py +++ b/datasette/cli.py @@ -376,6 +376,7 @@ def skeleton(files, metadata, sqlite_extensions): @click.option( "--spatialite", is_flag=True, help="Enable SpatialLite extension" ) +@click.option("--version-note", help="Additional note to show on /-/versions") @click.option("--title", help="Title for metadata") @click.option("--license", help="License label for metadata") @click.option("--license_url", help="License URL for metadata") @@ -392,6 +393,7 @@ def package( static, install, spatialite, + version_note, **extra_metadata ): "Package specified SQLite files into a new datasette Docker container" @@ -415,6 +417,7 @@ def package( static, install, spatialite, + version_note, extra_metadata, ): args = ["docker", "build"]