Skip to content

Commit

Permalink
feat: make php builds faster
Browse files Browse the repository at this point in the history
  • Loading branch information
saschanowak committed Jul 7, 2024
1 parent 436c4dc commit ff2ae4c
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 104 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,60 @@ jobs:
cache-from: type=gha, scope=${{ github.workflow }}-php
cache-to: type=gha, scope=${{ github.workflow }}-php, mode=max

build-docker-dev-image:
name: 'Build php-${{ matrix.image.version }}-dev docker image'
runs-on: ubuntu-latest

strategy:
fail-fast: false
max-parallel: 10
matrix:
image:
- version: 7.2
build-args: |
PHP_VERSION=7.2
UBUNTU_VERSION=18.04
XDEBUG_VERSION=3.1.6
- version: 7.4
build-args: |
PHP_VERSION=7.4
UBUNTU_VERSION=20.04
XDEBUG_VERSION=3.1.6
- version: 8.1
build-args: |
PHP_VERSION=8.1
UBUNTU_VERSION=22.04
XDEBUG_VERSION=3.3.2
- version: 8.2
file: 8.2.dockerfile
build-args: |
PHP_VERSION=8.2
UBUNTU_VERSION=24.04
XDEBUG_VERSION=3.3.2
- version: 8.3
build-args: |
PHP_VERSION=8.3
UBUNTU_VERSION=24.04
XDEBUG_VERSION=3.3.2
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup QEMU
uses: docker/setup-qemu-action@v3

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push (php-fpm-dev)
uses: docker/build-push-action@v6
with:
Expand Down
82 changes: 30 additions & 52 deletions php/8.2.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,35 @@ RUN apt-get update && \
apt-transport-https\
libfcgi-bin \
ca-certificates \
curl \
wget \
gnupg2 \
locales

RUN locale-gen de_DE.UTF-8 && \
locale-gen en_GB.UTF-8 && \
locale-gen en_US.UTF-8 && \
locale-gen es_ES.UTF-8 && \
locale-gen fr_FR.UTF-8 && \
locale-gen nl_NL.UTF-8 && \
locale-gen pt_PT.UTF-8 && \
locale-gen it_IT.UTF-8

# Install dev certificates
COPY certs/* /usr/share/ca-certificates/netlogix/
RUN echo "netlogix/docker-dev-ca.crt" >> /etc/ca-certificates.conf && update-ca-certificates

RUN echo 'deb https://packages.tideways.com/apt-packages-main any-version main' > /etc/apt/sources.list.d/tideways.list && \
curl -L -sS 'https://packages.tideways.com/key.gpg' | apt-key add -
RUN echo 'deb [signed-by=/usr/share/keyrings/tideways.gpg] https://packages.tideways.com/apt-packages-main any-version main' | tee /etc/apt/sources.list.d/tideways.list && \
wget -qO - 'https://packages.tideways.com/key.gpg' | gpg --dearmor | tee /usr/share/keyrings/tideways.gpg > /dev/null

RUN add-apt-repository ppa:ondrej/php -y

RUN apt-get update && \
apt-get -y install --no-install-suggests --no-install-recommends \
cron \
ghostscript \
gifsicle \
imagemagick \
jpegoptim \
openssl \
optipng \
pngquant \
supervisor \
tar \
unzip \
webp \
zip \
php${PHP_VERSION} \
php${PHP_VERSION}-apcu \
php${PHP_VERSION}-bcmath \
php${PHP_VERSION}-common \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-common \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-fpm \
php${PHP_VERSION}-gd \
Expand All @@ -83,15 +72,30 @@ RUN apt-get update && \
php${PHP_VERSION}-pgsql \
php${PHP_VERSION}-readline \
php${PHP_VERSION}-redis \
php${PHP_VERSION}-sqlite3 \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-yaml \
php${PHP_VERSION}-zip \
&& apt-get -y install --no-install-suggests --no-install-recommends \
tideways-php \
tideways-cli \
&& apt-get autoremove \
&& find /var/log -type f -name "*.log" -delete \
&& rm -rf /var/lib/apt/lists/* /var/cache/ldconfig/aux-cache
&& rm -rf /var/lib/apt/lists/* /var/cache/ldconfig/aux-cache \
&& rm -rf /etc/cron.*/*

# Install locales
RUN locale-gen de_DE.UTF-8 && \
locale-gen en_GB.UTF-8 && \
locale-gen en_US.UTF-8 && \
locale-gen es_ES.UTF-8 && \
locale-gen fr_FR.UTF-8 && \
locale-gen nl_NL.UTF-8 && \
locale-gen pt_PT.UTF-8 && \
locale-gen it_IT.UTF-8

# Install dev certificates
COPY certs/* /usr/share/ca-certificates/netlogix/
RUN echo "netlogix/docker-dev-ca.crt" >> /etc/ca-certificates.conf && update-ca-certificates

RUN ln -s /usr/sbin/php-fpm${PHP_VERSION} /usr/sbin/php-fpm

Expand All @@ -101,12 +105,18 @@ RUN mkdir -p "/run/php/" \
&& touch /var/log/xdebug.log \
&& chown www-data:www-data /var/log/xdebug.log

RUN touch /var/run/supervisord.pid \
&& chown www-data:www-data /var/run/supervisord.pid

# Config files
COPY config/conf.d /etc/php/${PHP_VERSION}/cli/conf.d/
COPY config/conf.d /etc/php/${PHP_VERSION}/fpm/conf.d/
COPY config/fpm/pool.d /etc/php/${PHP_VERSION}/fpm/pool.d/
COPY config/fpm-${PHP_VERSION}/pool.d /etc/php/${PHP_VERSION}/fpm/pool.d/

# Config files
COPY dev/bash /root/

# Test php-fpm config and php info
RUN php-fpm -tt
RUN php -i
Expand Down Expand Up @@ -136,36 +146,13 @@ CMD ["php", "-a"]

FROM php-cli AS php-cron

RUN apt-get update && \
apt-get -y install --no-install-suggests --no-install-recommends \
cron \
&& apt-get autoremove \
&& find /var/log -type f -name "*.log" -delete \
&& rm -rf /var/lib/apt/lists/* /var/cache/ldconfig/aux-cache \
&& rm -rf /etc/cron.*/*

WORKDIR /var/www

COPY cron/docker-cron-entrypoint /usr/local/bin/

ENTRYPOINT ["docker-cron-entrypoint"]
CMD ["cron", "-f", "-l", "2"]

FROM php-cli AS php-supervisor

RUN apt-get update && \
apt-get -y install --no-install-suggests --no-install-recommends \
supervisor \
&& apt-get autoremove \
&& find /var/log -type f -name "*.log" -delete \
&& rm -rf /var/lib/apt/lists/* /var/cache/ldconfig/aux-cache \
&& rm -rf /etc/cron.*/*

RUN touch /var/run/supervisord.pid \
&& chown www-data:www-data /var/run/supervisord.pid

WORKDIR /var/www

COPY supervisor/docker-supervisor-entrypoint /usr/local/bin/
COPY supervisor/supervisord.conf /etc/supervisor/supervisord.conf

Expand All @@ -188,7 +175,7 @@ ENV PHP_IDE_CONFIG="serverName=localhost"

RUN apt-get update && \
apt-get -y install --no-install-suggests --no-install-recommends \
make php${PHP_VERSION}-dev php${PHP_VERSION}-sqlite3 php-pear openssh-client git patch \
make php${PHP_VERSION}-dev php-pear openssh-client git patch \
&& mkdir -p /tmp/pear/cache \
&& pecl channel-update pecl.php.net \
&& pecl install xdebug-${XDEBUG_VERSION} \
Expand All @@ -210,7 +197,6 @@ RUN apt-get update && \

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
COPY dev/scripts /usr/local/bin/
COPY dev/bash /root/

# Dev PHP cli
FROM php-fpm-dev AS php-cli-dev
Expand All @@ -228,14 +214,6 @@ CMD ["php", "-a"]
# Dev PHP cron
FROM php-cli-dev AS php-cron-dev

RUN apt-get update && \
apt-get -y install --no-install-suggests --no-install-recommends \
cron \
&& apt-get autoremove \
&& find /var/log -type f -name "*.log" -delete \
&& rm -rf /var/lib/apt/lists/* /var/cache/ldconfig/aux-cache \
&& rm -rf /etc/cron.*/*

WORKDIR /var/www

COPY cron/docker-cron-entrypoint /usr/local/bin/
Expand Down
Loading

0 comments on commit ff2ae4c

Please sign in to comment.