2014-09-29 20:04:40 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "ERROR: $1"
|
|
|
|
exit 2
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:30:43 +08:00
|
|
|
if [ -e /etc/apache2/envvars.orig ]; then
|
|
|
|
# On container restart we create a fresh copy of environment variables
|
|
|
|
cp -f /etc/apache2/envvars.orig /etc/apache2/envvars
|
|
|
|
else
|
|
|
|
# On a fresh start we save the original environment variables to the side
|
|
|
|
cp -f /etc/apache2/envvars /etc/apache2/envvars.orig
|
|
|
|
fi
|
|
|
|
|
2014-09-29 20:04:40 +08:00
|
|
|
[[ -z "$ENV_DOCKER_REGISTRY_HOST" ]] && die "Missing environment variable: ENV_DOCKER_REGISTRY_HOST=url-to-your-registry"
|
|
|
|
[[ -z "$ENV_DOCKER_REGISTRY_PORT" ]] && ENV_DOCKER_REGISTRY_PORT=80
|
2015-01-02 18:16:44 +08:00
|
|
|
[[ -z "$ENV_REGISTRY_PROXY_FQDN" ]] && ENV_REGISTRY_PROXY_FQDN=$ENV_DOCKER_REGISTRY_HOST
|
|
|
|
[[ -z "$ENV_REGISTRY_PROXY_PORT" ]] && ENV_REGISTRY_PROXY_PORT=$ENV_DOCKER_REGISTRY_PORT
|
2014-09-29 20:04:40 +08:00
|
|
|
|
|
|
|
echo "export DOCKER_REGISTRY_HOST=$ENV_DOCKER_REGISTRY_HOST" >> /etc/apache2/envvars
|
|
|
|
echo "export DOCKER_REGISTRY_PORT=$ENV_DOCKER_REGISTRY_PORT" >> /etc/apache2/envvars
|
2015-01-02 18:16:44 +08:00
|
|
|
echo "export REGISTRY_PROXY_FQDN=$ENV_REGISTRY_PROXY_FQDN" >> /etc/apache2/envvars
|
|
|
|
echo "export REGISTRY_PROXY_PORT=$ENV_REGISTRY_PROXY_PORT" >> /etc/apache2/envvars
|
2014-09-29 20:04:40 +08:00
|
|
|
|
2014-11-15 09:04:56 +08:00
|
|
|
needModSsl=0
|
2014-11-15 03:27:19 +08:00
|
|
|
if [ -n "$ENV_DOCKER_REGISTRY_USE_SSL" ]; then
|
2014-11-15 09:04:56 +08:00
|
|
|
echo "export DOCKER_REGISTRY_SCHEME=https" >> /etc/apache2/envvars
|
|
|
|
needModSsl=1
|
2014-11-15 03:27:19 +08:00
|
|
|
else
|
2014-11-15 09:04:56 +08:00
|
|
|
echo "export DOCKER_REGISTRY_SCHEME=http" >> /etc/apache2/envvars
|
2014-11-15 03:27:19 +08:00
|
|
|
fi
|
|
|
|
|
2015-01-02 18:16:44 +08:00
|
|
|
# docker-registry-frontend acts as a proxy so may well
|
|
|
|
# have a different hostname than the registry itself.
|
|
|
|
echo "{\"host\": \"$ENV_REGISTRY_PROXY_FQDN\", \"port\": $ENV_REGISTRY_PROXY_PORT}" > /var/www/html/registry-host.json
|
2014-09-29 20:04:40 +08:00
|
|
|
|
2014-12-11 18:09:35 +08:00
|
|
|
# information about browse mode.
|
2014-12-16 18:55:10 +08:00
|
|
|
[[ x$ENV_MODE_BROWSE_ONLY =~ ^x(true|false)$ ]] || ENV_MODE_BROWSE_ONLY=false
|
2015-02-04 20:10:26 +08:00
|
|
|
echo "{\"browseOnly\":$ENV_MODE_BROWSE_ONLY}" > /var/www/html/app-mode.json
|
2015-02-13 18:34:29 +08:00
|
|
|
if [ "$ENV_MODE_BROWSE_ONLY" == "true" ]; then
|
|
|
|
echo "export APACHE_ARGUMENTS='-D FRONTEND_BROWSE_ONLY_MODE'" >> /etc/apache2/envvars
|
|
|
|
fi
|
2014-12-11 18:09:35 +08:00
|
|
|
|
2014-09-29 20:04:40 +08:00
|
|
|
# Optionally enable Kerberos authentication and do some parameter checks
|
|
|
|
if [ -n "$ENV_AUTH_USE_KERBEROS" ]; then
|
|
|
|
|
|
|
|
[[ -z "$ENV_AUTH_NAME" ]] && die "Missing environment variable for Kerberos: ENV_AUTH_NAME"
|
|
|
|
[[ -z "$ENV_AUTH_KRB5_KEYTAB" ]] && die "Missing environment variable for Kerberos: ENV_AUTH_KRB5_KEYTAB"
|
|
|
|
[[ -z "$ENV_AUTH_KRB_REALMS" ]] && die "Missing environment variable for Kerberos: ENV_AUTH_KRB_REALMS"
|
|
|
|
[[ -z "$ENV_AUTH_KRB_SERVICE_NAME" ]] && die "Missing environment variable for Kerberos: ENV_AUTH_KRB_SERVICE_NAME"
|
|
|
|
|
|
|
|
a2enmod auth_kerb
|
|
|
|
|
|
|
|
echo "export USE_KERBEROS_AUTH=$ENV_AUTH_USE_KERBEROS" >> /etc/apache2/envvars
|
|
|
|
echo "export AUTH_NAME=\"$ENV_AUTH_NAME\"" >> /etc/apache2/envvars
|
|
|
|
echo "export AUTH_KRB5_KEYTAB=$ENV_AUTH_KRB5_KEYTAB" >> /etc/apache2/envvars
|
|
|
|
echo "export AUTH_KRB_REALMS=$ENV_AUTH_KRB_REALMS" >> /etc/apache2/envvars
|
|
|
|
echo "export AUTH_KRB_SERVICE_NAME=$ENV_AUTH_KRB_SERVICE_NAME" >> /etc/apache2/envvars
|
|
|
|
else
|
|
|
|
a2dismod auth_kerb
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Optionally enable SSL
|
|
|
|
if [ -n "$ENV_USE_SSL" ]; then
|
2014-11-15 09:04:56 +08:00
|
|
|
useSsl="-D USE_SSL"
|
2014-09-29 20:04:40 +08:00
|
|
|
|
|
|
|
[[ ! -e /etc/apache2/server.crt ]] && die "/etc/apache2/server.crt is missing"
|
|
|
|
[[ ! -e /etc/apache2/server.key ]] && die "/etc/apache2/server.key is missing"
|
2014-11-15 09:04:56 +08:00
|
|
|
needModSsl=1
|
|
|
|
fi
|
2014-09-29 20:04:40 +08:00
|
|
|
|
2014-11-15 09:04:56 +08:00
|
|
|
if [ $needModSsl -ne 0 ]; then
|
2014-09-29 20:04:40 +08:00
|
|
|
a2enmod ssl
|
|
|
|
else
|
|
|
|
a2dismod ssl
|
|
|
|
fi
|
|
|
|
|
2015-03-25 19:30:43 +08:00
|
|
|
# Stop apache first if is still running from the last time the container was run
|
|
|
|
service apache2 stop
|
|
|
|
|
2014-11-15 09:04:56 +08:00
|
|
|
/usr/sbin/apache2ctl -D FOREGROUND ${useSsl}
|