kopia lustrzana https://github.com/simonw/datasette
Use build arguments, refs #1522
rodzic
c617e1769e
commit
a1ba6cd6bb
|
@ -5,14 +5,16 @@ RUN apk add --no-cache \
|
||||||
apache2-proxy \
|
apache2-proxy \
|
||||||
bash
|
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
|
ENV TINI_VERSION v0.18.0
|
||||||
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini
|
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini
|
||||||
RUN chmod +x /tini
|
RUN chmod +x /tini
|
||||||
|
|
||||||
# Append this to the end of the default httpd.conf file
|
# Append this to the end of the default httpd.conf file
|
||||||
RUN echo $'ServerName localhost\n\
|
RUN echo -e 'ServerName localhost\n\
|
||||||
\n\
|
\n\
|
||||||
<Proxy *>\n\
|
<Proxy *>\n\
|
||||||
Order deny,allow\n\
|
Order deny,allow\n\
|
||||||
|
@ -22,21 +24,22 @@ RUN echo $'ServerName localhost\n\
|
||||||
ProxyPass /prefix/ http://localhost:8001/\n\
|
ProxyPass /prefix/ http://localhost:8001/\n\
|
||||||
Header add X-Proxied-By "Apache2"' >> /etc/apache2/httpd.conf
|
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
|
WORKDIR /app
|
||||||
|
|
||||||
ADD https://latest.datasette.io/fixtures.db /app/fixtures.db
|
ADD https://latest.datasette.io/fixtures.db /app/fixtures.db
|
||||||
|
|
||||||
RUN echo $'#!/usr/bin/env bash\n\
|
RUN echo -e "#!/usr/bin/env bash\n\
|
||||||
set -e\n\
|
datasette /app/fixtures.db --setting base_url '/prefix/' --version-note '${DATASETTE_REF}' -h 0.0.0.0 -p 8001 &\n\
|
||||||
\n\
|
\n\
|
||||||
httpd -D FOREGROUND & \n\
|
httpd -D FOREGROUND & \n\
|
||||||
datasette fixtures.db --setting base_url "/prefix/" -h 0.0.0.0 -p 8001 &\n\
|
|
||||||
\n\
|
\n\
|
||||||
wait -n' > /app/start.sh
|
wait -n\n\
|
||||||
|
exit $?" > /app/start.sh
|
||||||
|
|
||||||
RUN chmod +x /app/start.sh
|
RUN chmod +x /app/start.sh
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
ENTRYPOINT ["/tini", "--", "/app/start.sh"]
|
|
||||||
|
CMD /tini -- /app/start.sh
|
||||||
|
|
|
@ -3,3 +3,14 @@
|
||||||
See also [Running Datasette behind a proxy](https://docs.datasette.io/en/latest/deploying.html#running-datasette-behind-a-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/
|
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/`
|
||||||
|
|
|
@ -1,13 +1,30 @@
|
||||||
#!/bin/bash
|
#!/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"
|
NAME="datasette-apache-proxy-demo"
|
||||||
PROJECT=$(gcloud config get-value project)
|
PROJECT=$(gcloud config get-value project)
|
||||||
IMAGE="gcr.io/$PROJECT/$NAME"
|
IMAGE="gcr.io/$PROJECT/$NAME"
|
||||||
|
|
||||||
gcloud builds submit --tag $IMAGE
|
# Need YAML so we can set --build-arg
|
||||||
gcloud run deploy \
|
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 \
|
--allow-unauthenticated \
|
||||||
--platform=managed \
|
--platform=managed \
|
||||||
--image $IMAGE $NAME \
|
--image $IMAGE \
|
||||||
--port 80
|
--port 80
|
||||||
|
|
Ładowanie…
Reference in New Issue