How to Build Your Own Openshift Builder Image (PHP 5.6 with oci, pdo_oci, rfc)


This post is written to show how to build Openshift PHP builder image that are using Oracle database connections, specifically using PDO-OCI extension. OCI8 connection is also being prepared. 

Checkout 

The git repository I prepared in github have a branch for our specific purpose : 'pdo_oci8'

aws@broker ~ $ git clone https://github.com/yudhiwidyatama/s2i-php-container.git


aws@broker ~ $ cd s2i-php-container/

aws@broker s2i-php-container $ git checkout pdo_oci8
Branch pdo_oci8 set up to track remote branch pdo_oci8 from origin.
Switched to a new branch 'pdo_oci8'

Checking the 5.6/root directory, there is a file that shows the required Oracle instant client rpm files. 

aws@broker s2i-php-container $ cd 5.6
aws@broker 5.6 $ cd root

aws@broker root $ ls
opt  stage1.list.txt
aws@broker root $ cat stage1.list.txt 
-rw-r--r-- 1 root root 62587782 Oct 29 11:40 oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
-rw-r--r-- 1 root root   634803 Oct 29 11:38 oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
-rw-r--r-- 1 root root   852271 Oct 29 11:38 oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

Then we need to download instant client from oracle. This is complicated by Oracle insisting us to sign-in using OTN Account. Open your browser and point to "https://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html", click on "Instant Client for Linux x86-64".

Click Accept License Agreement, then proceed to click the required rpm files (basic, devel, and sqlplus for 12.1.0.2 version).  Do a dummy download using your browser (at this point Oracle would ask for your Oracle Account / OTN login, which we could request at no charge) and then copying the Link Address from browser, so we could use the Link Address URL in our wget commands.

The Url is obtainable from the Chrome's Downloads menu. Right click and choose 'Copy Link Address'.

Create another 'root' under the 'root' directory. Paste the URL between quotes to wget, and rename to take out AuthParam in the resulting file :

aws@broker root $ mkdir root
aws@broker root $ cd root
aws@broker root $ ls
aws@broker root $ pwd
/home/aws/s2i-php-container/5.6/root/root

aws@broker root $ wget "https://download.oracle.com/otn/linux/instantclient/121020/oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542707896_f8e27ebee187829c54ba8692f79d720c"
--2018-11-20 16:56:51--  https://download.oracle.com/otn/linux/instantclient/121020/oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542707896_f8e27ebee187829c54ba8692f79d720c
Resolving download.oracle.com... 104.93.96.131
Connecting to download.oracle.com|104.93.96.131|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 62587782 (60M) [application/x-redhat-package-manager]
Saving to: “oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542707896_f8e27ebee187829c54ba8692f79d720c”

100%[===================================================================================================================================>] 62,587,782  33.7M/s   in 1.8s    

2018-11-20 16:56:53 (33.7 MB/s) - “oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542707896_f8e27ebee187829c54ba8692f79d720c” saved [62587782/62587782]

aws@broker root $ mv oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm\?AuthParam\=1542707896_f8e27ebee187829c54ba8692f79d720c oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
aws@broker root $ wget "https://download.oracle.com/otn/linux/instantclient/121020/oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542707982_0f69007df1efaa246b884e175eb1e7b9"
--2018-11-20 16:58:23--  https://download.oracle.com/otn/linux/instantclient/121020/oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542707982_0f69007df1efaa246b884e175eb1e7b9
Resolving download.oracle.com... 104.93.96.131
Connecting to download.oracle.com|104.93.96.131|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 634803 (620K) [application/x-redhat-package-manager]
Saving to: “oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542707982_0f69007df1efaa246b884e175eb1e7b9”

100%[===================================================================================================================================>] 634,803     --.-K/s   in 0.04s   

2018-11-20 16:58:23 (14.8 MB/s) - “oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542707982_0f69007df1efaa246b884e175eb1e7b9” saved [634803/634803]

aws@broker root $ mv oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm\?AuthParam\=1542707982_0f69007df1efaa246b884e175eb1e7b9 oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
aws@broker root $ wget "https://download.oracle.com/otn/linux/instantclient/121020/oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542708072_4faad0ac9a5562e854f08cadee1d87a8"
--2018-11-20 16:59:30--  https://download.oracle.com/otn/linux/instantclient/121020/oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542708072_4faad0ac9a5562e854f08cadee1d87a8
Resolving download.oracle.com... 104.93.96.131
Connecting to download.oracle.com|104.93.96.131|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 852271 (832K) [application/x-redhat-package-manager]
Saving to: “oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542708072_4faad0ac9a5562e854f08cadee1d87a8”

100%[===================================================================================================================================>] 852,271     --.-K/s   in 0.04s   

2018-11-20 16:59:30 (19.1 MB/s) - “oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm?AuthParam=1542708072_4faad0ac9a5562e854f08cadee1d87a8” saved [852271/852271]

aws@broker root $ mv oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm\?AuthParam\=1542708072_4faad0ac9a5562e854f08cadee1d87a8 oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

Building

Check the rpm files :
aws@broker root $ ls
oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm  oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm  oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

Proceed with building process :

aws@broker root $ cd ..
aws@broker root $ cd ..
aws@broker 5.6 $ pwd
/home/aws/s2i-php-container/5.6
aws@broker 5.6 $  docker build -t s2i-php56-pdooci .
Sending build context to Docker daemon 64.92 MB
Sending build context to Docker daemon 
Step 0 : FROM centos/s2i-base-centos7
 ---> ff41d164f277
Step 1 : EXPOSE 8080
 ---> Using cache
 ---> da1f2520288f
Step 2 : ENV PHP_VERSION 5.6 PATH $PATH:/opt/rh/rh-php56/root/usr/bin
 ---> Using cache
 ---> f944130c7708
Step 3 : ENV SUMMARY "Platform for building and running PHP $PHP_VERSION applications" DESCRIPTION "PHP $PHP_VERSION available as docker container is a base platform for building and running various PHP $PHP_VERSION applications and frameworks. PHP is an HTML-embedded scripting language. PHP attempts to make it easy for developers to write dynamically generated web pages. PHP also offers built-in database integration for several commercial and non-commercial database management systems, so writing a database-enabled webpage with PHP is fairly simple. The most common use of PHP coding is probably as a replacement for CGI scripts."
 ---> Using cache
 ---> 247b1e7eeb1b
...
Step 16 : RUN sed -i -f /opt/app-root/etc/httpdconf.sed /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf &&     echo "IncludeOptional /opt/app-root/etc/conf.d/*.conf" >> /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf &&     sed -i '/php_value session.save_path/d' /opt/rh/httpd24/root/etc/httpd/conf.d/rh-php56-php.conf &&     head -n151 /opt/rh/httpd24/root/etc/httpd/conf/httpd.conf | tail -n1 | grep "AllowOverride All" || exit &&     mkdir /tmp/sessions &&     chown -R 1001:0 /opt/app-root /tmp/sessions &&     chmod -R a+rwx /tmp/sessions &&     chmod -R ug+rwx /opt/app-root &&     chmod -R a+rwx /etc/opt/rh/rh-php56 &&     chmod -R a+rwx /opt/rh/httpd24/root/var/run/httpd
 ---> Running in e877a82cbebd
    AllowOverride All
 ---> 94bbfa64540a
Removing intermediate container e877a82cbebd
Step 17 : USER 1001
 ---> Running in b573ed446725
 ---> f11275cfcbe4
Removing intermediate container b573ed446725
Step 18 : CMD $STI_SCRIPTS_PATH/usage
 ---> Running in 84fd15f0d378
 ---> 27ab6f7675d2
Removing intermediate container 84fd15f0d378
Successfully built 27ab6f7675d2

Publishing to Docker Hub

Next step we tag and  publish the image:
aws@broker 5.6 $ docker tag s2i-php56-pdooci yudhiwidyatama/s2i-php56-pdooci:201801
aws@broker 5.6 $ docker push yudhiwidyatama/s2i-php56-pdooci:201801
The push refers to a repository [yudhiwidyatama/s2i-php56-pdooci] (len: 1)
27ab6f7675d2: Image already exists 
f11275cfcbe4: Image successfully pushed 
94bbfa64540a: Image successfully pushed 
47fb29191938: Image successfully pushed 
892ec8a5ac86: Image successfully pushed 
d633eb1d08f2: Image successfully pushed 
80831f5d7bb9: Image successfully pushed 
647b25811b6a: Image successfully pushed 
4049a4cf7897: Image successfully pushed 
eee73b56a072: Image successfully pushed 
beefd8a9f746: Image successfully pushed 
cdba5a3f763b: Image successfully pushed 
72906bd3915f: Image successfully pushed 
e071aabb7f3d: Image successfully pushed 
8a7c8fc193ee: Image already exists 
247b1e7eeb1b: Image already exists 
f944130c7708: Image already exists 
da1f2520288f: Image already exists 
ff41d164f277: Image already exists 
59c89aefca2f: Image successfully pushed 
c5013bcc9b43: Image already exists 
bb83746f161c: Image already exists 
c240b147d043: Image already exists 
581d3e9fafdb: Image successfully pushed 
3fa399969e3d: Image already exists 
3f12a77fa51e: Image already exists 
78d20169a434: Image already exists 
53a0573f2c8c: Image successfully pushed 
69852c4e3982: Image successfully pushed 
c8fa6e2ee625: Image already exists 
4d20e7d02f9a: Image already exists 
cc56be4d597b: Image already exists 
4b21f2a7e518: Image already exists 
9cc5960c49d3: Image already exists 
eb72e5beea78: Image already exists 
3993223e10aa: Image successfully pushed 
Digest: sha256:045bb0077acd4a910837955c2a676fb0985b84dca7db1f877c96dfd7813559eb

The image pushed successfully to Docker hub.

The hard part

Now I will try to describe the Dockerfile modifications (line 48-60).

First install the oracle instant client rpms and iproute :
# PDO_OCI, OCI8 extensions
RUN yum install -y iproute /root/oracle-instantclient12* && yum clean all -y && rm -rf /root/oracle-instantclient12*

Next copy the oci8 extension into modules directory :
COPY ./oci8.so /opt/rh/rh-php56/root/usr/lib64/php/modules/
The pdo_oci rpm also need to be copied and installed
COPY ./rh-php56-php-pdo_oci-5.6.25-1.el7.centos.x86_64.rpm /opt/app-root/

RUN rpm -ivh /opt/app-root/rh-php56-php-pdo_oci-5.6.25-1.el7.centos.x86_64.rpm
Oracle client library somehow not installed in the system, add the library by creating oracle12.conf file :
RUN echo "/usr/lib/oracle/12.1/client64/lib" > /etc/ld.so.conf.d/oracle12.conf 
RUN ldconfig 
Install the oci8 extension INI (the PDO_OCI already installed in the RPM, I think)

RUN echo "extension=oci8.so" > /opt/rh/rh-php56/root/etc/php.d/20-oci8.ini

The harder part is how to create the oci8.so and pdo_oci rpm, which would be described in  another post..


Comments

Popular posts from this blog

Long running process in Linux using PHP

Reverse Engineering Reptile Kernel module to Extract Authentication code

SAP System Copy Lessons Learned