github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/containers/ddev-webserver/Dockerfile (about)

     1  
     2  ### ---------------------------ddev-webserver-base--------------------------------------
     3  ### Build ddev-php-base from ddev-webserver-base
     4  ### ddev-php-base is the basic of ddev-php-prod
     5  ### and ddev-webserver-* (For DDEV local Usage)
     6  FROM ddev/ddev-php-base:v1.23.1 as ddev-webserver-base
     7  
     8  ENV BACKDROP_DRUSH_VERSION=1.4.0
     9  ENV DEBIAN_FRONTEND=noninteractive
    10  
    11  ENV NGINX_SITE_TEMPLATE /etc/nginx/nginx-site.conf
    12  ENV APACHE_SITE_TEMPLATE /etc/apache2/apache-site.conf
    13  ENV TERMINUS_CACHE_DIR=/mnt/ddev-global-cache/terminus/cache
    14  ENV CAROOT /mnt/ddev-global-cache/mkcert
    15  
    16  # TARGETPLATFORM is Docker buildx's target platform (e.g. linux/arm64), while
    17  # BUILDPLATFORM is the platform of the build host (e.g. linux/amd64)
    18  ARG TARGETPLATFORM
    19  ARG BUILDPLATFORM
    20  
    21  ADD ddev-webserver-etc-skel /
    22  RUN /sbin/mkhomedir_helper www-data
    23  
    24  # symfony cli
    25  RUN curl -1sLf 'https://dl.cloudsmith.io/public/symfony/stable/setup.deb.sh' | bash
    26  
    27  RUN apt-get -qq update
    28  RUN DEBIAN_FRONTEND=noninteractive apt-get -qq install -y -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests -y libcap2-bin locales-all pv supervisor symfony-cli
    29  
    30  # Arbitrary user needs to be able to bind to privileged ports (for nginx and apache2)
    31  RUN setcap CAP_NET_BIND_SERVICE=+eip /usr/sbin/nginx
    32  RUN setcap CAP_NET_BIND_SERVICE=+eip /usr/sbin/apache2
    33  
    34  # magerun and magerun2 for magento
    35  RUN curl --fail -sSL https://files.magerun.net/n98-magerun-latest.phar -o /usr/local/bin/magerun && chmod 777 /usr/local/bin/magerun
    36  RUN curl --fail -sSL https://raw.githubusercontent.com/netz98/n98-magerun/develop/res/autocompletion/bash/n98-magerun.phar.bash -o /etc/bash_completion.d/n98-magerun.phar
    37  RUN curl --fail -sSL https://files.magerun.net/n98-magerun2-latest.phar -o /usr/local/bin/magerun2 && chmod 777 /usr/local/bin/magerun2
    38  RUN curl --fail -sSL https://raw.githubusercontent.com/netz98/n98-magerun2/develop/res/autocompletion/bash/n98-magerun2.phar.bash -o /etc/bash_completion.d/n98-magerun2.phar && chmod +x /usr/local/bin/magerun
    39  
    40  RUN apt-get -qq autoremove && apt-get -qq clean -y && rm -rf /var/lib/apt/lists/* /tmp/*
    41  
    42  ADD ddev-webserver-base-files /
    43  ADD ddev-webserver-base-scripts /
    44  
    45  # /usr/local/bin may need to be updated by start.sh, etc
    46  RUN chmod -f ugo+rwx /usr/local/bin /usr/local/bin/composer
    47  # END ddev-webserver-base
    48  
    49  
    50  ### ---------------------------ddev-webserver-dev-base--------------------------------------
    51  ### Build ddev-webserver-dev-base from ddev-webserver-base
    52  FROM ddev-webserver-base as ddev-webserver-dev-base
    53  ENV CAROOT /mnt/ddev-global-cache/mkcert
    54  ENV PHP_DEFAULT_VERSION="8.2"
    55  
    56  RUN curl -s --fail https://packages.blackfire.io/gpg.key > /usr/share/keyrings/blackfire-archive-keyring.asc
    57  RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/blackfire-archive-keyring.asc] http://packages.blackfire.io/debian any main" > /etc/apt/sources.list.d/blackfire.list
    58  RUN apt-get update
    59  
    60  SHELL ["/bin/bash", "-c"]
    61  
    62  RUN DEBIAN_FRONTEND=noninteractive apt-get -qq install -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests -y \
    63      blackfire \
    64      blackfire-php \
    65      fontconfig \
    66      gettext \
    67      git \
    68      graphviz \
    69      iproute2 \
    70      iputils-ping \
    71      jq \
    72      libldap-common \
    73      libpcre3 \
    74      libpq-dev \
    75      libpython3-dev \
    76      locales-all \
    77      nano \
    78      ncurses-bin \
    79      netcat-traditional \
    80      openssh-client \
    81      patch \
    82      python-is-python3 \
    83      python3-pip \
    84      python3-psycopg2 \
    85      python3-venv \
    86      rsync \
    87      sqlite3 \
    88      sudo \
    89      telnet \
    90      unzip \
    91      zip
    92  
    93  RUN curl --fail -JL -s -o /usr/local/bin/mkcert "https://dl.filippo.io/mkcert/latest?for=${TARGETPLATFORM}" && chmod +x /usr/local/bin/mkcert
    94  
    95  # blackfire user by default is set up with /dev/null as homedir, and 999 as uid, which
    96  # can break people. Use a real homedir
    97  RUN mkdir -p /home/blackfire && chown blackfire:blackfire /home/blackfire && usermod -d /home/blackfire blackfire
    98  
    99  ADD ddev-webserver-dev-base-files /
   100  RUN phpdismod blackfire xdebug
   101  RUN phpdismod xhprof
   102  
   103  RUN set -x && set -o pipefail && tag=$(curl -L --fail --silent "https://api.github.com/repos/axllent/mailpit/releases/latest" | jq -r .tag_name) && curl --fail -sSL "https://github.com/axllent/mailpit/releases/download/${tag}/mailpit-linux-${TARGETPLATFORM##linux/}.tar.gz" -o /tmp/mailpit.tar.gz && tar -zx -C /usr/local/bin -f /tmp/mailpit.tar.gz mailpit && rm /tmp/mailpit.tar.gz
   104  
   105  RUN curl -sSL --fail --output /usr/local/bin/phive "https://phar.io/releases/phive.phar" && chmod 777 /usr/local/bin/phive
   106  # Install terminus cli
   107  RUN set -o pipefail && curl --fail -sSL https://github.com/pantheon-systems/terminus/releases/download/$(curl -L --fail --silent "https://api.github.com/repos/pantheon-systems/terminus/releases/latest" | perl -nle'print $& while m{"tag_name": "\K.*?(?=")}g')/terminus.phar --output /usr/local/bin/terminus && chmod 777 /usr/local/bin/terminus
   108  # Install platform cli
   109  RUN set -o pipefail && curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | bash
   110  # Install upsun cli
   111  RUN set -o pipefail && curl -fsSL https://raw.githubusercontent.com/platformsh/cli/main/installer.sh | VENDOR=upsun bash
   112  # Install lagoon cli
   113  RUN set -o pipefail && tag=$(curl -L --fail --silent "https://api.github.com/repos/uselagoon/lagoon-cli/releases/latest" | jq -r .tag_name) && curl --fail -sSL "https://github.com/uselagoon/lagoon-cli/releases/download/$tag/lagoon-cli-$tag-linux-${TARGETPLATFORM##linux/}" --output /usr/local/bin/lagoon && chmod 777 /usr/local/bin/lagoon
   114  # Install lagoon-sync
   115  RUN set -x && set -o pipefail && tag=$(curl -L --fail --silent "https://api.github.com/repos/uselagoon/lagoon-sync/releases/latest" | jq -r .tag_name) && curl --fail -sSL "https://github.com/uselagoon/lagoon-sync/releases/download/${tag}/lagoon-sync_${tag:1}_linux_${TARGETPLATFORM##linux/}" --output /usr/local/bin/lagoon-sync && chmod 777 /usr/local/bin/lagoon-sync
   116  
   117  RUN mkdir -p "/opt/phpstorm-coverage" && \
   118      chmod a+rw "/opt/phpstorm-coverage"
   119  
   120  RUN curl --fail -sSL --output /usr/local/bin/acli https://github.com/acquia/cli/releases/latest/download/acli.phar && chmod 777 /usr/local/bin/acli
   121  
   122  RUN curl --fail -sSL https://github.com/backdrop-contrib/drush/releases/download/${BACKDROP_DRUSH_VERSION}/backdrop-drush-extension.zip -o /tmp/backdrop-drush-extension.zip && unzip -o /tmp/backdrop-drush-extension.zip -d /var/tmp/backdrop_drush_commands && chmod -R ugo+w /var/tmp/backdrop_drush_commands && rm /tmp/backdrop-drush-extension.zip
   123  
   124  RUN mkdir -p /etc/nginx/sites-enabled /var/log/apache2 /var/run/apache2 /var/lib/apache2/module/enabled_by_admin /var/lib/apache2/module/disabled_by_admin && \
   125      touch /var/log/php-fpm.log && \
   126      chmod ugo+rw /var/log/php-fpm.log && \
   127      chmod ugo+rwx /var/run && \
   128      touch /var/log/nginx/access.log && \
   129      touch /var/log/nginx/error.log && \
   130      chmod -R ugo+rw /var/log/nginx/ && \
   131      chmod ugo+rwx /usr/local/bin/* && \
   132      ln -sf /usr/sbin/php-fpm${PHP_DEFAULT_VERSION} /usr/sbin/php-fpm
   133  
   134  RUN chmod -R 777 /var/log
   135  
   136  # we need to create the /var/cache/linux and /var/lib/nginx manually for the arm64 image and chmod them, please don't remove them!
   137  RUN mkdir -p /mnt/ddev-global-cache/mkcert /run/{php,blackfire} /var/cache/nginx /var/lib/nginx && chmod -R ugo+rw /mnt/ddev-global-cache/
   138  
   139  RUN chmod -fR ugo+w /usr/sbin /usr/bin /etc/nginx /var/cache/nginx /var/lib/nginx /run /var/www /etc/php/*/*/conf.d/ /var/lib/php/modules /etc/alternatives /usr/lib/node_modules /etc/php /etc/apache2 /var/log/apache2/ /var/run/apache2 /var/lib/apache2 /mnt/ddev-global-cache/*
   140  
   141  RUN mkdir -p /var/xhprof && curl --fail  -o /tmp/xhprof.tgz -sSL https://pecl.php.net/get/xhprof && tar -zxf /tmp/xhprof.tgz --strip-components=1 -C /var/xhprof && chmod 777 /var/xhprof/xhprof_html && rm /tmp/xhprof.tgz
   142  
   143  RUN touch /var/log/nginx/error.log /var/log/nginx/access.log /var/log/php-fpm.log && \
   144    chmod 666 /var/log/nginx/error.log /var/log/nginx/access.log /var/log/php-fpm.log
   145  
   146  RUN a2dismod mpm_event
   147  RUN a2enmod ssl headers expires
   148  
   149  # scripts added last because they're most likely place to make changes, speeds up build
   150  ADD ddev-webserver-base-scripts /
   151  RUN chmod ugo+x /start.sh /healthcheck.sh
   152  
   153  # Composer, etc may need to be updated by composer self-update
   154  RUN chmod -f ugo+rwx /usr/local/bin /usr/local/bin/*
   155  
   156  RUN chmod ugo+w /etc/ssl/certs /usr/local/share/ca-certificates
   157  
   158  HEALTHCHECK --interval=1s --retries=120 --timeout=120s --start-period=120s CMD ["/healthcheck.sh"]
   159  CMD ["/start.sh"]
   160  RUN apt-get -qq clean -y && rm -rf /var/lib/apt/lists/* /tmp/*
   161  RUN update-alternatives --set php /usr/bin/php${PHP_DEFAULT_VERSION}
   162  
   163  #END ddev-webserver-dev-base
   164  
   165  ### ---------------------------ddev-webserver--------------------------------------
   166  ### This could be known as ddev-webserver-dev as it's development-env targeted
   167  ### But for historical reasons, it's just ddev-webserver
   168  ### Build ddev-webserver by turning ddev-webserver-dev-base into one layer
   169  FROM scratch as ddev-webserver
   170  ENV PHP_DEFAULT_VERSION="8.2"
   171  ENV NGINX_SITE_TEMPLATE /etc/nginx/nginx-site.conf
   172  ENV APACHE_SITE_TEMPLATE /etc/apache2/apache-site.conf
   173  ENV TERMINUS_CACHE_DIR=/mnt/ddev-global-cache/terminus/cache
   174  ENV TERMINUS_HIDE_UPDATE_MESSAGE=1
   175  ENV CAROOT /mnt/ddev-global-cache/mkcert
   176  ENV COMPOSER_ALLOW_SUPERUSER=1
   177  ENV COMPOSER_CACHE_DIR=/mnt/ddev-global-cache/composer
   178  ENV COMPOSER_PROCESS_TIMEOUT=2000
   179  ENV DEBIAN_FRONTEND noninteractive
   180  ENV TERM xterm
   181  ENV MH_SMTP_BIND_ADDR 127.0.0.1:1025
   182  ENV BASH_ENV /etc/bash.nointeractive.bashrc
   183  ENV LANG=C.UTF-8
   184  ENV XHPROF_OUTPUT_DIR=/tmp/xhprof
   185  ENV PLATFORMSH_CLI_UPDATES_CHECK=0
   186  
   187  COPY --from=ddev-webserver-dev-base / /
   188  EXPOSE 80 8025
   189  HEALTHCHECK --interval=1s --retries=120 --timeout=120s --start-period=120s CMD ["/healthcheck.sh"]
   190  CMD ["/start.sh"]
   191  #END ddev-webserver
   192  
   193  ### ---------------------------ddev-webserver-prod-base--------------------------------------
   194  ### Build ddev-webserver-prod-base from ddev-webserver-base
   195  ### This image is aimed at actual hardened production environments
   196  FROM ddev-webserver-base as ddev-webserver-prod-base
   197  ENV CAROOT /mnt/ddev-global-cache/mkcert
   198  ENV PHP_DEFAULT_VERSION="8.2"
   199  ARG TARGETPLATFORM
   200  
   201  RUN curl -s --fail https://packages.blackfire.io/gpg.key > /usr/share/keyrings/blackfire-archive-keyring.asc
   202  RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/blackfire-archive-keyring.asc] http://packages.blackfire.io/debian any main" > /etc/apt/sources.list.d/blackfire.list
   203  RUN apt-get update
   204  
   205  SHELL ["/bin/bash", "-c"]
   206  
   207  RUN DEBIAN_FRONTEND=noninteractive apt-get -qq install -o Dpkg::Options::="--force-confold" --no-install-recommends --no-install-suggests -y \
   208      blackfire-php \
   209      fontconfig \
   210      gettext \
   211      git \
   212      iproute2 \
   213      iputils-ping \
   214      jq \
   215      libpcre3 \
   216      locales-all \
   217      nano \
   218      ncurses-bin \
   219      netcat-traditional \
   220      openssh-client \
   221      patch \
   222      rsync \
   223      sqlite3 \
   224      unzip \
   225      zip
   226  
   227  RUN curl --fail -JL -s -o /usr/local/bin/mkcert "https://dl.filippo.io/mkcert/latest?for=${TARGETPLATFORM}" && chmod +x /usr/local/bin/mkcert
   228  
   229  ADD ddev-webserver-prod-files /
   230  RUN phpdismod blackfire
   231  RUN phpdismod xhprof
   232  
   233  RUN curl --fail -sSL https://github.com/backdrop-contrib/drush/releases/download/${BACKDROP_DRUSH_VERSION}/backdrop-drush-extension.zip -o /tmp/backdrop-drush-extension.zip && unzip -o /tmp/backdrop-drush-extension.zip -d /var/tmp/backdrop_drush_commands && chmod -R ugo+w /var/tmp/backdrop_drush_commands && rm /tmp/backdrop-drush-extension.zip
   234  
   235  RUN mkdir -p /etc/nginx/sites-enabled /var/lock/apache2 /var/log/apache2 /var/run/apache2 /var/lib/apache2/module/enabled_by_admin /var/lib/apache2/module/disabled_by_admin && \
   236      touch /var/log/php-fpm.log && \
   237      chmod ugo+rw /var/log/php-fpm.log && \
   238      chmod ugo+rwx /var/run && \
   239      touch /var/log/nginx/access.log && \
   240      touch /var/log/nginx/error.log && \
   241      chmod -R ugo+rw /var/log/nginx/ && \
   242      chmod ugo+rx /usr/local/bin/* && \
   243      ln -sf /usr/sbin/php-fpm${PHP_DEFAULT_VERSION} /usr/sbin/php-fpm
   244  
   245  RUN chmod -R 777 /var/log
   246  
   247  # we need to create the /var/cache/linux and /var/lib/nginx manually for the arm64 image and chmod them, please don't remove them!
   248  RUN mkdir -p /mnt/ddev-global-cache/mkcert /run/php /var/cache/nginx /var/lib/nginx && chmod -R ugo+rw /home /mnt/ddev-global-cache/
   249  
   250  RUN chmod -fR ugo+w /usr/sbin /usr/bin /etc/nginx /var/cache/nginx /var/lib/nginx /run /var/www /etc/php/*/*/conf.d/ /var/lib/php/modules /etc/alternatives /usr/lib/node_modules /etc/php /etc/apache2 /var/lock/apache2 /var/log/apache2/ /var/run/apache2 /var/lib/apache2 /mnt/ddev-global-cache/*
   251  
   252  RUN touch /var/log/nginx/error.log /var/log/nginx/access.log /var/log/php-fpm.log && \
   253    chmod 666 /var/log/nginx/error.log /var/log/nginx/access.log /var/log/php-fpm.log
   254  
   255  RUN a2dismod mpm_event
   256  RUN a2enmod ssl headers expires
   257  
   258  # scripts added last because they're most likely place to make changes, speeds up build
   259  ADD ddev-webserver-prod-scripts /
   260  RUN chmod ugo+x /start.sh /healthcheck.sh
   261  
   262  RUN /sbin/mkhomedir_helper www-data
   263  
   264  RUN chmod ugo+w /etc/ssl/certs /usr/local/share/ca-certificates
   265  
   266  HEALTHCHECK --interval=1s --retries=120 --timeout=120s --start-period=120s CMD ["/healthcheck.sh"]
   267  CMD ["/start.sh"]
   268  RUN apt-get -qq clean -y && rm -rf /var/lib/apt/lists/* /tmp/*
   269  RUN update-alternatives --set php /usr/bin/php${PHP_DEFAULT_VERSION}
   270  
   271  #END ddev-webserver-prod-base
   272  
   273  ### ---------------------------ddev-webserver-prod--------------------------------------
   274  ### Build ddev-webserver-prod, the hardened version of ddev-webserver-base
   275  ### (Withut dev features, single layer)
   276  FROM scratch as ddev-webserver-prod
   277  ENV PHP_DEFAULT_VERSION="8.2"
   278  ENV NGINX_SITE_TEMPLATE /etc/nginx/nginx-site.conf
   279  ENV APACHE_SITE_TEMPLATE /etc/apache2/apache-site.conf
   280  ENV TERMINUS_CACHE_DIR=/mnt/ddev-global-cache/terminus/cache
   281  ENV TERMINUS_HIDE_UPDATE_MESSAGE=1
   282  ENV CAROOT /mnt/ddev-global-cache/mkcert
   283  ENV COMPOSER_ALLOW_SUPERUSER=1
   284  ENV COMPOSER_CACHE_DIR=/mnt/ddev-global-cache/composer
   285  ENV COMPOSER_PROCESS_TIMEOUT=2000
   286  ENV DEBIAN_FRONTEND noninteractive
   287  ENV LANG=C.UTF-8
   288  ENV TERM xterm
   289  ENV BASH_ENV /etc/bash.nointeractive.bashrc
   290  ENV PLATFORMSH_CLI_UPDATES_CHECK=0
   291  
   292  COPY --from=ddev-webserver-prod-base / /
   293  HEALTHCHECK --interval=1s --retries=120 --timeout=120s --start-period=120s CMD ["/healthcheck.sh"]
   294  CMD ["/start.sh"]
   295  #END ddev-webserver-prod