Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Dockerfile and add some dependencies #44

Open
wants to merge 7 commits into
base: 7.1-stretch
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git/*
# Swap files (vim)
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Temporary files including undo
*~
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Swap files (vim)
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Temporary files including undo
*~
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ install:
- docker build -t moodle-php-apache .
script:
- "docker run --name test0 -d -p 8000:80 -v $PWD/tests/fixtures:/var/www/html moodle-php-apache"
- sleep 5
- docker exec test0 php /var/www/html/test.php
- curl --fail http://127.0.0.1:8000/test.php
after_failure:
Expand Down
38 changes: 27 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
FROM php:7.1-apache-stretch

ADD root/ /
# Fix the original permissions of /tmp, the PHP default upload tmp dir.
RUN chmod 777 /tmp && chmod +t /tmp

# Setup the required extensions.
ARG DEBIAN_FRONTEND=noninteractive
RUN /tmp/setup/php-extensions.sh
RUN /tmp/setup/oci8-extension.sh

# Install NVM and the current (as of 26/02/2019) LTS version of Node.
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION lts/carbon
RUN mkdir -p $NVM_DIR && \
andrewnicols marked this conversation as resolved.
Show resolved Hide resolved
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash && \
. $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION

# Install the standard PHP extensions.
ADD root/tmp/setup/php-extensions.sh /tmp/setup/
RUN chmod 777 /tmp && chmod +t /tmp && \
/tmp/setup/php-extensions.sh
ADD nvm-wrapper /usr/local/bin/nvm

# Install the PHP MSSQL Extension.
ADD root/tmp/setup/mssql-extension.sh /tmp/setup/
RUN chmod 777 /tmp && chmod +t /tmp && \
/tmp/setup/mssql-extension.sh

# Install the PHP OCI8 Extension.
ENV LD_LIBRARY_PATH /usr/local/instantclient
ADD root/tmp/setup/oci8-extension.sh /tmp/setup/
RUN chmod 777 /tmp && chmod +t /tmp && \
/tmp/setup/oci8-extension.sh

RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \
mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \
mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \
mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps
# Set the custom entrypoint.
ADD moodle-php-entrypoint /usr/local/bin/
ENTRYPOINT ["moodle-php-entrypoint"]
andrewnicols marked this conversation as resolved.
Show resolved Hide resolved
CMD ["apache2-foreground"]
41 changes: 41 additions & 0 deletions moodle-php-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
set -Eeo pipefail

ARGS="$@"

# Create directories for general usage.
mkdir /var/www/moodledata && chown www-data:www-data /var/www/moodledata
mkdir /var/www/phpunitdata && chown www-data:www-data /var/www/phpunitdata
mkdir /var/www/behatdata && chown www-data:www-data /var/www/behatdata
mkdir /var/www/behatfaildumps && chown www-data:www-data /var/www/behatfaildumps

# Ensure that all users get NVM as standard.
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> /etc/bash.bashrc
echo 'export NODE_REPL_HISTORY=' >> /etc/bash.bashrc
mkdir /var/www/.config && chown www-data:www-data /var/www/.config

# Ensure that the requested version of node is installed.
source $NVM_DIR/nvm.sh && nvm install $NODE_VERSION && nvm use --delete-prefix $NODE_VERSION
echo 'nvm use "$NODE_VERSION"' >> /etc/bash.bashrc

# Load any additional entrypoint init files.
for f in /docker-entrypoint-initdb.d/*; do
case "$f" in
*.sh)
# https://github.com/docker-library/postgres/issues/450#issuecomment-393167936
# https://github.com/docker-library/postgres/pull/452
if [ -x "$f" ]; then
echo "$0: running $f"
"$f"
else
echo "$0: sourcing $f"
. "$f"
fi
;;
*) echo "$0: ignoring $f" ;;
esac
echo
done

# Execute the original entrypoint with the original args.
exec docker-php-entrypoint $ARGS
13 changes: 13 additions & 0 deletions nvm-wrapper
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -Eeo pipefail

# This is a wrapper around NVM to load the nvm functions, and then run nvm.

if [ -z "$(LC_ALL=C type -t nvm)" ] || [ "$(LC_ALL=C type -t nvm)" != function ]
then
# The `nvm` variable does not exist, or is not a function.
# Source nvm.sh to load it.
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
fi

nvm $@
25 changes: 25 additions & 0 deletions root/tmp/setup/mssql-extension.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

set -e

BUILD_PACKAGES="gnupg unixodbc-dev"

apt-get update
apt-get install -y --no-install-recommends apt-transport-https \
$BUILD_PACKAGES

# Install Microsoft dependcies for sqlsrv.
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/debian/9/prod.list -o /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install -y msodbcsql17

pecl install sqlsrv
docker-php-ext-enable sqlsrv

# Keep our image size down..
pecl clear-cache
apt-get remove --purge -y $BUILD_PACKAGES
apt-get autoremove -y
apt-get clean
rm -rf /var/lib/apt/lists/*
3 changes: 3 additions & 0 deletions root/tmp/setup/oci8-extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus

echo 'instantclient,/usr/local/instantclient' | pecl install oci8 && docker-php-ext-enable oci8
echo 'oci8.statement_cache_size = 0' >> /usr/local/etc/php/conf.d/docker-php-ext-oci8.ini

# Keep our image size down.
pecl clear-cache
17 changes: 6 additions & 11 deletions root/tmp/setup/php-extensions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ echo "Installing apt dependencies"
# Build packages will be added during the build, but will be removed at the end.
BUILD_PACKAGES="gettext gnupg libcurl4-openssl-dev libfreetype6-dev libicu-dev libjpeg62-turbo-dev \
libldap2-dev libmariadbclient-dev libmemcached-dev libpng-dev libpq-dev libxml2-dev libxslt-dev \
unixodbc-dev zlib1g-dev"
zlib1g-dev"

# Packages for Postgres.
PACKAGES_POSTGRES="libpq5"
Expand All @@ -18,6 +18,9 @@ PACKAGES_MYMARIA="libmariadbclient18"
# Packages for other Moodle runtime dependenices.
PACKAGES_RUNTIME="ghostscript libaio1 libcurl3 libgss3 libicu57 libmcrypt-dev libxml2 libxslt1.1 locales sassc unzip unixodbc sassc"

# Packages required for moodle-local_ci.
PACKAGES_CI="git"

# Packages for Memcached.
PACKAGES_MEMCACHED="libmemcached11 libmemcachedutil2"

Expand All @@ -31,7 +34,8 @@ apt-get install -y --no-install-recommends apt-transport-https \
$PACKAGES_MYMARIA \
$PACKAGES_RUNTIME \
$PACKAGES_MEMCACHED \
$PACKAGES_LDAP
$PACKAGES_LDAP \
$PACKAGES_CI

# Generate the locales configuration fo rboth Australia, and the US.
echo 'Generating locales..'
Expand Down Expand Up @@ -64,15 +68,6 @@ docker-php-ext-enable solr memcached redis apcu igbinary

echo 'apc.enable_cli = On' >> /usr/local/etc/php/conf.d/docker-php-ext-apcu.ini

# Install Microsoft dependcies for sqlsrv.
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/debian/9/prod.list -o /etc/apt/sources.list.d/mssql-release.list
apt-get update
ACCEPT_EULA=Y apt-get install -y msodbcsql17

pecl install sqlsrv
docker-php-ext-enable sqlsrv

# Keep our image size down..
pecl clear-cache
apt-get remove --purge -y $BUILD_PACKAGES
Expand Down