Skip to content

Commit

Permalink
Test: fixing GH CI test environment
Browse files Browse the repository at this point in the history
- Cleaning up testing structure
  • Loading branch information
Bryan Latten committed Dec 20, 2021
1 parent f6cf050 commit aebaaf7
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 40 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- linux/amd64
- linux/arm64
exclude:
- variant: 7.4-alpine
# TODO: enable with compile cache
- platform: linux/arm64
env:
TEST_MATCH: PHP Version ${{ matrix.variant }}
Expand All @@ -28,8 +28,9 @@ jobs:
-
name: Install goss
run: |
curl -fsSL https://goss.rocks/install | sh
curl -L https://github.com/aelsabbahy/goss/releases/download/v0.3.9/goss-linux-amd64 -o /usr/local/bin/goss
curl -L https://raw.githubusercontent.com/aelsabbahy/goss/master/extras/dgoss/dgoss -o /usr/local/bin/dgoss
chmod +rx /usr/local/bin/goss
chmod +rx /usr/local/bin/dgoss
-
name: Detect host configuration
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ sudo: required

env:
global:
- GOSS_INSTALL_PATH="./"
- GOSS_PATH="./goss"
- DGOSS_PATH="./dgoss"
jobs:
- PHP_VARIANT=7.4-alpine
- PHP_VARIANT=7.4
Expand Down
11 changes: 0 additions & 11 deletions runtime-tests/newrelic/7.4-alpine/goss.yaml

This file was deleted.

7 changes: 7 additions & 0 deletions runtime-tests/newrelic/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ file:
- '/^newrelic.loglevel = \"verbosedebug\"/'
- '/^newrelic.daemon.loglevel = \"verbosedebug\"/'
- '/^newrelic.special=debug_autorum/'
/goss/docker_output.log:
exists: true
filetype: file # file, symlink, directory
contains: # Check file content for these patterns
- '/enabling APM metrics/'
- '/adding in newrelic.special/'
- '/enabling tracing/'
6 changes: 0 additions & 6 deletions runtime-tests/startup/7.4/goss.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions runtime-tests/startup/8.0/goss.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ file:
filetype: file # file, symlink, directory
contains: # Check file content for these patterns
- '/launching...$/'
- '/fpm is running/'
- '/ready to handle connections/'
46 changes: 32 additions & 14 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ set -o pipefail
MACHINE=$1
INTERNAL_PORT=8080
PREFIX="==>"
BASE_NAME="docker-php"

if [ -z "$1" ]; then
if [[ -z "$1" ]]; then
printf "Basic integration script for docker-php and its variants\n\n"
printf "Usage:\n\ttest.sh [docker-machine ip]\n"
exit 1;
exit 1
fi

if [ ! $PHP_VARIANT ]; then
if [[ ! $PHP_VARIANT ]]; then
echo "Missing PHP_VARIANT environment variable"
exit 1
fi

# Required for dgoss execution, below
if [[ ! -n "$GOSS_PATH" ]]; then
[ -f $(which goss) ] || { echo 'goss not found, pass GOSS_PATH'; exit 1; }
GOSS_PATH=$(which goss)
fi

if [[ ! -n "$DGOSS_PATH" ]]; then
[ -f $(which dgoss) ] || { echo 'dgoss not found, pass DGOSS_PATH'; exit 1; }
DGOSS_PATH=$(which dgoss)
fi

# Distinguish between naming types
VARIANT_NAME=$PHP_VARIANT
DOCKERFILE_NAME="Dockerfile-${PHP_VARIANT}"
Expand All @@ -36,13 +48,12 @@ TEST_STRING="PHP Version ${PHP_VERSION}."
PLATFORM="${PLATFORM:=linux/amd64}"

# Since containers may or may not be against the same docker engine, create a matrix-unique tag name for outputs
TAG_NAME="docker-php-${VARIANT_NAME}-${PLATFORM}"
TAG_NAME="${BASE_NAME}-${VARIANT_NAME}-${PLATFORM}"
# Formats as lowercase
TAG_NAME=$(echo $TAG_NAME | tr '[:upper:]' '[:lower:]')
# Removes slashes
TAG_NAME=$(echo $TAG_NAME | sed 's/\///')


echo "${PREFIX} Variant ${VARIANT_NAME}"
echo "${PREFIX} PHP Version: ${PHP_VERSION}"
echo "${PREFIX} Dockerfile: ${DOCKERFILE_NAME}"
Expand All @@ -51,6 +62,9 @@ echo "${PREFIX} Platform: ${PLATFORM}"

printf "${PREFIX} Building container\n"

printf "${PREFIX} using goss (${GOSS_PATH})\n"
printf "${PREFIX} using dgoss (${DGOSS_PATH})\n"

docker buildx build --platform $PLATFORM --iidfile $TAG_NAME -t $TAG_NAME -f $DOCKERFILE_NAME .

# NOTE: multi-arch builds may not be accessible by docker tag, instead target by ID
Expand All @@ -63,6 +77,9 @@ printf "${PREFIX} Running container in background\n"
CONTAINER_ID=$(docker run --rm --platform $PLATFORM --env-file ./.test.env -p $INTERNAL_PORT -d $BUILD_SHA)
CONTAINER_PORT=$(docker inspect --format '{{ (index (index .NetworkSettings.Ports "8080/tcp") 0).HostPort }}' $CONTAINER_ID)

printf "${PREFIX} Waiting for container to boot\n"
sleep 5

# ==> Cleanup routine
# CI environments may be ephemeral, but local environments are not
function finish {
Expand All @@ -77,9 +94,7 @@ function finish {

trap finish EXIT

printf "${PREFIX} Waiting for container to boot\n"
sleep 5

# -------------------------------------------------------------
echo "${PREFIX} Check default response, including PHP version identification"
curl "${MACHINE}:${CONTAINER_PORT}" | grep "${TEST_STRING}"

Expand All @@ -90,16 +105,19 @@ echo "${PREFIX} Send uploaded file"
curl --form [email protected] "${MACHINE}:${CONTAINER_PORT}" \
| grep "${TEST_STRING}" > /dev/null

# -------------------------------------------------------------
echo "${PREFIX} Perform startup tests"
GOSS_PATH=goss \

GOSS_FILES_PATH="runtime-tests/startup/" \
GOSS_SLEEP=5 \
GOSS_FILES_PATH="runtime-tests/startup/${PHP_VARIANT}/" \
"${GOSS_INSTALL_PATH}dgoss" run --rm $BUILD_SHA
$DGOSS_PATH run --rm $BUILD_SHA

# -------------------------------------------------------------
echo "${PREFIX} Perform NewRelic runtime tests"
GOSS_PATH=goss \
GOSS_FILES_PATH="runtime-tests/newrelic/${PHP_VARIANT}/" \
"${GOSS_INSTALL_PATH}dgoss" run \

GOSS_FILES_PATH="runtime-tests/newrelic/" \
GOSS_SLEEP=5 \
$DGOSS_PATH run --rm \
-e REPLACE_NEWRELIC_APP="abcdefg" \
-e REPLACE_NEWRELIC_LICENSE="hijklmno" \
-e NEWRELIC_TRACING_ENABLED="true" \
Expand Down

0 comments on commit aebaaf7

Please sign in to comment.