Skip to content

Commit

Permalink
Use build arguments, refs #1522
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Nov 20, 2021
1 parent c617e17 commit a1ba6cd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 17 deletions.
23 changes: 13 additions & 10 deletions demos/apache-proxy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,41 @@ RUN apk add --no-cache \
apache2-proxy \
bash

RUN pip install datasette
ARG DATASETTE_REF

RUN pip install https://github.com/simonw/datasette/archive/${DATASETTE_REF}.zip

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\
RUN echo -e 'ServerName localhost\n\
\n\
<Proxy *>\n\
Order deny,allow\n\
Allow from all\n\
</Proxy>\n\
\n\
ProxyPass /prefix/ http://localhost:8001/\n\
ProxyPass /prefix/ http://localhost:8001/\n\
Header add X-Proxied-By "Apache2"' >> /etc/apache2/httpd.conf

RUN echo $'<a href="/prefix/">Datasette</a>' > /var/www/localhost/htdocs/index.html
RUN echo '<a href="/prefix/">Datasette</a>' > /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\
RUN echo -e "#!/usr/bin/env bash\n\
datasette /app/fixtures.db --setting base_url '/prefix/' --version-note '${DATASETTE_REF}' -h 0.0.0.0 -p 8001 &\n\
\n\
httpd -D FOREGROUND &\n\
datasette fixtures.db --setting base_url "/prefix/" -h 0.0.0.0 -p 8001 &\n\
httpd -D FOREGROUND & \n\
\n\
wait -n' > /app/start.sh
wait -n\n\
exit $?" > /app/start.sh

RUN chmod +x /app/start.sh

EXPOSE 80
ENTRYPOINT ["/tini", "--", "/app/start.sh"]

CMD /tini -- /app/start.sh
11 changes: 11 additions & 0 deletions demos/apache-proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,14 @@
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/

To build locally, passing in a Datasette commit hash (or `main` for the main branch):

docker build -t datasette-apache-proxy-demo . \
--build-arg DATASETTE_REF=c617e1769ea27e045b0f2907ef49a9a1244e577d

Then run it like this:

docker run -p 5000:80 datasette-apache-proxy-demo

And visit `http://localhost:5000/` or `http://localhost:5000/prefix/`
31 changes: 24 additions & 7 deletions demos/apache-proxy/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
#!/bin/bash
# https://til.simonwillison.net/cloudrun/ship-dockerfile-to-cloud-run
# https://til.simonwillison.net/cloudrun/using-build-args-with-cloud-run

if [[ -z "$DATASETTE_REF" ]]; then
echo "Must provide DATASETTE_REF environment variable" 1>&2
exit 1
fi

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
# Need YAML so we can set --build-arg
echo "
steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', '$IMAGE', '.', '--build-arg', 'DATASETTE_REF=$DATASETTE_REF']
- name: 'gcr.io/cloud-builders/docker'
args: ['push', '$IMAGE']
" > /tmp/cloudbuild.yml

gcloud builds submit --config /tmp/cloudbuild.yml

rm /tmp/cloudbuild.yml

gcloud run deploy $NAME \
--allow-unauthenticated \
--platform=managed \
--image $IMAGE \
--port 80

0 comments on commit a1ba6cd

Please sign in to comment.