|
| 1 | +FROM ymir/runtime/base as php-build |
| 2 | + |
| 3 | + |
| 4 | +############################################################################### |
| 5 | +# Oniguruma |
| 6 | +# This library is not packaged in PHP since PHP 7.4. |
| 7 | +# See https://github.com/php/php-src/blob/43dc7da8e3719d3e89bd8ec15ebb13f997bbbaa9/UPGRADING#L578-L581 |
| 8 | +# We do not install the system version because I didn't manage to make it work... |
| 9 | +# Ideally we shouldn't compile it ourselves. |
| 10 | +# https://github.com/kkos/oniguruma/releases |
| 11 | +# Needed by: |
| 12 | +# - php mbstring |
| 13 | +ENV VERSION_ONIG=6.9.6 |
| 14 | +ENV ONIG_BUILD_DIR=${BUILD_DIR}/oniguruma |
| 15 | +RUN set -xe; \ |
| 16 | + mkdir -p ${ONIG_BUILD_DIR}; \ |
| 17 | + curl -Ls https://github.com/kkos/oniguruma/releases/download/v${VERSION_ONIG}/onig-${VERSION_ONIG}.tar.gz \ |
| 18 | + | tar xzC ${ONIG_BUILD_DIR} --strip-components=1 |
| 19 | +WORKDIR ${ONIG_BUILD_DIR}/ |
| 20 | +RUN set -xe; \ |
| 21 | + ./configure --prefix=${INSTALL_DIR}; \ |
| 22 | + make -j $(nproc); \ |
| 23 | + make install |
| 24 | + |
| 25 | + |
| 26 | +ENV PHP_BUILD_DIR=${BUILD_DIR}/php |
| 27 | +RUN set -xe; \ |
| 28 | + mkdir -p ${PHP_BUILD_DIR}; \ |
| 29 | +# Download and upack the source code |
| 30 | + curl -Ls https://github.com/php/php-src/archive/php-8.0.10.tar.gz \ |
| 31 | + | tar xzC ${PHP_BUILD_DIR} --strip-components=1 |
| 32 | +# Move into the unpackaged code directory |
| 33 | +WORKDIR ${PHP_BUILD_DIR}/ |
| 34 | + |
| 35 | +# Configure the build |
| 36 | +# -fstack-protector-strong : Be paranoid about stack overflows |
| 37 | +# -fpic : Make PHP's main executable position-independent (improves ASLR security mechanism, and has no performance impact on x86_64) |
| 38 | +# -fpie : Support Address Space Layout Randomization (see -fpic) |
| 39 | +# -O3 : Optimize for fastest binaries possible. |
| 40 | +# -I : Add the path to the list of directories to be searched for header files during preprocessing. |
| 41 | +# --enable-option-checking=fatal: make sure invalid --configure-flags are fatal errors instead of just warnings |
| 42 | +# --enable-ftp: because ftp_ssl_connect() needs ftp to be compiled statically (see https://github.com/docker-library/php/issues/236) |
| 43 | +# --enable-mbstring: because otherwise there's no way to get pecl to use it properly (see https://github.com/docker-library/php/issues/195) |
| 44 | +# --enable-maintainer-zts: build PHP as ZTS (Zend Thread Safe) to be able to use pthreads |
| 45 | +# --with-zlib and --with-zlib-dir: See https://stackoverflow.com/a/42978649/245552 |
| 46 | +# --with-pear: necessary for `pecl` to work (to install PHP extensions) |
| 47 | +# |
| 48 | +RUN set -xe \ |
| 49 | + && ./buildconf --force \ |
| 50 | + && CFLAGS="-fstack-protector-strong -fpic -fpie -O3 -I${INSTALL_DIR}/include -I/usr/include -ffunction-sections -fdata-sections" \ |
| 51 | + CPPFLAGS="-fstack-protector-strong -fpic -fpie -O3 -I${INSTALL_DIR}/include -I/usr/include -ffunction-sections -fdata-sections" \ |
| 52 | + LDFLAGS="-L${INSTALL_DIR}/lib64 -L${INSTALL_DIR}/lib -Wl,-O1 -Wl,--strip-all -Wl,--hash-style=both -pie" \ |
| 53 | + ./configure \ |
| 54 | + --build=x86_64-pc-linux-gnu \ |
| 55 | + --prefix=${INSTALL_DIR} \ |
| 56 | + --enable-option-checking=fatal \ |
| 57 | + --enable-sockets \ |
| 58 | + --with-config-file-path=${INSTALL_DIR}/etc/php \ |
| 59 | + --with-config-file-scan-dir=${INSTALL_DIR}/etc/php/conf.d:/var/task/php/conf.d \ |
| 60 | + --enable-fpm \ |
| 61 | + --disable-cgi \ |
| 62 | + --enable-cli \ |
| 63 | + --disable-phpdbg \ |
| 64 | + --disable-phpdbg-webhelper \ |
| 65 | + --with-sodium \ |
| 66 | + --with-readline \ |
| 67 | + --with-openssl \ |
| 68 | + --with-zlib=${INSTALL_DIR} \ |
| 69 | + --with-zlib-dir=${INSTALL_DIR} \ |
| 70 | + --with-curl \ |
| 71 | + --enable-exif \ |
| 72 | + --enable-ftp \ |
| 73 | + --with-gettext \ |
| 74 | + --enable-mbstring \ |
| 75 | + --with-pdo-mysql=shared,mysqlnd \ |
| 76 | + --with-mysqli \ |
| 77 | + --enable-pcntl \ |
| 78 | + --with-zip \ |
| 79 | + --enable-bcmath \ |
| 80 | + --enable-intl=shared \ |
| 81 | + --enable-soap \ |
| 82 | + --with-xsl=${INSTALL_DIR} \ |
| 83 | + --with-pear |
| 84 | +RUN make -j $(nproc) |
| 85 | +# Run `make install` and override PEAR's PHAR URL because pear.php.net is down |
| 86 | +RUN set -xe; \ |
| 87 | + make install PEAR_INSTALLER_URL='https://github.com/pear/pearweb_phars/raw/master/install-pear-nozlib.phar'; \ |
| 88 | + { find ${INSTALL_DIR}/bin ${INSTALL_DIR}/sbin -type f -perm +0111 -exec strip --strip-all '{}' + || true; }; \ |
| 89 | + make clean; \ |
| 90 | + cp php.ini-production ${INSTALL_DIR}/etc/php/php.ini |
| 91 | + |
| 92 | +# Install extensions using pecl |
| 93 | +RUN pecl install APCu |
| 94 | +RUN pecl install igbinary |
| 95 | +RUN pecl install zstd |
| 96 | + |
| 97 | +# Build extensions |
| 98 | +WORKDIR ${IMAGICK_BUILD_DIR} |
| 99 | +RUN set -xe; \ |
| 100 | + pecl download imagick-${VERSION_IMAGICK_EXTENSION}; \ |
| 101 | + tar xzf imagick-${VERSION_IMAGICK_EXTENSION}.tgz |
| 102 | +WORKDIR ${IMAGICK_BUILD_DIR}/imagick-${VERSION_IMAGICK_EXTENSION} |
| 103 | +RUN set -xe; \ |
| 104 | + phpize; \ |
| 105 | + ./configure --with-imagick=${INSTALL_DIR}; \ |
| 106 | + make -j $(nproc); \ |
| 107 | + make install; |
| 108 | + |
| 109 | +WORKDIR ${REDIS_BUILD_DIR} |
| 110 | +RUN set -xe; \ |
| 111 | + pecl download redis-${VERSION_REDIS_EXTENSION}; \ |
| 112 | + tar xzf redis-${VERSION_REDIS_EXTENSION}.tgz |
| 113 | +WORKDIR ${REDIS_BUILD_DIR}/redis-${VERSION_REDIS_EXTENSION} |
| 114 | +RUN set -xe; \ |
| 115 | + phpize; \ |
| 116 | + ./configure --enable-redis-igbinary --enable-redis-zstd; \ |
| 117 | + make && make install; |
| 118 | + |
| 119 | +# Install Composer |
| 120 | +RUN curl -sS https://getcomposer.org/installer | ${INSTALL_DIR}/bin/php -- --install-dir=${INSTALL_DIR}/bin/ --filename=composer |
| 121 | + |
| 122 | +# Symlink all our binaries into /opt/bin so that Lambda sees them in the path. |
| 123 | +RUN mkdir -p /opt/bin \ |
| 124 | + && cd /opt/bin \ |
| 125 | + && ln -s ../ymir/bin/* . \ |
| 126 | + && ln -s ../ymir/sbin/* . |
| 127 | + |
| 128 | +# Remove extra files to make the layers as slim as possible |
| 129 | +COPY clean.sh /tmp |
| 130 | +RUN /tmp/clean.sh && rm /tmp/clean.sh |
| 131 | + |
| 132 | +# Copy config files |
| 133 | +COPY php.ini ${INSTALL_DIR}/etc/php/conf.d |
| 134 | +COPY php-fpm.conf ${INSTALL_DIR}/etc/php-fpm.d |
| 135 | + |
| 136 | +# Build PHP runtime |
| 137 | +RUN git clone https://github.com/ymirapp/php-runtime.git /tmp/runtime-build \ |
| 138 | + && cd /tmp/runtime-build \ |
| 139 | + && git checkout tags/v1.0.0 \ |
| 140 | + && cd /opt \ |
| 141 | + && cp -R /tmp/runtime-build/composer.json /tmp/runtime-build/composer.lock /tmp/runtime-build/runtime/bootstrap /tmp/runtime-build/runtime/runtime.php /tmp/runtime-build/src ./ \ |
| 142 | + && chmod 0555 /opt/bootstrap /opt/runtime.php \ |
| 143 | + && composer install --no-dev |
| 144 | + |
| 145 | +# Now we start back from a clean image. |
| 146 | +# We get rid of everything that is unnecessary (build tools, source code, and anything else |
| 147 | +# that might have created intermediate layers for docker) by copying online the /opt directory. |
| 148 | +FROM public.ecr.aws/lambda/provided:al2 |
| 149 | +ENV PATH="/opt/bin:${PATH}" \ |
| 150 | + LD_LIBRARY_PATH="/opt/ymir/lib64:/opt/ymir/lib" |
| 151 | + |
| 152 | +# Copy everything we built above into the same dir on the base AmazonLinux container. |
| 153 | +COPY --from=php-build /opt /opt |
| 154 | + |
| 155 | +# Needed for building the layer |
| 156 | +COPY --from=php-build /usr/lib64 /usr/lib64 |
0 commit comments