Skip to content

Commit 0de9fae

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 0de9fae

File tree

3 files changed

+37
-13
lines changed

3 files changed

+37
-13
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: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
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=""
15+
16+
echo "Installing apt dependencies"
17+
apt-get update
18+
apt-get install -y --no-install-recommends apt-transport-https \
19+
$BUILD_PACKAGES \
20+
$PACKAGES_SQLSRV
21+
522
# Install Microsoft dependencies for sqlsrv
623
echo "Downloading sqlsrv files"
724
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
@@ -17,3 +34,10 @@ ln -fsv /opt/mssql-tools/bin/* /usr/bin
1734
# Need 5.10.1 (or later) for PHP 8.2 support
1835
pecl install sqlsrv-5.10.1
1936
docker-php-ext-enable sqlsrv
37+
38+
# Keep our image size down..
39+
pecl clear-cache
40+
apt-get remove --purge -y $BUILD_PACKAGES
41+
apt-get autoremove -y
42+
apt-get clean
43+
rm -rf /var/lib/apt/lists/*

0 commit comments

Comments
 (0)