home / tils / til

Menu
  • GraphQL API

til: digitalocean_datasette-on-digitalocean-app-platform.md

This data as json

path topic title url body html shot created created_utc updated updated_utc shot_hash slug
digitalocean_datasette-on-digitalocean-app-platform.md digitalocean Running Datasette on DigitalOcean App Platform https://github.com/simonw/til/blob/main/digitalocean/datasette-on-digitalocean-app-platform.md [App Platform](https://www.digitalocean.com/docs/app-platform/) is the new PaaS from DigitalOcean. I figured out how to run Datasette on it. The bare minimum needed is a GitHub repository with two files: `requirements.txt` and `Procfile`. `requirements.txt` can contain a single line: ``` datasette ``` `Procfile` needs this: ``` web: datasette . -h 0.0.0.0 -p $PORT --cors ``` Your web process needs to listen on `0.0.0.0` and on the port in the `$PORT` environment variable. Connect this GitHub repository up to DigitalOcean App Platform and it will deploy the application - detecting that it's a Python application (due to the `requirements.txt` file), installing those requirements and then starting up the process in the `Procfile`. Any SQLite `.db` files that you add to the root of the GitHub repository will be automatically served by Datasette when it starts up. Because Datasette is run using `datasette .` it will also automatically pick up a `metadata.json` file or anything in custom `templates/` or `plugins/` folders, as described in [Configuration directory mode](https://docs.datasette.io/en/stable/config.html#configuration-directory-mode) in the documentation. ## Building database files I don't particularly like putting binary SQLite files in a GitHub repository - I prefer to store CSV files or SQL text files and build them into a database file as part of the deployment process. The best way I've found to do this in a DigitalOcean App is to create a `build.sh` script that builds the database, then execute it using a `Build Command`. One way to do this is to visit the "Components" tab end click "Edit" in the Commands section, then set the "Build Command" to `. build.sh`. Now any code you add to a `build.sh` script in your repo will be executed as part of the deployment. A better way (thanks, [Kamal Nasser](https://www.digitalocean.com/community/questions/configure-a-build-command-for-a-python-project-without-using-the-web-ui?comment=92105)) is to use a `bin/pre_compile` or `bin/post_compile` script in your repository. I started with a `build.sh` script that looked like this: ``` wget https://latest.datasette.io/fixtures.db ``` And this resulted in the `fixtures.db` folder being served at `/fixtures` under my app's subdomain. <p><a href="https://www.digitalocean.com/docs/app-platform/" rel="nofollow">App Platform</a> is the new PaaS from DigitalOcean. I figured out how to run Datasette on it.</p> <p>The bare minimum needed is a GitHub repository with two files: <code>requirements.txt</code> and <code>Procfile</code>.</p> <p><code>requirements.txt</code> can contain a single line:</p> <pre><code>datasette </code></pre> <p><code>Procfile</code> needs this:</p> <pre><code>web: datasette . -h 0.0.0.0 -p $PORT --cors </code></pre> <p>Your web process needs to listen on <code>0.0.0.0</code> and on the port in the <code>$PORT</code> environment variable.</p> <p>Connect this GitHub repository up to DigitalOcean App Platform and it will deploy the application - detecting that it's a Python application (due to the <code>requirements.txt</code> file), installing those requirements and then starting up the process in the <code>Procfile</code>.</p> <p>Any SQLite <code>.db</code> files that you add to the root of the GitHub repository will be automatically served by Datasette when it starts up.</p> <p>Because Datasette is run using <code>datasette .</code> it will also automatically pick up a <code>metadata.json</code> file or anything in custom <code>templates/</code> or <code>plugins/</code> folders, as described in <a href="https://docs.datasette.io/en/stable/config.html#configuration-directory-mode" rel="nofollow">Configuration directory mode</a> in the documentation.</p> <h2> <a id="user-content-building-database-files" class="anchor" href="#building-database-files" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Building database files</h2> <p>I don't particularly like putting binary SQLite files in a GitHub repository - I prefer to store CSV files or SQL text files and build them into a database file as part of the deployment process.</p> <p>The best way I've found to do this in a DigitalOcean App is to create a <code>build.sh</code> script that builds the database, then execute it using a <code>Build Command</code>.</p> <p>One way to do this is to visit the "Components" tab end click "Edit" in the Commands section, then set the "Build Command" to <code>. build.sh</code>. Now any code you add to a <code>build.sh</code> script in your repo will be executed as part of the deployment.</p> <p>A better way (thanks, <a href="https://www.digitalocean.com/community/questions/configure-a-build-command-for-a-python-project-without-using-the-web-ui?comment=92105" rel="nofollow">Kamal Nasser</a>) is to use a <code>bin/pre_compile</code> or <code>bin/post_compile</code> script in your repository.</p> <p>I started with a <code>build.sh</code> script that looked like this:</p> <pre><code>wget https://latest.datasette.io/fixtures.db </code></pre> <p>And this resulted in the <code>fixtures.db</code> folder being served at <code>/fixtures</code> under my app's subdomain.</p> <Binary: 62,729 bytes> 2020-10-06T19:45:25-07:00 2020-10-07T02:45:25+00:00 2020-10-07T07:29:46-07:00 2020-10-07T14:29:46+00:00 412787a6bcb503088eddbc6cfbd2114f datasette-on-digitalocean-app-platform
Powered by Datasette · How this site works · Code of conduct