preview.sh: Allow preview.sh keep running for multiple build.sh calls

antora deletes and recreates public/ every time the docs are rebuilt;
mounting public/ directly meant that when build.sh, the existing nginx
container didn't see the new docs. Instead of mounting public/ directly
into the nginx default webroot, mount the parent directory at /antora,
and install a tiny nginx configuration file to point the webroot at the
right place.
This commit is contained in:
Owen W. Taylor 2018-09-04 10:57:29 -04:00
parent b058593d87
commit 670c91f96a
2 changed files with 16 additions and 2 deletions

14
nginx.conf Normal file
View file

@ -0,0 +1,14 @@
server {
listen 80;
server_name localhost;
location / {
root /antora/public;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

View file

@ -5,7 +5,7 @@ if [ "$(uname)" == "Darwin" ]; then
# Let's assume that the user has the Docker CE installed
# which doesn't require a root password.
echo "The preview will be available at http://localhost:8080/"
docker run --rm -v $(pwd)/public:/usr/share/nginx/html:ro -p 8080:80 nginx
docker run --rm -v $(pwd):/antora:ro -p 8080:80 nginx
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
# Running on Linux.
@ -14,5 +14,5 @@ elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
echo ""
echo "This build script is using Docker to run the build in an isolated environment. You might be asked for a root password in order to start it."
echo "The preview will be available at http://localhost:8080/"
sudo docker run --rm -v $(pwd)/public:/usr/share/nginx/html:ro -p 8080:80 nginx
sudo docker run --rm -v $(pwd):/antora:ro,z -v $(pwd)/nginx.conf:/etc/nginx/conf.d/default.conf:ro,z -p 8080:80 nginx
fi