kopia lustrzana https://github.com/simonw/datasette
rodzic
7d81083d40
commit
65e350ca2a
|
@ -1,7 +0,0 @@
|
|||
FROM python:3
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
RUN pip install .
|
||||
RUN datasite build
|
||||
EXPOSE 8006
|
||||
CMD ["datasite", "serve", "--port", "8006"]
|
|
@ -1,6 +1,10 @@
|
|||
import click
|
||||
from click_default_group import DefaultGroup
|
||||
import os
|
||||
from subprocess import call
|
||||
import tempfile
|
||||
from .app import Datasette, ensure_build_metadata
|
||||
from .utils import make_dockerfile
|
||||
|
||||
|
||||
@click.group(cls=DefaultGroup, default='serve', default_if_no_args=True)
|
||||
|
@ -16,6 +20,30 @@ def build(files):
|
|||
ensure_build_metadata(files, True)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument('files', type=click.Path(exists=True), nargs=-1)
|
||||
def publish(files):
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
# We create a datasette folder in there to get a nicer now deploy name
|
||||
datasette_dir = os.path.join(tmp.name, 'datasette')
|
||||
os.mkdir(datasette_dir)
|
||||
saved_cwd = os.getcwd()
|
||||
file_paths = [
|
||||
os.path.join(saved_cwd, name)
|
||||
for name in files
|
||||
]
|
||||
try:
|
||||
dockerfile = make_dockerfile(files)
|
||||
os.chdir(datasette_dir)
|
||||
open('Dockerfile', 'w').write(dockerfile)
|
||||
for path, filename in zip(file_paths, files):
|
||||
os.link(path, os.path.join(datasette_dir, filename))
|
||||
call('now')
|
||||
finally:
|
||||
tmp.cleanup()
|
||||
os.chdir(saved_cwd)
|
||||
|
||||
|
||||
@cli.command()
|
||||
@click.argument('files', type=click.Path(exists=True), nargs=-1)
|
||||
@click.option('-h', '--host', default='0.0.0.0')
|
||||
|
|
|
@ -115,3 +115,17 @@ _css_re = re.compile(r'''['"\n\\]''')
|
|||
|
||||
def escape_css_string(s):
|
||||
return _css_re.sub(lambda m: '\\{:X}'.format(ord(m.group())), s)
|
||||
|
||||
|
||||
def make_dockerfile(files):
|
||||
return '''
|
||||
FROM python:3
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
RUN pip install https://static.simonwillison.net/static/2017/datasette-0.1-py3-none-any.whl
|
||||
RUN datasette build {}
|
||||
EXPOSE 8006
|
||||
CMD ["datasette", "serve", {}, "--port", "8006"]'''.format(
|
||||
' '.join(files),
|
||||
'"' + '", "'.join(files) + '"',
|
||||
).strip()
|
||||
|
|
Ładowanie…
Reference in New Issue