Skip to content

Commit

Permalink
Fix permissions using entrypoint scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ckulka committed Sep 26, 2022
1 parent 6a10cd0 commit e3ddbd8
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 72 deletions.
10 changes: 5 additions & 5 deletions apache-php8.0.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ LABEL repository="https://github.com/ckulka/baikal-docker"
LABEL website="http://sabre.io/baikal/"

# Install Baikal and required dependencies
RUN mkdir -p /usr/src/baikal
COPY --from=builder baikal /usr/src/baikal

COPY --from=builder --chown=www-data:www-data baikal /var/www/baikal
RUN apt-get update &&\
apt-get install -y libcurl4-openssl-dev sendmail &&\
rm -rf /var/lib/apt/lists/* &&\
Expand All @@ -32,5 +30,7 @@ EXPOSE 443
VOLUME /var/www/baikal/config
VOLUME /var/www/baikal/Specific

COPY files/start.sh /opt
ENTRYPOINT [ "sh", "/opt/start.sh", "apache" ]
COPY files/docker-entrypoint.sh /docker-entrypoint.sh
COPY files/40-*.sh /docker-entrypoint.d/
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "apache2-foreground" ]
10 changes: 5 additions & 5 deletions apache.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ LABEL repository="https://github.com/ckulka/baikal-docker"
LABEL website="http://sabre.io/baikal/"

# Install Baikal and required dependencies
RUN mkdir -p /usr/src/baikal
COPY --from=builder baikal /usr/src/baikal

COPY --from=builder --chown=www-data:www-data baikal /var/www/baikal
RUN apt-get update &&\
apt-get install -y libcurl4-openssl-dev sendmail &&\
rm -rf /var/lib/apt/lists/* &&\
Expand All @@ -32,5 +30,7 @@ EXPOSE 443
VOLUME /var/www/baikal/config
VOLUME /var/www/baikal/Specific

COPY files/start.sh /opt
ENTRYPOINT [ "sh", "/opt/start.sh", "apache" ]
COPY files/docker-entrypoint.sh /docker-entrypoint.sh
COPY files/40-*.sh /docker-entrypoint.d/
ENTRYPOINT [ "/docker-entrypoint.sh" ]
CMD [ "apache2-foreground" ]
36 changes: 36 additions & 0 deletions files/40-fix-baikal-permissions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

set -e
ME=$(basename $0)

if ! [ -d /var/www/baikal/Specific/db ]
then
echo >&3 "$ME: info: Creating new Baikal database folder"
mkdir -p /var/www/baikal/Specific/db
fi

# Detect if we're running in the Apache httpd image
if [ ! -z ${APACHE_CONFDIR+x} ]
then
echo >&3 "$ME: info: Adjusting Baikal file permissions for Apache httpd"
chown -R www-data:www-data /var/www/baikal

# Inject ServerName and ServerAlias if specified
APACHE_CONFIG="/etc/apache2/sites-available/000-default.conf"
if [ ! -z ${BAIKAL_SERVERNAME+x} ]
then
sed -i "s/# InjectedServerName .*/ServerName $BAIKAL_SERVERNAME/g" $APACHE_CONFIG
fi

if [ ! -z ${BAIKAL_SERVERALIAS+x} ]
then
sed -i "s/# InjectedServerAlias .*/ServerAlias $BAIKAL_SERVERALIAS/g" $APACHE_CONFIG
fi
fi

# Detect if we're running in the nginx image
if [ ! -z ${NGINX_VERSION+x} ]
then
echo >&3 "$ME: info: Adjusting Baikal file permissions for nginx"
chown -R nginx:nginx /var/www/baikal
fi
13 changes: 13 additions & 0 deletions files/40-php-fpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

set -e
ME=$(basename $0)

# Start PHP FPM if it exists
if [ -f "/etc/init.d/php8.0-fpm" ]; then
echo >&3 "$ME: info: Starting PHP 8.0"
/etc/init.d/php8.0-fpm start
elif [ -f "/etc/init.d/php8.1-fpm" ]; then
echo >&3 "$ME: info: Starting PHP 8.1"
/etc/init.d/php8.1-fpm start
fi
43 changes: 43 additions & 0 deletions files/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/sh

# Based on /etc/docker-entrypoint.sh in nginx image

set -e

if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
exec 3>&1
else
exec 3>/dev/null
fi

# Run the scripts in /docker-entrypoint.d if we're starting either Apache httpd or nginx
if [ "$1" = "nginx" -o "$1" = "nginx-debug" -o "$1" = "apache2-foreground" ]
then
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v
then
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f
do
case "$f" in
*.sh)
if [ -x "$f" ]
then
echo >&3 "$0: Launching $f";
"$f"
else
# warn on shell scripts without exec bit
echo >&3 "$0: Ignoring $f, not executable";
fi
;;
*) echo >&3 "$0: Ignoring $f";;
esac
done

echo >&3 "$0: Configuration complete; ready for start up"
else
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
fi
fi

exec "$@"
48 changes: 0 additions & 48 deletions files/start.sh

This file was deleted.

9 changes: 2 additions & 7 deletions nginx-php8.0.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ LABEL repository="https://github.com/ckulka/baikal-docker"
LABEL website="http://sabre.io/baikal/"

# Install dependencies: PHP (with libffi6 dependency) & SQLite3
RUN mkdir -p /usr/src/baikal
COPY --from=builder baikal /usr/src/baikal

RUN curl -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg &&\
apt update &&\
apt install -y lsb-release &&\
Expand All @@ -38,11 +35,9 @@ RUN curl -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sed -i 's/^listen = .*/listen = \/var\/run\/php-fpm.sock/' /etc/php/8.0/fpm/pool.d/www.conf

# Add Baikal & nginx configuration
COPY files/40-*.sh /docker-entrypoint.d/
COPY files/nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=builder --chown=nginx:nginx baikal /var/www/baikal

VOLUME /var/www/baikal/config
VOLUME /var/www/baikal/Specific

COPY files/start.sh /opt
ENTRYPOINT [ "sh", "/opt/start.sh", "nginx-php8.0" ]

9 changes: 2 additions & 7 deletions nginx.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ LABEL repository="https://github.com/ckulka/baikal-docker"
LABEL website="http://sabre.io/baikal/"

# Install dependencies: PHP (with libffi6 dependency) & SQLite3
RUN mkdir -p /usr/src/baikal
COPY --from=builder baikal /usr/src/baikal

RUN curl -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg &&\
apt update &&\
apt install -y lsb-release &&\
Expand All @@ -38,11 +35,9 @@ RUN curl -o /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
sed -i 's/^listen = .*/listen = \/var\/run\/php-fpm.sock/' /etc/php/8.1/fpm/pool.d/www.conf

# Add Baikal & nginx configuration
COPY files/40-*.sh /docker-entrypoint.d/
COPY --from=builder --chown=nginx:nginx baikal /var/www/baikal
COPY files/nginx.conf /etc/nginx/conf.d/default.conf

VOLUME /var/www/baikal/config
VOLUME /var/www/baikal/Specific

COPY files/start.sh /opt
ENTRYPOINT [ "sh", "/opt/start.sh", "nginx" ]

0 comments on commit e3ddbd8

Please sign in to comment.