From 2f92728a9fc85305f167f2cde0357b81560b200f Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Tue, 6 Apr 2021 16:57:50 -0600 Subject: [PATCH] add needed files for docker build --- Dockerfile | 79 ++++++++++++++++++++++++++++ application/classes/beans/config.php | 50 ++++++++++++++++++ docker-php-ext-configure | 19 +++++++ docker-php-ext-enable | 63 ++++++++++++++++++++++ docker-php-ext-install | 47 +++++++++++++++++ 5 files changed, 258 insertions(+) create mode 100644 Dockerfile create mode 100644 application/classes/beans/config.php create mode 100644 docker-php-ext-configure create mode 100644 docker-php-ext-enable create mode 100644 docker-php-ext-install diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3affaef --- /dev/null +++ b/Dockerfile @@ -0,0 +1,79 @@ +# Dockerfile +# Because php5.6 is old and sucks to do stuff with. +# Stolen from the now deprecated and removed php docker repo @ +# https://github.com/docker-library/php/blob/995bf17c9ded3d622f6b9efb902756562538ab13/5.4/Dockerfile + +FROM debian:jessie + +# persistent / runtime deps +RUN apt-get update && apt-get install -y ca-certificates curl librecode0 libsqlite3-0 libxml2 --no-install-recommends && rm -r /var/lib/apt/lists/* + +# phpize deps +RUN apt-get update && apt-get install -y autoconf file g++ gcc libc-dev make pkg-config re2c --no-install-recommends && rm -r /var/lib/apt/lists/* + +ENV PHP_INI_DIR /usr/local/etc/php +RUN mkdir -p $PHP_INI_DIR/conf.d + +ENV GPG_KEYS F38252826ACD957EF380D39F2F7956BC5DA04B5D +RUN set -xe \ + && for key in $GPG_KEYS; do \ + gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \ + done + +ENV PHP_VERSION 5.4.45 + +# --enable-mysqlnd is included below because it's harder to compile after the fact the extensions are (since it's a plugin for several extensions, not an extension in itself) +RUN buildDeps=" \ + $PHP_EXTRA_BUILD_DEPS \ + bzip2 \ + libcurl4-openssl-dev \ + libreadline6-dev \ + librecode-dev \ + libsqlite3-dev \ + libssl-dev \ + libxml2-dev \ + " \ + && set -x \ + && apt-get update && apt-get install -y $buildDeps --no-install-recommends && rm -rf /var/lib/apt/lists/* \ + && curl -SL "http://php.net/get/php-$PHP_VERSION.tar.bz2/from/this/mirror" -o php.tar.bz2 \ + && curl -SL "http://php.net/get/php-$PHP_VERSION.tar.bz2.asc/from/this/mirror" -o php.tar.bz2.asc \ + && gpg --verify php.tar.bz2.asc \ + && mkdir -p /usr/src/php \ + && tar -xof php.tar.bz2 -C /usr/src/php --strip-components=1 \ + && rm php.tar.bz2* \ + && cd /usr/src/php \ + && ./configure \ + --with-config-file-path="$PHP_INI_DIR" \ + --with-config-file-scan-dir="$PHP_INI_DIR/conf.d" \ + $PHP_EXTRA_CONFIGURE_ARGS \ + --disable-cgi \ + --enable-mysqlnd \ + --with-curl \ + --with-mysql \ + --with-mysqli \ + --with-openssl \ + --with-readline \ + --with-recode \ + --with-zlib \ + && make -j"$(nproc)" \ + && make install \ + && { find /usr/local/bin /usr/local/sbin -type f -executable -exec strip --strip-all '{}' + || true; } \ + && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false -o APT::AutoRemove::SuggestsImportant=false $buildDeps \ + && make clean + +COPY docker-php-ext-* /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-php-* + +# Install all the beansbooks extensions +RUN apt-get update && apt-get install -y \ + libfreetype6-dev \ + libjpeg62-turbo-dev \ + libmcrypt-dev \ + libpng-dev \ + --no-install-recommends && rm -r /var/lib/apt/lists/* + +RUN docker-php-ext-install mcrypt mysql mysqli pdo pdo_mysql gd + +COPY . /beansbooks +EXPOSE 80 +CMD ["php", "-d", "KOHANA_ENV=PRODUCTION", "-S", "0.0.0.0:80", "-t", "/beansbooks"] diff --git a/application/classes/beans/config.php b/application/classes/beans/config.php new file mode 100644 index 0000000..415ab38 --- /dev/null +++ b/application/classes/beans/config.php @@ -0,0 +1,50 @@ + getenv('BEANS_SHA_HASH'), + 'sha_salt' => getenv('BEANS_SHA_SALT'), + 'cookie_salt' => getenv('BEANS_COOKIE_SALT'), + 'modules' => + array ( + 'encrypt' => + array ( + 'default' => + array ( + 'key' => getenv('BEANS_ENCRYPT_KEY'), + 'cipher' => 'rijndael-128', + 'mode' => 'nofb', + ), + ), + 'database' => + array ( + 'default' => + array ( + 'type' => 'mysql', + 'connection' => + array ( + 'hostname' => getenv('BEANS_DB_HOST'), + 'database' => getenv('BEANS_DB_NAME'), + 'username' => getenv('BEANS_DB_USERNAME'), + 'password' => getenv('BEANS_DB_PASSWORD'), + 'persistent' => false, + ), + 'table_prefix' => '', + 'charset' => 'utf8', + 'caching' => true, + 'profiling' => false, + ), + ), + 'email' => + array ( + 'driver' => 'smtp', + 'options' => + array ( + 'hostname' => getenv('BEANS_EMAIL_HOST'), + 'port' => getenv('BEANS_EMAIL_PORT'), + 'username' => getenv('BEANS_EMAIL_USERNAME'), + 'password' => getenv('BEANS_EMAIL_PASSWORD'), + 'encryption' => getenv('BEANS_EMAIL_ENCRYPTION'), + ), + ), + ), +); diff --git a/docker-php-ext-configure b/docker-php-ext-configure new file mode 100644 index 0000000..3d21b5b --- /dev/null +++ b/docker-php-ext-configure @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +ext="$1" +extDir="/usr/src/php/ext/$ext" +if [ -z "$ext" -o ! -d "$extDir" ]; then + echo >&2 "usage: $0 ext-name [configure flags]" + echo >&2 " ie: $0 gd --with-jpeg-dir=/usr/local/something" + echo >&2 + echo >&2 'Possible values for ext-name:' + echo >&2 $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort) + exit 1 +fi +shift + +set -x +cd "$extDir" +phpize +./configure "$@" diff --git a/docker-php-ext-enable b/docker-php-ext-enable new file mode 100644 index 0000000..f84e955 --- /dev/null +++ b/docker-php-ext-enable @@ -0,0 +1,63 @@ +#!/bin/bash +set -e + +cd "$(php -r 'echo ini_get("extension_dir");')" + +usage() { + echo "usage: $0 module-name [module-name ...]" + echo " ie: $0 gd mysqli" + echo " $0 pdo pdo_mysql" + echo + echo 'Possible values for module-name:' + echo $(find -maxdepth 1 -type f -name '*.so' -exec basename '{}' ';' | sort) +} + +modules=() +while [ $# -gt 0 ]; do + module="$1" + shift + if [ -z "$module" ]; then + continue + fi + if [ -f "$module.so" -a ! -f "$module" ]; then + # allow ".so" to be optional + module+='.so' + fi + if [ ! -f "$module" ]; then + echo >&2 "error: $(readlink -f "$module") does not exist" + echo >&2 + usage >&2 + exit 1 + fi + modules+=( "$module" ) +done + +if [ "${#modules[@]}" -eq 0 ]; then + usage >&2 + exit 1 +fi + +for module in "${modules[@]}"; do + if grep -q zend_extension_entry "$module"; then + # https://wiki.php.net/internals/extensions#loading_zend_extensions + line="zend_extension=$(readlink -f "$module")" + else + line="extension=$module" + fi + + ext="$(basename "$module")" + ext="${ext%.*}" + if php -r 'exit(extension_loaded("'"$ext"'") ? 0 : 1);'; then + # this isn't perfect, but it's better than nothing + # (for example, 'opcache.so' presents inside PHP as 'Zend OPcache', not 'opcache') + echo >&2 + echo >&2 "warning: $ext ($module) is already loaded!" + echo >&2 + continue + fi + + ini="/usr/local/etc/php/conf.d/docker-php-ext-$ext.ini" + if ! grep -q "$line" "$ini" 2>/dev/null; then + echo "$line" >> "$ini" + fi +done diff --git a/docker-php-ext-install b/docker-php-ext-install new file mode 100644 index 0000000..70dcf14 --- /dev/null +++ b/docker-php-ext-install @@ -0,0 +1,47 @@ +#!/bin/bash +set -e + +cd /usr/src/php/ext + +usage() { + echo "usage: $0 ext-name [ext-name ...]" + echo " ie: $0 gd mysqli" + echo " $0 pdo pdo_mysql" + echo + echo 'if custom ./configure arguments are necessary, see docker-php-ext-configure' + echo + echo 'Possible values for ext-name:' + echo $(find /usr/src/php/ext -mindepth 2 -maxdepth 2 -type f -name 'config.m4' | cut -d/ -f6 | sort) +} + +exts=() +while [ $# -gt 0 ]; do + ext="$1" + shift + if [ -z "$ext" ]; then + continue + fi + if [ ! -d "$ext" ]; then + echo >&2 "error: $(pwd -P)/$ext does not exist" + echo >&2 + usage >&2 + exit 1 + fi + exts+=( "$ext" ) +done + +if [ "${#exts[@]}" -eq 0 ]; then + usage >&2 + exit 1 +fi + +for ext in "${exts[@]}"; do + ( + cd "$ext" + [ -e Makefile ] || docker-php-ext-configure "$ext" + make + make install + find modules -maxdepth 1 -name '*.so' -exec basename '{}' ';' | xargs --no-run-if-empty --verbose docker-php-ext-enable + make clean + ) +done