Skip to content

Commit

Permalink
Use two init levels for startup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cytopia committed Dec 28, 2018
1 parent 3926ee7 commit 452269c
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Dockerfiles/prod/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ disable_modules "DISABLE_MODULES" "${DEBUG_LEVEL}"
###
### Run custom user supplied scripts
###
execute_custom_scripts "/startup.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.1.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.2.d" "${DEBUG_LEVEL}"


###
Expand Down
3 changes: 2 additions & 1 deletion Dockerfiles/work/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ update_ca_certificates "/ca" "${DEBUG_LEVEL}"
###
### Run custom user supplied scripts
###
execute_custom_scripts "/startup.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.1.d" "${DEBUG_LEVEL}"
execute_custom_scripts "/startup.2.d" "${DEBUG_LEVEL}"


###
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ Have a look at the following table to see all offered volumes for each Docker im
</thead>
<tbody>
<tr>
<td rowspan="6"><strong>prod</strong><br/><br/><strong>work</strong></td>
<td rowspan="7"><strong>prod</strong><br/><br/><strong>work</strong></td>
<td><code>/etc/php-custom.d</code></td>
<td>Mount this directory into your host computer and add custom <code>\*.ini</code> files in order to alter php behaviour.</td>
</tr>
Expand All @@ -773,8 +773,12 @@ Have a look at the following table to see all offered volumes for each Docker im
<td>Mount this directory into your host computer and add custo <code>\*.so</code> files in order to add your php modules.<br/><br/><strong>Note:</strong>Your should then also provide a custom <code>\*.ini</code> file in order to actually load your custom provided module.</td>
</tr>
<tr>
<td><code>/startup.d</code></td>
<td>Any executable scripts ending by <code>\*.sh</code> found in this directory will be executed during startup. This is useful to supply additional commands (such as installing custom software) when the container starts up.</td>
<td><code>/startup.1.d</code></td>
<td>Any executable scripts ending by <code>\*.sh</code> found in this directory will be executed during startup. This is useful to supply additional commands (such as installing custom software) when the container starts up. (will run before <code>/startup.2.d</code>)</td>
</tr>
<tr>
<td><code>/startup.2.d</code></td>
<td>Any executable scripts ending by <code>\*.sh</code> found in this directory will be executed during startup. This is useful to supply additional commands (such as installing custom software) when the container starts up. (will run after <code>/startup.1.d</code>)</td>
</tr>
<tr>
<td><code>/var/log/php</code></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ FLAVOUR="${3}"
### Check if PHP still starts up with working scripts
###
RUN_SH_HOST="$( mktemp -d )"
RUN_SH_CONT="/startup.d"
RUN_SH_CONT="/startup.1.d"

# Fix mount permissions
chmod 0777 "${RUN_SH_HOST}"
Expand Down
62 changes: 62 additions & 0 deletions tests/prod/09-test-custom-user-scripts-2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

set -e
set -u
set -o pipefail

CWD="$(cd -P -- "$(dirname -- "$0")" && pwd -P)"

IMAGE="${1}"
VERSION="${2}"
FLAVOUR="${3}"

# shellcheck disable=SC1090
. "${CWD}/../.lib.sh"



############################################################
# Tests
############################################################

###
### Check if PHP still starts up with working scripts
###
RUN_SH_HOST="$( mktemp -d )"
RUN_SH_CONT="/startup.2.d"

# Fix mount permissions
chmod 0777 "${RUN_SH_HOST}"

# Add a startup script to execute
printf "#!/bin/bash\\necho 'abcdefghijklmnopq';\\n" > "${RUN_SH_HOST}/myscript1.sh"
chmod +x "${RUN_SH_HOST}/myscript1.sh"

# Start PHP-FPM
did="$( docker_run "${IMAGE}:${VERSION}-${FLAVOUR}" "-e DEBUG_ENTRYPOINT=2 -e NEW_UID=$(id -u) -e NEW_GID=$(id -g) -v ${RUN_SH_HOST}:${RUN_SH_CONT}" )"

# Wait for both containers to be up and running
run "sleep 10"

# Check entrypoint for script run
if ! run "docker logs ${did} | grep 'myscript1.sh'"; then
docker_logs "${did}" || true
docker_stop "${did}" || true
rm -rf "${RUN_SH_HOST}"
echo "Failed"
exit 1
fi

# Check entrypoint for script output
if ! run "docker logs ${did} | grep 'abcdefghijklmnopq'"; then
docker_logs "${did}" || true
docker_stop "${did}" || true
rm -rf "${RUN_SH_HOST}"
echo "Failed"
exit 1
fi


# Cleanup
docker_stop "${did}"
rm -rf "${RUN_SH_HOST}"

0 comments on commit 452269c

Please sign in to comment.