From c76bbd40664f789c45564b7796628e5110cd3b17 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Fri, 19 Nov 2021 14:50:06 -0800 Subject: [PATCH] New live demo with Apache proxying, refs #1522 --- demos/apache-proxy/Dockerfile | 42 +++++++++++++++++++++++++++++++++++ demos/apache-proxy/README.md | 5 +++++ demos/apache-proxy/deploy.sh | 13 +++++++++++ 3 files changed, 60 insertions(+) create mode 100644 demos/apache-proxy/Dockerfile create mode 100644 demos/apache-proxy/README.md create mode 100755 demos/apache-proxy/deploy.sh diff --git a/demos/apache-proxy/Dockerfile b/demos/apache-proxy/Dockerfile new file mode 100644 index 0000000000..2956f913f3 --- /dev/null +++ b/demos/apache-proxy/Dockerfile @@ -0,0 +1,42 @@ +FROM python:3-alpine + +RUN apk add --no-cache \ + apache2 \ + apache2-proxy \ + bash + +RUN pip install datasette + +ENV TINI_VERSION v0.18.0 +ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini +RUN chmod +x /tini + +# Append this to the end of the default httpd.conf file +RUN echo $'ServerName localhost\n\ +\n\ +\n\ + Order deny,allow\n\ + Allow from all\n\ +\n\ +\n\ +ProxyPass /prefix/ http://localhost:8001/\n\ +Header add X-Proxied-By "Apache2"' >> /etc/apache2/httpd.conf + +RUN echo $'Datasette' > /var/www/localhost/htdocs/index.html + +WORKDIR /app + +ADD https://latest.datasette.io/fixtures.db /app/fixtures.db + +RUN echo $'#!/usr/bin/env bash\n\ +set -e\n\ +\n\ +httpd -D FOREGROUND &\n\ +datasette fixtures.db --setting base_url "/prefix/" -h 0.0.0.0 -p 8001 &\n\ +\n\ +wait -n' > /app/start.sh + +RUN chmod +x /app/start.sh + +EXPOSE 80 +ENTRYPOINT ["/tini", "--", "/app/start.sh"] diff --git a/demos/apache-proxy/README.md b/demos/apache-proxy/README.md new file mode 100644 index 0000000000..9bd3897cac --- /dev/null +++ b/demos/apache-proxy/README.md @@ -0,0 +1,5 @@ +# Datasette running behind an Apache proxy + +See also [Running Datasette behind a proxy](https://docs.datasette.io/en/latest/deploying.html#running-datasette-behind-a-proxy) + +This live demo is running at https://apache-proxy-demo.datasette.io/ diff --git a/demos/apache-proxy/deploy.sh b/demos/apache-proxy/deploy.sh new file mode 100755 index 0000000000..ae33941c71 --- /dev/null +++ b/demos/apache-proxy/deploy.sh @@ -0,0 +1,13 @@ +#!/bin/bash +# https://til.simonwillison.net/cloudrun/ship-dockerfile-to-cloud-run + +NAME="datasette-apache-proxy-demo" +PROJECT=$(gcloud config get-value project) +IMAGE="gcr.io/$PROJECT/$NAME" + +gcloud builds submit --tag $IMAGE +gcloud run deploy \ + --allow-unauthenticated \ + --platform=managed \ + --image $IMAGE $NAME \ + --port 80