From 0ce137e725861413358d0c849d8e56dde4bc5648 Mon Sep 17 00:00:00 2001 From: Nick Santamaria Date: Thu, 31 Oct 2024 13:50:29 +1100 Subject: [PATCH] Ensure php-fpm-exporter binary is patched (#323) --- gh-actions-bake.hcl | 11 +++++++++++ images/php-fpm-exporter/Dockerfile | 18 ++++++++++++++++++ images/php-fpm-exporter/README.md | 15 +++++++++++++++ images/php/Dockerfile.fpm | 7 +++---- ...fpm_exporter.sh => bay-php-fpm-exporter.sh} | 8 ++++---- 5 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 images/php-fpm-exporter/Dockerfile create mode 100644 images/php-fpm-exporter/README.md rename images/php/entrypoints/{bay-php-fpm_exporter.sh => bay-php-fpm-exporter.sh} (71%) diff --git a/gh-actions-bake.hcl b/gh-actions-bake.hcl index 9e080ff6..bed01c36 100755 --- a/gh-actions-bake.hcl +++ b/gh-actions-bake.hcl @@ -82,6 +82,17 @@ target "php-fpm" { "org.opencontainers.image.source" = "https://github.com/dpc-sdp/bay/blob/6.x/images/bay-php/Dockerfile.fpm" } } +target "php-fpm-exporter" { + inherits = ["docker-metadata-action"] + context = "${CONTEXT}/php-fpm-exporter" + dockerfile = "Dockerfile" + + platforms = ["linux/amd64", "linux/arm64"] + + labels = { + "org.opencontainers.image.source" = "https://github.com/dpc-sdp/bay/blob/6.x/images/bay-php-exporter/Dockerfile" + } +} target "ripple-static" { inherits = ["docker-metadata-action"] context = "${CONTEXT}/ripple-static" diff --git a/images/php-fpm-exporter/Dockerfile b/images/php-fpm-exporter/Dockerfile new file mode 100644 index 00000000..74ab56d3 --- /dev/null +++ b/images/php-fpm-exporter/Dockerfile @@ -0,0 +1,18 @@ +FROM golang:latest as builder +RUN git clone https://github.com/hipages/php-fpm_exporter.git /workspace +WORKDIR /workspace +RUN make deps +RUN TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}; \ + GOOS=${TARGETPLATFORM%%/*} GOARCH=${TARGETPLATFORM#*/} go build -o php-fpm-exporter . + +FROM gcr.io/distroless/static:nonroot +LABEL org.opencontainers.image.authors="Single Digital Presence" +LABEL org.opencontainers.image.description="Utility to export php-fpm data as prometheus metrics" +LABEL org.opencontainers.image.source="https://github.com/dpc-sdp/bay" + +WORKDIR / +EXPOSE 9253 +COPY --from=builder /workspace/php-fpm-exporter . +USER nonroot:nonroot +ENTRYPOINT ["/php-fpm-exporter"] +CMD ["server"] \ No newline at end of file diff --git a/images/php-fpm-exporter/README.md b/images/php-fpm-exporter/README.md new file mode 100644 index 00000000..41d7a0d9 --- /dev/null +++ b/images/php-fpm-exporter/README.md @@ -0,0 +1,15 @@ +# # Container Image - php-fpm-exporter + +Provides a [php-fpm-exporter](https://github.com/hipages/php-fpm_exporter/) image. + +## Usage + +Container needs to be able to access the php-fpm status endpoint, so should be deployed as a sidecar alongside a php-fpm container. + +## Environment Variables + +None + +## Ports + +- `9253` - metrics server diff --git a/images/php/Dockerfile.fpm b/images/php/Dockerfile.fpm index c89c771e..24f9c050 100644 --- a/images/php/Dockerfile.fpm +++ b/images/php/Dockerfile.fpm @@ -1,8 +1,8 @@ ARG PHP_VERSION=8.3 +FROM ghcr.io/dpc-sdp/bay/php-fpm-exporter:6.x AS php-fpm-exporter FROM uselagoon/php-${PHP_VERSION}-fpm:latest ARG BAY_CLI_VERSION=v1.1.3 -ARG PHP_FPM_EXPORTER_VERSION=2.2.0 RUN mkdir /bay COPY 01-bay.ini /usr/local/etc/php/conf.d/ @@ -10,7 +10,7 @@ COPY bay-php-config.sh /bay # Ensure temp dir exists if required COPY entrypoints/bay-shared-temp-files-dir-check.sh /lagoon/entrypoints -COPY entrypoints/bay-php-fpm_exporter.sh /lagoon/entrypoints +COPY entrypoints/bay-php-fpm-exporter.sh /lagoon/entrypoints # Add common drupal config. COPY redis-unavailable.services.yml /bay @@ -34,8 +34,7 @@ RUN chmod +x /tmp/bay RUN mv /tmp/bay /bin/bay # Install php-fpm_exporter -RUN curl -s -L "https://github.com/hipages/php-fpm_exporter/releases/download/v${PHP_FPM_EXPORTER_VERSION}/php-fpm_exporter_${PHP_FPM_EXPORTER_VERSION}_$(echo ${TARGETPLATFORM:-linux/amd64} | tr '/' '_')" --output /bin/php-fpm_exporter -RUN chmod +x /bin/php-fpm_exporter +COPY --from=php-fpm-exporter /php-fpm-exporter /bin/ EXPOSE 9253 ONBUILD ARG BAY_DISABLE_FUNCTIONS=phpinfo,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,system,exec,shell_exec,passthru,phpinfo,show_source,highlight_file,popen,fopen_with_path,dbmopen,dbase_open,filepro,filepro_rowcount,filepro_retrieve,posix_mkfifo diff --git a/images/php/entrypoints/bay-php-fpm_exporter.sh b/images/php/entrypoints/bay-php-fpm-exporter.sh similarity index 71% rename from images/php/entrypoints/bay-php-fpm_exporter.sh rename to images/php/entrypoints/bay-php-fpm-exporter.sh index b595ea85..d0b0c297 100644 --- a/images/php/entrypoints/bay-php-fpm_exporter.sh +++ b/images/php/entrypoints/bay-php-fpm-exporter.sh @@ -1,7 +1,7 @@ #!/usr/bin/env sh set -euo pipefail -#/ Usage: PHP_FPM_EXPORTER_ENABLED=true ./bay-php-fpm_exporter.sh +#/ Usage: PHP_FPM_EXPORTER_ENABLED=true ./bay-php-fpm-exporter.sh #/ Options: #/ --help: Display this help message usage() { grep '^#/' "$0" | cut -c4- ; exit 0 ; } @@ -14,8 +14,8 @@ error() { echoerr "[ERROR] $*" ; } fatal() { echoerr "[FATAL] $*" ; exit 1 ; } if [ "${PHP_FPM_EXPORTER_ENABLED:-false}" = "true" ]; then - info starting php-fpm_exporter metrics server - php-fpm_exporter server & + info starting php-fpm-exporter metrics server + php-fpm-exporter server & else - info php-fpm_exporter metrics server disabled + info php-fpm-exporter metrics server disabled fi