newrelic / newrelic-php-agent

The New Relic PHP Agent
https://opensource.newrelic.com/projects/newrelic/newrelic-php-agent
Apache License 2.0
114 stars 60 forks source link

Install script fails on alpine 3.20 for official php docker images #905

Closed mvanduijker closed 2 weeks ago

mvanduijker commented 1 month ago

Install script fails on alpine 3.20 for official docker image tags

Description

Yesterday official docker images are released with alpine 3.20. The "naked" (like php:8.3-fpm-alpine) alpine tags are upgraded to this version but the install script fails with this error:

FATAL: failed to copy daemon init script to /etc/init.d/newrelic-daemon
FATAL: New Relic agent installation failed.
        Please contact https://support.newrelic.com/
        and report the above error. We have also created a tar file with
        log files and other system info that can help solve the problem.
        If the file /tmp/nrinstall-20240523-054511-10.tar exists please attach it to your bug report.
        We apologize for the inconvenience.

Steps to Reproduce

build this dockerfile

FROM docker.io/library/php:8.3-fpm-alpine

ENV NEWRELIC_VERSION=10.21.0.11
ARG TARGETPLATFORM

# this directory needs to exist for the copy command in the production stage to not fail
RUN mkdir -p /extension

RUN set -eux ; \
    curl \
      --silent \
      --fail \
      --location \
      --user-agent Dockerfile \
      --url https://download.newrelic.com/php_agent/archive/${NEWRELIC_VERSION}/newrelic-php5-${NEWRELIC_VERSION}-linux-musl.tar.gz \
      --output - \
      | tar --directory /tmp --extract --gzip --file - ; \
    export NR_INSTALL_USE_CP_NOT_LN=1 NR_INSTALL_SILENT=1 ; \
    /tmp/newrelic-php5-*/newrelic-install install ; \
    cp "$(php -r "echo ini_get ('extension_dir');")/newrelic.so" /extension/ ; \
    rm -rf /tmp/*;

Expected Behavior

Relevant Logs / Console output

FATAL: failed to copy daemon init script to /etc/init.d/newrelic-daemon
FATAL: New Relic agent installation failed.
        Please contact https://support.newrelic.com/
        and report the above error. We have also created a tar file with
        log files and other system info that can help solve the problem.
        If the file /tmp/nrinstall-20240523-054511-10.tar exists please attach it to your bug report.
        We apologize for the inconvenience.

Your Environment

Additional context

Building the docker container with alpine 3.19 works. So if you have this issue, set docker tag to something like php:8.3-fpm-alpine3.19

workato-integration[bot] commented 1 month ago

https://new-relic.atlassian.net/browse/NR-272798

Jimbolino commented 1 month ago

possible workaround for the bugged install script:

mkdir /etc/conf.d && mkdir /etc/init.d

Alpine 3.20 removed these empty directories, and the install script expects these directories to be present. I'm not sure where the newrelic-install script source is located, but reading it i found another bug:

In the doc it says NR_INSTALL_INITSCRIPT, but later on NR_INSTALL_INITFILE is used. You could set this to a temp folder, so you dont need to create the /etc/init.d/ folder. But no such mechanism exists for the /etc/conf.d problem, because the path is hardcoded:

    elif [ "${ostype}" = "alpine" ]; then
      sysconf=/etc/conf.d/newrelic-daemon
    fi
workato-integration[bot] commented 3 weeks ago

Work has been completed on this issue.

workato-integration[bot] commented 2 weeks ago

Work has been completed on this issue.

bilal-07 commented 6 days ago

Below is the commands that works for me in php:8.1-fpm-alpine

RUN mkdir -p /etc/conf.d && mkdir -p /etc/init.d
#Install Newrelic Agent
ENV NEW_RELIC_AGENT_VERSION=10.12.0.1
RUN curl -L https://download.newrelic.com/php_agent/archive/${NEW_RELIC_AGENT_VERSION}/newrelic-php5-${NEW_RELIC_AGENT_VERSION}-linux-musl.tar.gz | tar -C /tmp -zx \
    && export NR_INSTALL_USE_CP_NOT_LN=1 \
    && export NR_INSTALL_SILENT=1 \
    && export NR_INSTALL_INITFILE=/tmp/newrelic-daemon \
    && /tmp/newrelic-php5-*/newrelic-install install \
    && rm -rf /tmp/newrelic-php5-* /tmp/nrinstall*