...
 
Commits (10)
......@@ -2,4 +2,5 @@ apache-logs/
certbot-logs/
vhosts/
certs/
static/
laststart.var
......@@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.4.0] - 2018-11-21
### Added
- Static folder Apache can serve directly (bind mount from host)
- Auto mount of web_static_* volumes at startup
### Changed
- The start command applies the last start parameters if it finds them and if no env var is supplied
## [1.3.0] - 2018-06-26
### Added
......
......@@ -63,11 +63,19 @@ Be sure you have no other program listening to the ports 80 and 443. To launch t
```
# ./start
```
By default all important data go to the SLARP installation directory. However you can adjust the values of 4 environment variables before starting: `VHOSTS_DIR`, `CERTS_DIR`, `APACHE_LOGS_DIR` and `CERTBOT_LOGS_DIR`. For example
By default all important data go to the SLARP installation directory. However you can adjust the values of these environment variables before starting: `VHOSTS_DIR`, `CERTS_DIR`, `APACHE_LOGS_DIR` and `CERTBOT_LOGS_DIR`.
Additionnally, you can use `STATIC_DIR` to define which path of your host will be mounted (read-only) into `/var/www/static` in the container. By default it uses the `static` directory in the SLARP installation directory. This bind mount is useful if you want to define vhosts that serve static files of your host.
If a directory does not exist, the start command creates it. In particular, a first start without using these environment variables will create all directories in your SLARP location.
For example
```
# VHOSTS_DIR=/path/to/your/vhosts CERTS_DIR=/path/to/your/certificates ./start
```
runs the service with a customized location for the *vhosts* and the *certs*, but still keeps logs where SLARP is installed.
runs the service with a customized location for the *vhosts* and the *certs*, but still keeps logs where SLARP is installed. Also, if you want to serve static contents, put your files into `/your-slarp-installation/static`.
The current in-use parameters (default or user-defined) are written in `laststart.var` at startup, so you don't need to redefine them by setting environment variables each time you restart SLARP, because the start command checks this file. Instead of using env vars on the start command line you could edit `laststart.var` like a classic configuration file, however don't modify it while SLARP is running because some commands could not work properly.
If you have docker volumes whose name start with "web_static_*", the start command mounts them into `/var/www/static_*`. This feature is an alternative to the bind mount of the `static` folder, and is designed to serve directly the static data your backend containers are likely to share. For exemple, if you have a "web_static_searx" volume (let's say it's created as you start a "searx" container), this volume is mounted into `/var/www/static_searx` in the reverse proxy container.
Now a container named "slarp-reverse-proxy" is running, but for now it has nothing to forward.
......
......@@ -4,7 +4,7 @@ FROM $BASE_IMAGE
LABEL maintainer="zareldyn" \
description="A simple HTTP(S) reverse proxy based on Apache and Let's Encrypt."
ENV SLARP_VERSION="1.3.0"
ENV SLARP_VERSION="1.4.0"
RUN ["/bin/bash", "-c", " \
apt-get update && \
......
......@@ -8,12 +8,26 @@ APP_VARFILE="$SELF_DIR/laststart.var"
exit
}
function get_laststart_var {
if [ ! -r "$APP_VARFILE" ] || [ ! -f "$APP_VARFILE" ]; then
echo ""
return
fi
grep $1 "$APP_VARFILE" | cut -d= -f2
}
[ -z "$CERTS_DIR" ] && CERTS_DIR=$(get_laststart_var CERTS_DIR)
[ -z "$CERTS_DIR" ] && CERTS_DIR="$SELF_DIR"/certs
[ -z "$VHOSTS_DIR" ] && VHOSTS_DIR=$(get_laststart_var VHOSTS_DIR)
[ -z "$VHOSTS_DIR" ] && VHOSTS_DIR="$SELF_DIR"/vhosts
[ -z "$APACHE_LOGS_DIR" ] && APACHE_LOGS_DIR=$(get_laststart_var APACHE_LOGS_DIR)
[ -z "$APACHE_LOGS_DIR" ] && APACHE_LOGS_DIR="$SELF_DIR"/apache-logs
[ -z "$CERTBOT_LOGS_DIR" ] && CERTBOT_LOGS_DIR=$(get_laststart_var CERTBOT_LOGS_DIR)
[ -z "$CERTBOT_LOGS_DIR" ] && CERTBOT_LOGS_DIR="$SELF_DIR"/certbot-logs
[ -z "$STATIC_DIR" ] && STATIC_DIR=$(get_laststart_var STATIC_DIR)
[ -z "$STATIC_DIR" ] && STATIC_DIR="$SELF_DIR"/static
for dir in "$CERTS_DIR" "$VHOSTS_DIR" "$APACHE_LOGS_DIR" "$CERTBOT_LOGS_DIR"; do
for dir in "$CERTS_DIR" "$VHOSTS_DIR" "$APACHE_LOGS_DIR" "$CERTBOT_LOGS_DIR" "$STATIC_DIR"; do
mkdir -p "$dir" || {
echo "Could not create $dir - aborting" >&2
exit 74
......@@ -27,6 +41,13 @@ echo CERTS_DIR="$CERTS_DIR" > "$APP_VARFILE" || {
echo VHOSTS_DIR="$VHOSTS_DIR" >> "$APP_VARFILE"
echo APACHE_LOGS_DIR="$APACHE_LOGS_DIR" >> "$APP_VARFILE"
echo CERTBOT_LOGS_DIR="$CERTBOT_LOGS_DIR" >> "$APP_VARFILE"
echo STATIC_DIR="$STATIC_DIR" >> "$APP_VARFILE"
volumes=($(docker volume ls -q | grep ^web_static_ | cut -d_ -f3))
mountCommand=''
for name in ${volumes[@]}; do
mountCommand="$mountCommand -v web_static_$name:/var/www/static_$name:ro"
done
docker run -d --restart on-failure \
--name $APP_NAME \
......@@ -35,6 +56,8 @@ docker run -d --restart on-failure \
-v "$VHOSTS_DIR":/etc/apache2/sites-enabled \
-v "$APACHE_LOGS_DIR":/var/log/apache2 \
-v "$CERTBOT_LOGS_DIR":/var/log/letsencrypt \
-v "$STATIC_DIR":/var/www/static:ro \
$mountCommand \
-p 80:80 -p 443:443 \
$APP_NAME:latest bash -c \
"cron &&
......