Skip to content

Fix permissions using entrypoint scripts #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" ]