Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ functions:
| ODBC Snowflake | `${bref-extra:odbc-snowflake-php-81}` |
| OpenSwoole | `${bref-extra:openswoole-php-81}` |
| OpenTelemetry | `${bref-extra:opentelemetry-php-81}` |
| Oracle | `${bref-extra:oci8-php-80}` |
| Oracle | `${bref-extra:oci8-php-83}` |
| Pcov | `${bref-extra:pcov-php-81}` |
| PostgreSQL | `${bref-extra:pgsql-php-81}` |
| RdKafka | `${bref-extra:rdkafka-php-81}` |
Expand Down
84 changes: 45 additions & 39 deletions layers/oci8/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
ARG PHP_VERSION
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext
ARG OL_VERSION=8
ARG IC_VERSION=21
# Oracle Instant Client image
FROM public.ecr.aws/docker/library/oraclelinux:$OL_VERSION AS oracle_base
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested the layer? Here the library is installed in an image that is not the one used in AWS Lambda, there's high risk the library is incompatible when running in Lambda.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did. I created a custom layer and ran it with arn:aws:lambda:us-west-2:873528684822:layer:php-84:16. It connected and queried an Oracle database happily. I even tried it with the v2 layer (al.2) - which failed due to an incompatible lib. I totally get if you're not comfortable approving this PR. It could certainly have some sneaky issues. I'm happy to keep using my custom layer until you or the previous maintainer can get around to updating it :)

ARG OL_VERSION
RUN dnf -y install oracle-instantclient-release-el${OL_VERSION}

FROM oracle_base AS oracle_devel
RUN dnf -y install oracle-instantclient-devel && \
mkdir -p /opt/oracle && \
cp -r /usr/lib/oracle/*/client64/lib/* /opt/oracle/ && \
cp -r /usr/include/oracle/*/client64/* /opt/oracle/

FROM oracle_base AS oracle_client
RUN dnf -y install oracle-instantclient-basiclite && \
mkdir -p /opt/oracle && \
cp -r /usr/lib/oracle/*/client64/lib/* /opt/oracle/

# Redeclare for scope
ARG PHP_VERSION

# Specify library path
ENV LD_LIBRARY_PATH=/usr/lib:/usr/lib64:$LD_LIBRARY_PATH
ENV ORACLE_BUILD_DIR=${BUILD_DIR}/oracle

# Install libaio
RUN dnf install -y libaio

# Instant Client newer than 21.x requires glibc 2.28+ which is not available on Amazon Linux 2
RUN mkdir -p ${ORACLE_BUILD_DIR}; \
cd ${ORACLE_BUILD_DIR}; \
curl -o oci-basic.zip https://download.oracle.com/otn_software/linux/instantclient/2116000/instantclient-basiclite-linux.x64-21.16.0.0.0dbru.zip && \
unzip oci-basic.zip -d src -x META-INF/* && \
curl -o oci-sdk.zip https://download.oracle.com/otn_software/linux/instantclient/2116000/instantclient-sdk-linux.x64-21.16.0.0.0dbru.zip && \
unzip oci-sdk.zip -d src -x META-INF/*

RUN if [ "$PHP_VERSION" = "80" ] ; then \
echo "instantclient,${ORACLE_BUILD_DIR}/src/instantclient_21_16" | pecl install oci8-3.0.1; \
elif [ "$PHP_VERSION" = "81" ] ; then \
echo "instantclient,${ORACLE_BUILD_DIR}/src/instantclient_21_16" | pecl install oci8-3.2.1; \
else \
echo "instantclient,${ORACLE_BUILD_DIR}/src/instantclient_21_16" | pecl install oci8; \
fi

RUN cp /usr/lib64/libaio.so.1 /tmp/libaio.so.1
RUN cp ${ORACLE_BUILD_DIR}/src/instantclient_21_16/libclntshcore.so.21.1 /tmp/libclntshcore.so.21.1
RUN cp ${ORACLE_BUILD_DIR}/src/instantclient_21_16/libclntsh.so.21.1 /tmp/libclntsh.so.21.1
RUN cp ${ORACLE_BUILD_DIR}/src/instantclient_21_16/libocci.so.21.1 /tmp/libocci.so.21.1
RUN cp ${ORACLE_BUILD_DIR}/src/instantclient_21_16/libnnz21.so /tmp/libnnz21.so
RUN cp ${ORACLE_BUILD_DIR}/src/instantclient_21_16/libociicus.so /tmp/libociicus.so
RUN cp `php-config --extension-dir`/oci8.so /tmp/oci8.so
RUN echo 'extension=oci8.so' > /tmp/ext.ini

RUN php /bref/lib-copy/copy-dependencies.php /tmp/oci8.so /tmp/extension-libs
# Missing these two
RUN cp /tmp/libocci.so.21.1 /tmp/extension-libs
RUN cp /tmp/libociicus.so /tmp/extension-libs
ARG BREF_VERSION
FROM bref/build-php-$PHP_VERSION:$BREF_VERSION AS ext
ARG IC_VERSION
ENV ORACLE_DEVEL_DIR=/opt/oracle-devel
ENV ORACLE_CLIENT_DIR=/opt/oracle-client
ENV LD_LIBRARY_PATH=/usr/lib:/usr/lib64:$ORACLE_CLIENT_DIR:$ORACLE_DEVEL_DIR:$LD_LIBRARY_PATH

COPY --from=oracle_devel /usr/lib64/libaio.so.1 /usr/lib64/libaio.so.1
COPY --from=oracle_devel /opt/oracle $ORACLE_DEVEL_DIR
COPY --from=oracle_client /opt/oracle $ORACLE_CLIENT_DIR

RUN echo "instantclient,${ORACLE_DEVEL_DIR}" | pecl install oci8

RUN cp /usr/lib64/libaio.so.1 /tmp/libaio.so.1 && \
cp ${ORACLE_CLIENT_DIR}/libclntshcore.so.${IC_VERSION}.1 /tmp && \
cp ${ORACLE_CLIENT_DIR}/libclntsh.so.${IC_VERSION}.1 /tmp && \
cp ${ORACLE_CLIENT_DIR}/libnnz${IC_VERSION}.so /tmp && \
cp ${ORACLE_CLIENT_DIR}/libocci.so.${IC_VERSION}.1 /tmp && \
cp ${ORACLE_CLIENT_DIR}/libociicus.so /tmp && \
cp `php-config --extension-dir`/oci8.so /tmp/oci8.so && \
echo 'extension=oci8.so' > /tmp/ext.ini

RUN php /bref/lib-copy/copy-dependencies.php /tmp/oci8.so /tmp/extension-libs && \
cp /tmp/libocci.so.${IC_VERSION}.1 /tmp/extension-libs && \
cp /tmp/libociicus.so /tmp/extension-libs

# Build the final image from the scratch image that contain files you want to export
FROM scratch

COPY --from=ext /tmp/oci8.so /opt/bref/extensions/oci8.so
COPY --from=ext /tmp/ext.ini /opt/bref/etc/php/conf.d/ext-oci8.ini
COPY --from=ext /tmp/extension-libs /opt/lib
COPY --from=ext /tmp/extension-libs /opt/lib
3 changes: 3 additions & 0 deletions layers/oci8/config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"php": [
"83",
"84",
"85"
]
}
7 changes: 7 additions & 0 deletions layers/oci8/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
db:
image: container-registry.oracle.com/database/free:latest-lite
ports:
- "1521:1521"
environment:
- ORACLE_PWD=testing
39 changes: 38 additions & 1 deletion layers/oci8/test.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,45 @@
<?php

if (!function_exists($func = 'oci_connect')) {
if (! extension_loaded('oci8')) {
echo 'FAIL: Extension "oci8" is not loaded.'.PHP_EOL;
exit(1);
}

if (! function_exists($func = 'oci_connect')) {
echo sprintf('FAIL: Function "%s" does not exist.', $func).PHP_EOL;
exit(1);
}

$clientVersion = oci_client_version();
if (empty($clientVersion) || $clientVersion === '0.0.0.0.0') {
echo 'FAIL: Extension loaded, but can\'t find Oracle Instant Client libraries.'.PHP_EOL;
exit(1);
}

// Test live connection assuming db container is started (see docker-compose.yml for example).
// You may need to add --add-host=host.docker.internal:host-gateway to Makefile test: docker run if
// you are on Linux
/*
$conn = oci_connect('SYSTEM', 'testing', 'host.docker.internal/FREE');
if (! $conn) {
echo 'FAIL: Can\'t connect to Oracle database: '.oci_error()['message'].PHP_EOL;
exit(1);
}

$stid = oci_parse($conn, 'SELECT 1 FROM DUAL');
if (! $stid) {
echo 'FAIL: Can\'t parse SQL statement: '.oci_error($conn)['message'].PHP_EOL;
oci_close($conn);
exit(1);
}

if (! oci_execute($stid)) {
echo 'FAIL: Can\'t execute SQL statement: '.oci_error($conn)['message'].PHP_EOL;
oci_close($conn);
exit(1);
}
$stid = null;
oci_close($conn);
*/

exit(0);
Loading