Skip to content

Commit

Permalink
Add tests for custom startup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cytopia committed Dec 24, 2018
1 parent 023ad2a commit 70764c2
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions tests/prod/08-test-custom-user-scripts.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.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 70764c2

Please sign in to comment.