Skip to content

Commit

Permalink
Merge pull request #9 from ipunkt/reown-storage-environment
Browse files Browse the repository at this point in the history
Reown storage environment
  • Loading branch information
Sven Speckmaier authored Sep 7, 2017
2 parents 2a3681b + a181ac2 commit 31f3015
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ PHP Configuration value: php_admin_value\[memory\_limit\]
PHP Configuration value: php_admin_value\[post\_max\_size\]
### PHP_UPLOAD_MAX_FILESIZE
PHP Configuration value: php_admin_value\[upload\_max\_filesize\]
### INITSCRIPT
Path to a script that is run the first time the container is started
Uses the file /var/init.lock to track having been run
Defaults to `/var/www/app/init.sh`
### STARTSCRIPT
Path to a script that is run each time the container is started
Defaults to `/var/www/app/start.sh`

## Available includes

Expand Down
2 changes: 1 addition & 1 deletion debug/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ipunktbs/nginx:1.10.2-7-1.3.0
FROM ipunktbs/nginx:1.10.2-7-1.3.1
RUN apt-get update && apt-get -y install php7.0-xdebug \
&& rm -Rf /var/lib/apt/lists \
&& mkdir -p /opt/profiling ; chmod 777 /opt/profiling
Expand Down
56 changes: 54 additions & 2 deletions start.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/bin/sh

INITLOCK="/var/init.lock"
APPPATH="/var/www/app"

if [ -z "$INITSCRIPT" ] ; then
INITSCRIPT="$APPPATH/init.sh"
fi
if [ -z "$STARTSCRIPT" ] ; then
STARTSCRIPT="$APPPATH/start.sh"
fi

USER="www-data"
if [ ! -z "$USER_ID" -a ! -z "$GROUP_ID" ] ; then
echo "Switching to user"
Expand Down Expand Up @@ -50,8 +58,19 @@ sed \
-e "s/%%PHP_UPLOAD_MAX_FILESIZE%%/$PHP_UPLOAD_MAX_FILESIZE/" \
/opt/config/www.conf.tpl > /etc/php/7.0/fpm/pool.d/www.conf

for STORAGE in "${APPPATH}/storage" "${APPPATH}/app/storage" \
"${APPPATH}/bootstrap/cache" ; do
###############################################################################
# ensure the storage is writable by changing its user to the one running nginx
# and php-fpm
#
# Environment: STORAGE_REOWN_MODE decides how this is done
# - default / empty: Start the changing process int he foreground
# - background: Start the changing process in the background
# - none: Do nont change the ownership of the storage
###############################################################################
own_storage() {
echo Started reowning storage
for STORAGE in "${APPPATH}/storage" "${APPPATH}/app/storage" \
"${APPPATH}/bootstrap/cache" ; do
if [ -d $STORAGE ] ; then
echo Making $STORAGE writable
#chmod -R 777 $STORAGE
Expand All @@ -60,6 +79,20 @@ for STORAGE in "${APPPATH}/storage" "${APPPATH}/app/storage" \
echo Storage $STORAGE not found
fi
done
echo Finished reowning storage
}

case "$STORAGE_REOWN_MODE" in
background)
own_storage &
;;
none)
echo "Not reonwing storage."
;;
*)
own_storage
;;
esac

if [ x"$SERVER_URL" = x"" ] ; then
SERVER_URL=localhost
Expand Down Expand Up @@ -123,6 +156,24 @@ if [ -z "$NO_FPM" ] ; then
/etc/init.d/php7.0-fpm start
fi

#
# Run INITSCRIPT if the file $INITLOCK does not exist yet.
# - Then create $INITLOCK
# -> Should only be run once per container.
#
if [ ! -f "$INITLOCK" ] ; then

if [ -f "$INITSCRIPT" ] ; then
$INITSCRIPT
fi

echo "The existance of this files prevents the INITSCRIPT to be run." > "$INITLOCK"
fi

if [ -f "$STARTSCRIPT" ] ; then
$STARTSCRIPT
fi

echo Starting NGINX
nginx -g "daemon off;" &

Expand All @@ -143,6 +194,7 @@ else
echo "Artisan not found at $ARTISAN: skipping migrate and seed"
fi


echo "Entering main-wait for the webserver"
wait

Expand Down

0 comments on commit 31f3015

Please sign in to comment.