Skip to content

Commit

Permalink
Merge pull request #186 from bryanlatten/newrelic-go-cache
Browse files Browse the repository at this point in the history
Newrelic: remove go-cache after compile, Github CI compatible + working
  • Loading branch information
adobejmong committed Dec 22, 2021
2 parents ae9d5f1 + 25fbf83 commit 6127fa7
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 80 deletions.
35 changes: 18 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,39 @@ jobs:
strategy:
matrix:
variant:
- 7.4
- 7.4-alpine
- 8.0
- "7.4"
- "7.4-alpine"
- "8.0"
platform:
- linux/amd64
# - linux/arm64
- linux/arm64
exclude:
- props:
Dockerfile: Dockerfile-7.4-alpine
# TODO: enable with compile cache
- platform: linux/arm64
env:
TEST_MATCH: PHP Version ${{ matrix.props.version }}
TEST_MATCH: PHP Version ${{ matrix.variant }}
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Install goss
run: |
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
run: |
# NOTE: Docker host configuration determines the networking target for integration testing
v=$(mount | grep "/run/docker.sock")
TARGET_HOST=
if [ -n "$v" ]; then
echo "Injected docker socket detected"
if [[ -n "$ACT" ]]; then
echo "Local execution detected"
TARGET_HOST="host.docker.internal"
elif [ -S /var/run/docker.sock ]; then
TARGET_HOST="localhost"
else
echo "No Docker socket detected, fail"
exit 1
fi
TARGET_HOST="localhost"
fi;
echo "TARGET_HOST=${TARGET_HOST}" >> $GITHUB_ENV
-
# Build and execute in multiple configurations: vanilla, with env overrides, with TLS enabled
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
10 changes: 7 additions & 3 deletions Dockerfile-7.4
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM behance/docker-nginx:9.0
FROM behance/docker-nginx:9.0 as output
LABEL maintainers="Behance Team <dev-behance@adobe.com>"

# Set TERM to suppress warning messages.
Expand Down Expand Up @@ -138,9 +138,13 @@ RUN cp /etc/php/7.0/mods-available/* $CONF_PHPMODS && \
# Run standard set of tweaks to ensure runs performant, reliably, and consistent between variants
/bin/bash -e /scripts/prep-php.sh

# TESTING PHASE: using multi-stage to isolate any possible side effects
FROM output as testenvironment

# HACK: workaround for https://github.com/aelsabbahy/goss/issues/392
# Run the child and parent test configs separately instead of leveraging inheritance
RUN goss -g /tests/php-fpm/7.4.goss.yaml validate && \
goss -g /tests/php-fpm/base.goss.yaml validate && \
/aufs_hack.sh
goss -g /tests/php-fpm/base.goss.yaml validate

# Output the final image
FROM output
10 changes: 7 additions & 3 deletions Dockerfile-7.4-alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM behance/docker-nginx:9.0-alpine
FROM behance/docker-nginx:9.0-alpine as output
LABEL maintainers="Behance Team <dev-behance@adobe.com>"

# Set TERM to suppress warning messages.
Expand Down Expand Up @@ -130,8 +130,12 @@ RUN cp /etc/php/7.0/mods-available/* $CONF_PHPMODS && \
ln -s /usr/sbin/php-fpm7 /usr/sbin/php-fpm && \
/bin/bash -e /scripts/prep-php.sh

# TESTING PHASE: using multi-stage to isolate any possible side effects
FROM output
# HACK: workaround for https://github.com/aelsabbahy/goss/issues/392
# Run the child and parent test configs separately instead of leveraging inheritance
RUN goss -g /tests/php-fpm/7.4-alpine.goss.yaml validate && \
goss -g /tests/php-fpm/base.goss.yaml validate && \
/aufs_hack.sh
goss -g /tests/php-fpm/base.goss.yaml validate

# Output the final image
FROM output
11 changes: 8 additions & 3 deletions Dockerfile-8.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM behance/docker-nginx:9.0
FROM behance/docker-nginx:9.0 as output
LABEL maintainers="Behance Team <dev-behance@adobe.com>"

# Set TERM to suppress warning messages.
Expand Down Expand Up @@ -133,8 +133,13 @@ RUN cp /etc/php/7.0/mods-available/* $CONF_PHPMODS && \
# Run standard set of tweaks to ensure runs performant, reliably, and consistent between variants
/bin/bash -e /scripts/prep-php.sh

# TESTING PHASE: using multi-stage to isolate any possible side effects
FROM output as testenvironment

# HACK: workaround for https://github.com/aelsabbahy/goss/issues/392
# Run the child and parent test configs separately instead of leveraging inheritance
RUN goss -g /tests/php-fpm/8.0.goss.yaml validate && \
goss -g /tests/php-fpm/base.goss.yaml validate && \
/aufs_hack.sh
goss -g /tests/php-fpm/base.goss.yaml validate

# Output the final image
FROM output
11 changes: 0 additions & 11 deletions runtime-tests/newrelic/7.4/goss.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions runtime-tests/newrelic/8.0/goss.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
file:
/etc/php7/conf.d/newrelic.ini:
{{ .Env.CONF_PHPMODS }}/newrelic.ini:
exists: true
mode: "0644"
filetype: file # file, symlink, directory
Expand All @@ -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-alpine/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/'
7 changes: 4 additions & 3 deletions scripts/install-newrelic-alpine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ mkdir -p /var/log/newrelic
chmod 777 /var/log/newrelic
cp agent/scripts/newrelic.ini.template "${CONF_PHPMODS}"/newrelic.ini

# Delete compilation directories, no longer needed
go clean --cache
rm -rf /root/newrelic-php-agent

# Cleanup script-specific packages
apk del .newrelic_deps

# Delete compilation directory, no longer needed
rm -rf /root/newrelic-php-agent
4 changes: 3 additions & 1 deletion scripts/install-newrelic-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ mkdir -p /var/log/newrelic
chmod 777 /var/log/newrelic
cp agent/scripts/newrelic.ini.template "${CONF_PHPMODS}"/newrelic.ini

# Delete compilation directory, no longer needed
# Delete compilation directories, no longer needed
go clean --cache
rm -rf /root/newrelic-php-agent

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 upload=@tmp.txt "${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 6127fa7

Please sign in to comment.