Skip to content

Commit

Permalink
[shopsys] introduced php-fpm base image (#2762)
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmannmartin authored Sep 7, 2023
2 parents 8e93128 + 94e87b6 commit 636f350
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 181 deletions.
126 changes: 7 additions & 119 deletions app/docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,124 +1,11 @@
ARG DEBIAN_VERSION=bullseye
ARG NODE_MAJOR=16

FROM php:8.1-fpm-${DEBIAN_VERSION} as base
FROM shopsys/php-image:13.0 as base

ARG project_root=.
ARG NODE_MAJOR
ARG DEBIAN_VERSION

# install required tools
# git for computing diffs and for npm to download packages
# wget for installation of other tools
# gnupg and g++ for gd extension
# locales for locale-gen command
# apt-utils so package configuartion does not get delayed
# unzip to ommit composer zip packages corruption
# dialog for apt-get to be
# ca-certificates to ensure certificates are up to date
RUN apt-get update && \
apt-get install -y --no-install-recommends \
wget \
gnupg \
g++ \
locales \
unzip \
ca-certificates \
dialog \
apt-utils \
git && \
apt-get clean

# Install NodeJS
RUN mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list && \
apt-get update && apt-get install nodejs -y && apt-get clean

# install Composer
COPY ${project_root}/docker/php-fpm/docker-install-composer /usr/local/bin/docker-install-composer

RUN chmod +x /usr/local/bin/docker-install-composer && \
docker-install-composer

# libpng-dev needed by "gd" extension
# libzip-dev needed by "zip" extension
# libicu-dev for intl extension
# libpg-dev for connection to postgres database
# autoconf needed by "redis" extension
RUN apt-get update && \
apt-get install -y --no-install-recommends \
bash-completion \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
libzip-dev \
libicu-dev \
libpq-dev \
vim \
nano \
mc \
htop \
autoconf && \
apt-get clean

RUN docker-php-ext-configure gd --with-freetype --with-jpeg

# install necessary tools for running application
RUN docker-php-ext-install \
bcmath \
fileinfo \
gd \
intl \
opcache \
pgsql \
pdo_pgsql \
zip

# install PostgreSQl client for dumping database
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /etc/apt/keyrings/postgresql.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt/ $DEBIAN_VERSION-pgdg main" | tee /etc/apt/sources.list.d/PostgreSQL.list && \
apt-get update && apt-get install -y postgresql-12 postgresql-client-12 && apt-get clean

# install redis extension
RUN pecl install redis-5.3.7 && \
docker-php-ext-enable redis

# install locales and switch to en_US.utf8 in order to enable UTF-8 support
# see http://jaredmarkell.com/docker-and-locales/ from where was this code taken
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
locale-gen
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

# copy php.ini configuration
COPY ${project_root}/docker/php-fpm/php-ini-overrides.ini /usr/local/etc/php/php.ini

# add bash completion for phing
COPY ${project_root}/docker/php-fpm/phing-completion /etc/bash_completion.d/phing

# overwrite the original entry-point from the PHP Docker image with our own
COPY ${project_root}/docker/php-fpm/docker-php-entrypoint /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-php-entrypoint

# set www-data user his home directory
# the user "www-data" is used when running the image, and therefore should own the workdir
RUN usermod -m -d /home/www-data www-data && \
mkdir -p /var/www/html && \
chown -R www-data:www-data /home/www-data /var/www/html

# Switch to user
USER www-data

# enable bash completion
RUN echo "source /etc/bash_completion" >> ~/.bashrc

RUN mkdir -p /var/www/html/.npm-global
ENV NPM_CONFIG_PREFIX /var/www/html/.npm-global
# copy custom php.ini configuration
COPY ${project_root}/docker/php-fpm/php-ini-overrides.ini /usr/local/etc/php/php.ini

# set COMPOSER_MEMORY_LIMIT to -1 (i.e. unlimited - this is a hotfix until https://github.com/shopsys/shopsys/issues/634 is solved)
ENV COMPOSER_MEMORY_LIMIT=-1
# Your can add your custom commands here (e.g. installing additional PHP extensions)

########################################################################################################################

Expand All @@ -143,7 +30,7 @@ FROM base as production

ARG project_root=.

# copy FPM pool configuration
# copy custom FPM pool configuration
COPY ${project_root}/docker/php-fpm/production-www.conf /usr/local/etc/php-fpm.d/www.conf

COPY --chown=www-data:www-data / /var/www/html
Expand All @@ -152,6 +39,7 @@ RUN composer install --optimize-autoloader --no-interaction --no-progress --no-d

RUN php phing build-deploy-part-1-db-independent clean

########################################################################################################################

FROM production as production-project

Expand All @@ -165,7 +53,7 @@ COPY --chown=www-data:www-data / /var/www/html

RUN composer install --optimize-autoloader --no-interaction --no-progress --dev

RUN php phing composer-dev dirs-create test-dirs-create assets npm standards tests-unit tests-acceptance-build
RUN php phing build-deploy-part-1-db-independent

RUN ./bin/console shopsys:environment:change prod

Expand Down
20 changes: 0 additions & 20 deletions app/docker/php-fpm/docker-install-composer

This file was deleted.

21 changes: 0 additions & 21 deletions app/docker/php-fpm/docker-php-entrypoint

This file was deleted.

21 changes: 0 additions & 21 deletions app/docker/php-fpm/phing-completion

This file was deleted.

0 comments on commit 636f350

Please sign in to comment.