Skip to content
Draft
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
79 changes: 79 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
50 changes: 50 additions & 0 deletions application/classes/beans/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php defined('SYSPATH') or die('No direct access allowed.');

return array (
'sha_hash' => 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'),
),
),
),
);
19 changes: 19 additions & 0 deletions docker-php-ext-configure
Original file line number Diff line number Diff line change
@@ -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 "$@"
63 changes: 63 additions & 0 deletions docker-php-ext-enable
Original file line number Diff line number Diff line change
@@ -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
47 changes: 47 additions & 0 deletions docker-php-ext-install
Original file line number Diff line number Diff line change
@@ -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