Skip to content

Commit 48c6827

Browse files
committed
Streamline the build of the image
This change makes it much faster to make smaller changes to the image by: - moving the ADD commands to more targeted additions in order of build size - breaking out the Oracle and sqlsrv builds into their own ADD and RUN sections in the Dockerfile - moving the addition of non build-related files to right at the end of the Dockerfile These changes mean that it is possible to more easily developer the image, for example: - you can now make changes to files within the /usr directory without recompiling all PHP extensions - you can now iterate on the Oracle and/or sqlsrv extensions without recompiling all PHP extensinos - you can now iterate on the sqlsrv extension, without recompiling all PHP extensions Whist this has little effect on the end image, or the build process within CI systems, local development is substantially improved (unless you're making changes to the php-extensions.sh script).
1 parent a5411f6 commit 48c6827

File tree

3 files changed

+41
-15
lines changed

3 files changed

+41
-15
lines changed

Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ ARG TARGETPLATFORM
55
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
66
RUN echo "Building for ${TARGETPLATFORM}"
77

8-
ADD root/ /
9-
# Fix the original permissions of /tmp, the PHP default upload tmp dir.
10-
RUN chmod 777 /tmp && chmod +t /tmp
11-
128
# Install some packages that are useful within the images.
139
RUN apt-get update && apt-get install -y \
1410
git \
@@ -30,11 +26,24 @@ RUN apt-get update && apt-get install -y \
3026

3127
# Setup the required extensions.
3228
ARG DEBIAN_FRONTEND=noninteractive
29+
ADD root/tmp/setup/php-extensions.sh /tmp/setup/php-extensions.sh
3330
RUN /tmp/setup/php-extensions.sh
31+
32+
# Install Oracle Instantclient
33+
ADD root/tmp/setup/oci8-extension.sh /tmp/setup/oci8-extension.sh
3434
RUN /tmp/setup/oci8-extension.sh
3535
ENV LD_LIBRARY_PATH /usr/local/instantclient
3636

37+
# Install Microsoft sqlsrv.
38+
ADD root/tmp/setup/sqlsrv-extension.sh /tmp/setup/sqlsrv-extension.sh
39+
RUN /tmp/setup/sqlsrv-extension.sh
40+
3741
RUN mkdir /var/www/moodledata && chown www-data /var/www/moodledata && \
3842
mkdir /var/www/phpunitdata && chown www-data /var/www/phpunitdata && \
3943
mkdir /var/www/behatdata && chown www-data /var/www/behatdata && \
4044
mkdir /var/www/behatfaildumps && chown www-data /var/www/behatfaildumps
45+
46+
ADD root/usr /usr
47+
48+
# Fix the original permissions of /tmp, the PHP default upload tmp dir.
49+
RUN chmod 777 /tmp && chmod +t /tmp

root/tmp/setup/php-extensions.sh

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ echo "Installing apt dependencies"
77
# Build packages will be added during the build, but will be removed at the end.
88
BUILD_PACKAGES="gettext gnupg libcurl4-openssl-dev libfreetype6-dev libicu-dev libjpeg62-turbo-dev \
99
libldap2-dev libmariadb-dev libmemcached-dev libpng-dev libpq-dev libxml2-dev libxslt-dev \
10-
unixodbc-dev uuid-dev"
10+
uuid-dev"
1111

1212
# Packages for Postgres.
1313
PACKAGES_POSTGRES="libpq5"
@@ -17,7 +17,7 @@ PACKAGES_MYMARIA="libmariadb3"
1717

1818
# Packages for other Moodle runtime dependenices.
1919
PACKAGES_RUNTIME="ghostscript libaio1 libcurl4 libgss3 libicu67 libmcrypt-dev libxml2 libxslt1.1 \
20-
libzip-dev locales sassc unixodbc unzip zip"
20+
libzip-dev locales sassc unzip zip"
2121

2222
# Packages for Memcached.
2323
PACKAGES_MEMCACHED="libmemcached11 libmemcachedutil2"
@@ -74,15 +74,6 @@ echo "pcov.exclude='~\/(tests|coverage|vendor|node_modules)\/~'" >> /usr/local/e
7474
echo "pcov.directory=." >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
7575
echo "pcov.initial.files=1024" >> /usr/local/etc/php/conf.d/docker-php-ext-pcov.ini
7676

77-
# Install Microsoft dependencies for sqlsrv.
78-
# (kept apart for clarity, still need to be run here
79-
# before some build packages are deleted)
80-
if [[ ${TARGETPLATFORM} == "linux/amd64" ]]; then
81-
/tmp/setup/sqlsrv-extension.sh
82-
else
83-
echo "sqlsrv extension not available for ${TARGETPLATFORM} architecture, skipping"
84-
fi
85-
8677
# Keep our image size down..
8778
pecl clear-cache
8879
apt-get remove --purge -y $BUILD_PACKAGES

root/tmp/setup/sqlsrv-extension.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22

33
set -e
44

5+
if [[ ${TARGETPLATFORM} != "linux/amd64" ]]; then
6+
echo "sqlsrv extension not available for ${TARGETPLATFORM} architecture, skipping"
7+
exit 0
8+
fi
9+
10+
# Packages for build.
11+
BUILD_PACKAGES="gnupg unixodbc-dev"
12+
13+
# Packages for sqlsrv runtime.
14+
PACKAGES_SQLSRV="unixodbc"
15+
16+
# Note: These dependencies must be installed before installing the Microsoft source because there is a package in there
17+
# which breaks the install.
18+
echo "Installing apt dependencies"
19+
apt-get update
20+
apt-get install -y --no-install-recommends apt-transport-https \
21+
$BUILD_PACKAGES \
22+
$PACKAGES_SQLSRV
23+
524
# Install Microsoft dependencies for sqlsrv
625
echo "Downloading sqlsrv files"
726
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
@@ -17,3 +36,10 @@ ln -fsv /opt/mssql-tools/bin/* /usr/bin
1736
# Need 5.10.1 (or later) for PHP 8.2 support
1837
pecl install sqlsrv-5.10.1
1938
docker-php-ext-enable sqlsrv
39+
40+
# Keep our image size down..
41+
pecl clear-cache
42+
apt-get remove --purge -y $BUILD_PACKAGES
43+
apt-get autoremove -y
44+
apt-get clean
45+
rm -rf /var/lib/apt/lists/*

0 commit comments

Comments
 (0)