Skip to content

Commit

Permalink
Otel optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderM91 committed Jan 30, 2025
1 parent 6d7b291 commit dcf2e51
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 87 deletions.
26 changes: 13 additions & 13 deletions alpine/3.20/8.3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# syntax = docker/dockerfile:1.0.2-experimental
ARG SPRYKER_PHP_VERSION=8.3.13
ARG EXTENSION_IMAGE=spryker/grpc-protobuf:8.3-alpine3.20
#ARG EXTENSION_IMAGE=spryker/grpc-protobuf:8.3-alpine3.20

FROM ${EXTENSION_IMAGE} AS extension
#FROM ${EXTENSION_IMAGE} AS extension

FROM php:${SPRYKER_PHP_VERSION}-fpm-alpine3.20

Expand Down Expand Up @@ -190,24 +190,24 @@ COPY context/php/conf.d/92-session.ini /usr/local/etc/php/conf.d/
COPY context/php/disabled /usr/local/etc/php/disabled

#OTEL: disable code instrumentattion by default
ENV OTEL_SDK_DISABLED=true
ENV OTEL_PHP_DISABLED_INSTRUMENTATIONS="all"
#ENV OTEL_SDK_DISABLED=true
#ENV OTEL_PHP_DISABLED_INSTRUMENTATIONS="all"

# Copy extensions from extension image to tpm path
COPY --from=extension /usr/local/lib/php/extensions/no-debug-non-zts-20230831/grpc.so /tmp/php-ext-dir-path/grpc.so
COPY --from=extension /usr/local/lib/php/extensions/no-debug-non-zts-20230831/protobuf.so /tmp/php-ext-dir-path/protobuf.so
#COPY --from=extension /usr/local/lib/php/extensions/no-debug-non-zts-20230831/grpc.so /tmp/php-ext-dir-path/grpc.so
#COPY --from=extension /usr/local/lib/php/extensions/no-debug-non-zts-20230831/protobuf.so /tmp/php-ext-dir-path/protobuf.so

#Calculate tarrget php extension folder and copy required extensions
RUN PHP_EXT_DIR=$(php-config --extension-dir) \
&& echo "Using PHP extension directory: $PHP_EXT_DIR" \
&& cp /tmp/php-ext-dir-path/grpc.so $PHP_EXT_DIR/grpc.so \
&& cp /tmp/php-ext-dir-path/protobuf.so $PHP_EXT_DIR/protobuf.so
RUN #PHP_EXT_DIR=$(php-config --extension-dir) \
# && echo "Using PHP extension directory: $PHP_EXT_DIR" \
# && cp /tmp/php-ext-dir-path/grpc.so $PHP_EXT_DIR/grpc.so \
# && cp /tmp/php-ext-dir-path/protobuf.so $PHP_EXT_DIR/protobuf.so


#OTEL: Disable OTEL related extensions and keep original configs.
COPY --from=extension /usr/local/etc/php/conf.d/docker-php-ext-protobuf.ini /usr/local/etc/php/disabled/protobuf.ini
COPY --from=extension /usr/local/etc/php/conf.d/docker-php-ext-grpc.ini /usr/local/etc/php/disabled/grpc.ini
RUN mv /usr/local/etc/php/conf.d/docker-php-ext-opentelemetry.ini /usr/local/etc/php/disabled/opentelemetry.ini
#COPY --from=extension /usr/local/etc/php/conf.d/docker-php-ext-protobuf.ini /usr/local/etc/php/disabled/protobuf.ini
#COPY --from=extension /usr/local/etc/php/conf.d/docker-php-ext-grpc.ini /usr/local/etc/php/disabled/grpc.ini
RUN #mv /usr/local/etc/php/conf.d/docker-php-ext-opentelemetry.ini /usr/local/etc/php/disabled/opentelemetry.ini

WORKDIR /data

Expand Down
222 changes: 148 additions & 74 deletions alpine/extension/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,84 +1,158 @@
# GRPC + Protobuf extension
ARG MAJOR_PHP_VERSION=8.3
ARG ALPINE_VERSION=3.20
FROM php:${MAJOR_PHP_VERSION}-fpm-alpine${ALPINE_VERSION}
## GRPC + Protobuf extension
#ARG MAJOR_PHP_VERSION=8.3
#ARG ALPINE_VERSION=3.20
#FROM php:${MAJOR_PHP_VERSION}-fpm-alpine${ALPINE_VERSION}
#
## Set environment variables
#ENV srcRoot /data
#ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
#
#ARG PHP_RUN_DEPS="\
# freetype \
# gmp \
# gnu-libiconv \
# icu-libs \
# libbz2 \
# libc6-compat \
# libjpeg-turbo \
# libpng \
# libwebp \
# libxml2 \
# libxpm \
# libxslt \
# libzip \
# protobuf \
# grpc"
#
#ARG PHP_BUILD_DEPS="\
# autoconf \
# bzip2-dev \
# freetype-dev \
# gmp-dev \
# icu-dev \
# icu-data-full \
# libjpeg-turbo-dev \
# libpng-dev \
# libwebp-dev \
# libxml2-dev \
# libxpm-dev \
# libzip-dev \
# postgresql-dev \
# rabbitmq-c-dev \
# protobuf-dev \
# grpc-dev \
# g++"
#
#ARG PHP_PECL_EXTENSIONS="\
# opentelemetry \
# protobuf \
# grpc"
#
#ARG ADDITIONAL_PHP_PECL_EXTENSIONS=""
#
#RUN apk add --no-cache \
# bash \
# coreutils \
# curl \
# git \
# make \
# mysql-client \
# netcat-openbsd \
# openssh \
# postgresql-client \
# procps \
# python3 \
# shadow \
# unzip \
# linux-headers \
# libstdc++ \
# ${PHP_RUN_DEPS} \
# && apk add --no-cache --virtual .php-build-deps ${PHP_BUILD_DEPS} \
# && MAKEFLAGS="-j$(nproc)" pecl install -o -f ${PHP_PECL_EXTENSIONS} ${ADDITIONAL_PHP_PECL_EXTENSIONS} \
# && docker-php-ext-enable ${PHP_PECL_EXTENSIONS} \
# && rm -rf /tmp/pear \
# && apk del --no-cache .php-build-deps
#
#RUN mkdir -p ${srcRoot}
#
## Set environment variables
#ENV srcRoot /data
#ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
#
#WORKDIR ${srcRoot}
#
#USER root

#ARG MAJOR_PHP_VERSION=8.3
#ARG ALPINE_VERSION=3.20
#FROM php:${MAJOR_PHP_VERSION}-fpm-alpine${ALPINE_VERSION}
#
## Install required dependencies
#RUN apk add --no-cache \
# php83-pear \
# php83-dev \
# autoconf \
# g++ \
# libtool \
# make \
# linux-headers \
# grpc grpc-dev protobuf protobuf-dev \
# && pecl install grpc --configure-options="--disable-debug --enable-optimize" \
# && docker-php-ext-enable grpc \
# && apk del --no-cache php-dev autoconf g++ libtool make linux-headers grpc-dev protobuf-dev \
# && rm -rf /tmp/pear
#
#RUN apk add --no-cache strip
#RUN strip --strip-unneeded /usr/local/lib/php/extensions/no-debug-non-zts-20230831/grpc.so
#
## Verify GRPC installation
#RUN php --ri grpc || echo "GRPC INSTALLATION FAILED!"

# Set environment variables
ENV srcRoot /data
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

ARG PHP_RUN_DEPS="\
freetype \
gmp \
gnu-libiconv \
icu-libs \
libbz2 \
libc6-compat \
libjpeg-turbo \
libpng \
libwebp \
libxml2 \
libxpm \
libxslt \
libzip \
protobuf \
grpc"
#ARG MAJOR_PHP_VERSION=8.3
#ARG ALPINE_VERSION=3.20
#FROM php:${MAJOR_PHP_VERSION}-fpm-alpine${ALPINE_VERSION}
#
## Install GRPC and Protobuf extensions
#RUN apk add --no-cache php83-pecl-grpc php83-pecl-protobuf
#
## Manually enable GRPC and Protobuf (since `docker-php-ext-enable` does not work)
#RUN echo "extension=grpc.so" > /etc/php83/conf.d/00_grpc.ini \
# && echo "extension=protobuf.so" > /etc/php83/conf.d/00_protobuf.ini
#
## Verify installation
#RUN php --ri grpc || echo "GRPC INSTALLATION FAILED!"
#RUN php --ri protobuf || echo "PROTOBUF INSTALLATION FAILED!"

ARG PHP_BUILD_DEPS="\
autoconf \
bzip2-dev \
freetype-dev \
gmp-dev \
icu-dev \
icu-data-full \
libjpeg-turbo-dev \
libpng-dev \
libwebp-dev \
libxml2-dev \
libxpm-dev \
libzip-dev \
postgresql-dev \
rabbitmq-c-dev \
protobuf-dev \
grpc-dev \
g++"
#ARG MAJOR_PHP_VERSION=8.3
#ARG ALPINE_VERSION=3.20
#FROM php:${MAJOR_PHP_VERSION}-fpm-alpine${ALPINE_VERSION}
#
## Install GRPC extension
#RUN apk add --no-cache php83-pecl-grpc
#
## Manually enable GRPC
#RUN echo "extension=grpc.so" > /etc/php83/conf.d/00_grpc.ini
#
## Verify GRPC installation
#RUN php --ri grpc || echo "GRPC INSTALLATION FAILED!"

ARG PHP_PECL_EXTENSIONS="\
opentelemetry \
protobuf \
grpc"
ARG MAJOR_PHP_VERSION=8.3
ARG ALPINE_VERSION=3.20
FROM php:${MAJOR_PHP_VERSION}-fpm-alpine${ALPINE_VERSION}

ARG ADDITIONAL_PHP_PECL_EXTENSIONS=""
# Add community repository where PHP extensions are available
RUN echo "https://dl-cdn.alpinelinux.org/alpine/v$(cut -d'.' -f1,2 /etc/alpine-release)/community" >> /etc/apk/repositories

RUN apk add --no-cache \
bash \
coreutils \
curl \
git \
make \
mysql-client \
netcat-openbsd \
openssh \
postgresql-client \
procps \
python3 \
shadow \
unzip \
linux-headers \
libstdc++ \
${PHP_RUN_DEPS} \
&& apk add --no-cache --virtual .php-build-deps ${PHP_BUILD_DEPS} \
&& MAKEFLAGS="-j$(nproc)" pecl install -o -f ${PHP_PECL_EXTENSIONS} ${ADDITIONAL_PHP_PECL_EXTENSIONS} \
&& docker-php-ext-enable ${PHP_PECL_EXTENSIONS} \
&& rm -rf /tmp/pear \
&& apk del --no-cache .php-build-deps

RUN mkdir -p ${srcRoot}
php83-pecl-grpc \
php83-pecl-protobuf

# Set environment variables
ENV srcRoot /data
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so
RUN ln -s /usr/lib/php83/modules/grpc.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/grpc.so && \
ln -s /usr/lib/php83/modules/protobuf.so /usr/local/lib/php/extensions/no-debug-non-zts-20230831/protobuf.so

WORKDIR ${srcRoot}
RUN echo "extension=grpc.so" > /usr/local/etc/php/conf.d/docker-php-ext-grpc.ini && \
echo "extension=protobuf.so" > /usr/local/etc/php/conf.d/docker-php-ext-protobuf.ini

USER root
# Verify GRPC installation
RUN php -m | grep grpc

0 comments on commit dcf2e51

Please sign in to comment.