Skip to content

Commit

Permalink
Add rdkafka extension (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnharvey authored Jul 31, 2021
1 parent d709b8a commit 7130c08
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
40 changes: 40 additions & 0 deletions layers/rdkafka/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ARG PHP_VERSION
FROM bref/build-php-$PHP_VERSION:1.1.4 AS ext

ENV LIBRDKAFKA_BUILD_DIR=${BUILD_DIR}/librdkafka

RUN set -xe; \
mkdir -p ${LIBRDKAFKA_BUILD_DIR}; \
# Download and upack the source code
curl -Ls https://github.com/edenhill/librdkafka/archive/refs/tags/v1.7.0.tar.gz \
| tar xzC ${LIBRDKAFKA_BUILD_DIR}

# Move into the unpackaged code directory
WORKDIR ${LIBRDKAFKA_BUILD_DIR}/librdkafka-1.7.0/

# Install
RUN set -xe; \
./configure --prefix=${INSTALL_DIR} && \
make && \
make install

RUN pecl install --onlyreqdeps --nobuild rdkafka && \
cd "$(pecl config-get temp_dir)/rdkafka" && \
phpize && \
./configure --with-rdkafka=${INSTALL_DIR} && \
make && \
make install && \
cd -

RUN cp /opt/bref/lib/php/extensions/no-debug-non-zts-*/rdkafka.so /tmp/rdkafka.so
RUN echo 'extension=/opt/bref-extra/rdkafka.so' > /tmp/ext.ini


# Build the final image with just the files we need
FROM scratch

# Copy things we installed to the final image
COPY --from=ext /tmp/rdkafka.so /opt/bref-extra/rdkafka.so
COPY --from=ext /tmp/ext.ini /opt/bref/etc/php/conf.d/ext-rdkafka.ini
COPY --from=ext /opt/bref/lib/librdkafka* /opt/bref/lib/
COPY --from=ext /opt/bref/include/librdkafka /opt/bref/include/
7 changes: 7 additions & 0 deletions layers/rdkafka/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"php": [
"73",
"74",
"80"
]
}
8 changes: 8 additions & 0 deletions layers/rdkafka/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

if (!class_exists($class = RdKafka\KafkaConsumer::class)) {
echo sprintf('FAIL: Class "%s" does not exist.', $class).PHP_EOL;
exit(1);
}

exit(0);

0 comments on commit 7130c08

Please sign in to comment.