Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial setup #1

Merged
merged 9 commits into from
Nov 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!/files
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[{*,*.dist}.{yml,yaml}]
indent_size = 2
23 changes: 23 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# For all configuration options:
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: docker
directory: "fpm"
schedule:
interval: "daily"
ignore:
- dependency-name: '*'
update-types: ["version-update:semver-major", "version-update:semver-minor"]
- package-ecosystem: docker
directory: "apache"
schedule:
interval: "daily"
ignore:
- dependency-name: '*'
update-types: ["version-update:semver-major", "version-update:semver-minor"]
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
52 changes: 52 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Main

on:
push:
branches: [main]

permissions:
actions: write
packages: write
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
uses: Ilyes512/github-actions/.github/workflows/build-php.yml@0.4.0
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
docker:
- dockerfile: fpm/Dockerfile
image-name: ghcr.io/${{ github.repository }}
key: fpm
- dockerfile: apache/Dockerfile
image-name: ghcr.io/${{ github.repository }}/apache
key: apache
with:
runs-on: ubuntu-24.04
platform: ${{ matrix.platform }}
image-name: ${{ matrix.docker.image-name }}
dockerfile: ${{ matrix.docker.dockerfile }}
cache-key: ${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-${{ github.ref_name }}-${{ github.sha }}
cache-restore-keys: |
${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-${{ github.ref_name }}-
${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}
merge:
uses: Ilyes512/github-actions/.github/workflows/merge-php.yml@0.4.0
needs: build
strategy:
matrix:
image-name:
- ghcr.io/${{ github.repository }}
- ghcr.io/${{ github.repository }}/apache
with:
runs-on: ubuntu-24.04
image-name: ${{ matrix.image-name }}
52 changes: 52 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Pull Requests

on:
pull_request:

permissions:
actions: write
packages: write
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
uses: Ilyes512/github-actions/.github/workflows/build-php.yml@0.4.0
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
docker:
- dockerfile: fpm/Dockerfile
image-name: ghcr.io/${{ github.repository }}
key: fpm
- dockerfile: apache/Dockerfile
image-name: ghcr.io/${{ github.repository }}/apache
key: apache
with:
runs-on: ubuntu-24.04
platform: ${{ matrix.platform }}
image-name: ${{ matrix.docker.image-name }}
dockerfile: ${{ matrix.docker.dockerfile }}
cache-key: ${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-pr-${{ github.event.number }}-${{ github.sha }}
cache-restore-keys: |
${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-pr-${{ github.event.number }}-
${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-pr-
${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-main-
merge:
uses: Ilyes512/github-actions/.github/workflows/merge-php.yml@0.4.0
needs: build
strategy:
matrix:
image-name:
- ghcr.io/${{ github.repository }}
- ghcr.io/${{ github.repository }}/apache
with:
runs-on: ubuntu-24.04
image-name: ${{ matrix.image-name }}
53 changes: 53 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Tags

on:
push:
tags: ['*']

permissions:
actions: write
packages: write
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
uses: Ilyes512/github-actions/.github/workflows/build-php.yml@0.4.0
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
- linux/arm64
docker:
- dockerfile: fpm/Dockerfile
image-name: ghcr.io/${{ github.repository }}
key: fpm
- dockerfile: apache/Dockerfile
image-name: ghcr.io/${{ github.repository }}/apache
key: apache
with:
runs-on: ubuntu-24.04
platform: ${{ matrix.platform }}
image-name: ${{ matrix.docker.image-name }}
dockerfile: ${{ matrix.docker.dockerfile }}
cache-key: ${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-${{ github.ref_name }}-${{ github.sha }}
cache-restore-keys: |
${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-${{ github.ref_name }}-
${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-main-
${{ matrix.os }}-buildx-${{ matrix.platform }}-${{ matrix.docker.key }}-
merge:
uses: Ilyes512/github-actions/.github/workflows/merge-php.yml@0.4.0
needs: build
strategy:
matrix:
image-name:
- ghcr.io/${{ github.repository }}
- ghcr.io/${{ github.repository }}/apache
with:
runs-on: ubuntu-24.04
image-name: ${{ matrix.image-name }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
dev
Taskfile.yml
3 changes: 3 additions & 0 deletions .hadolint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ignored:
- SC2086
- DL3008
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Ilyes Ahidar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@ A PHP 8.4 (FPM and Apache) based Docker base image.
```
docker pull ghcr.io/ilyes512/php84:runtime-latest
docker pull ghcr.io/ilyes512/php84:builder-latest
docker pull ghcr.io/ilyes512/php84:builder-nodejs-latest
docker pull ghcr.io/ilyes512/php84:builder_nodejs-latest
docker pull ghcr.io/ilyes512/php84/apache:runtime-latest
docker pull ghcr.io/ilyes512/php84/apache:builder-latest
docker pull ghcr.io/ilyes512/php84/apache:builder-nodejs-latest
docker pull ghcr.io/ilyes512/php84/apache:builder_nodejs-latest
```

The tag scheme: `{TARGET}-{VERSION}`
@@ -44,7 +44,7 @@ docker build --tag ghcr.io/ilyes512/php84:builder-latest --file fpm/Dockerfile -
Building `builder_nodejs`-target:

```
docker build --tag ghcr.io/ilyes512/php84:builder-nodejs-latest --file fpm/Dockerfile --target builder_nodejs .
docker build --tag ghcr.io/ilyes512/php84:builder_nodejs-latest --file fpm/Dockerfile --target builder_nodejs .
```

## Task commands
135 changes: 135 additions & 0 deletions Taskfile.dist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
version: "3"

vars:
DOCKER_REPO: ghcr.io
DOCKER_OWNER: ilyes512
# Latatest version of Hadolint: https://hub.docker.com/r/hadolint/hadolint/tags or https://github.com/hadolint/hadolint/releases
HADOLINT_TAG_VERSION: v2.12.0

# env:
# BUILDKIT_PROGRESS: plain

silent: true

tasks:

build:
desc: Build all PHP Docker image targets of both the FPM and Apache variants
cmds:
- task: build:fpm
- task: build:apache

build:fpm:
desc: Build all PHP Docker image targets of the FPM variant
deps: [lint:fpm]
vars:
DOCKER_IMAGE_NAME: php84
DOCKER_FILE_PATH: ./fpm/Dockerfile
cmds:
- task: build:target
vars:
TARGET: runtime
DOCKER_IMAGE_NAME: '{{.DOCKER_IMAGE_NAME}}'
DOCKER_FILE_PATH: '{{.DOCKER_FILE_PATH}}'
- task: build:target
vars:
TARGET: builder
DOCKER_IMAGE_NAME: '{{.DOCKER_IMAGE_NAME}}'
DOCKER_FILE_PATH: '{{.DOCKER_FILE_PATH}}'
- task: build:target
vars:
TARGET: builder_nodejs
DOCKER_IMAGE_NAME: '{{.DOCKER_IMAGE_NAME}}'
DOCKER_FILE_PATH: '{{.DOCKER_FILE_PATH}}'

build:apache:
desc: Build all PHP Docker image targets of the Apache variant
deps: [lint:apache]
vars:
DOCKER_IMAGE_NAME: php84/apache
DOCKER_FILE_PATH: ./apache/Dockerfile
cmds:
- task: build:target
vars:
TARGET: runtime
DOCKER_IMAGE_NAME: '{{.DOCKER_IMAGE_NAME}}'
DOCKER_FILE_PATH: '{{.DOCKER_FILE_PATH}}'
- task: build:target
vars:
TARGET: builder
DOCKER_IMAGE_NAME: '{{.DOCKER_IMAGE_NAME}}'
DOCKER_FILE_PATH: '{{.DOCKER_FILE_PATH}}'
- task: build:target
vars:
TARGET: builder_nodejs
DOCKER_IMAGE_NAME: '{{.DOCKER_IMAGE_NAME}}'
DOCKER_FILE_PATH: '{{.DOCKER_FILE_PATH}}'

build:target:
preconditions:
- sh: >
test '{{.TARGET}}' = 'runtime'
-o '{{.TARGET}}' = 'builder'
-o '{{.TARGET}}' = 'builder_nodejs'
msg: TARGET needs to contain the Docker TARGET [runtime, builder, builder_nodejs]
vars:
VERSION: '{{.VERSION | default "latest"}}'
cmds:
- docker build
--target {{.TARGET}}
--tag {{.DOCKER_REPO}}/{{.DOCKER_OWNER}}/{{.DOCKER_IMAGE_NAME}}:{{.TARGET}}-{{.VERSION}}
--file {{.DOCKER_FILE_PATH}}
.
requires:
vars: [DOCKER_IMAGE_NAME, TARGET, DOCKER_FILE_PATH]

lint:fpm:
desc: Apply a Dockerfile linter (https://github.com/hadolint/hadolint)
cmds:
- task: lint
vars: { DOCKERFILE_PATH: fpm/Dockerfile }

lint:apache:
desc: Apply a Dockerfile linter (https://github.com/hadolint/hadolint)
cmds:
- task: lint
vars: { DOCKERFILE_PATH: apache/Dockerfile }

lint:
cmds:
- docker run
--interactive
--rm
--volume $(pwd)/.hadolint.yml:/.hadolint.yml
hadolint/hadolint:{{.HADOLINT_TAG_VERSION}}
hadolint
-
< {{.DOCKERFILE_PATH}}
requires:
vars: [DOCKERFILE_PATH]

shell:fpm:
desc: Interactive shell
interactive: true
vars:
DOCKER_IMAGE_NAME: php84
cmds:
- docker run
--interactive
--tty
--rm
{{.DOCKER_REPO}}/{{.DOCKER_OWNER}}/{{.DOCKER_IMAGE_NAME}}:builder_nodejs-{{.VERSION | default "latest" }}
bash

shell:apache:
desc: Interactive shell
interactive: true
vars:
DOCKER_IMAGE_NAME: php84/apache
cmds:
- docker run
--interactive
--tty
--rm
{{.DOCKER_REPO}}/{{.DOCKER_OWNER}}/{{.DOCKER_IMAGE_NAME}}:builder_nodejs-{{.VERSION | default "latest" }}
bash
191 changes: 191 additions & 0 deletions apache/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Latest version of PHP base image: https://hub.docker.com/_/php?tab=tags
FROM php:8.4.1-apache-bookworm AS runtime

ARG UNIQUE_ID_FOR_CACHEFROM=runtime

# Latest version of event-extension: https://pecl.php.net/package/event
ARG PHP_EVENT_VERSION=3.1.4
# Latest version of igbinary-extension: https://pecl.php.net/package/igbinary
ARG PHP_IGBINARY_VERSION=3.2.16
# Latest version of redis-extension: https://pecl.php.net/package/redis
ARG PHP_REDIS_VERSION=6.1.0RC2
# Latest version of amqp-extension: https://pecl.php.net/package/amqp
ARG PHP_AMQP_VERSION=2.1.2

ENV SMTPHOST=mail
ENV SMTPEHLO=localhost

WORKDIR /var/www

RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
ca-certificates \
openssl \
curl \
msmtp-mta \
# Dependency of the PHP intl-extension
libicu72 \
# Dependency of the PHP gd-extension
libpng16-16 \
libwebp7 \
libjpeg62-turbo \
libfreetype6 \
# Dependency of PHP zip-extension
libzip4 \
# Dependency of PHP event-extension
libevent-2.1-7 \
libevent-openssl-2.1-7 \
libevent-extra-2.1-7 \
# Dependency of PHP pdo_pgsql-extension
libpq5 \
# Dependency of PHP amqp-extension
librabbitmq4 \
# Dependency of PHP xsl-extension
libxslt1.1 \
# Install packages that are needed for building PHP extensions
&& apt-get install --assume-yes --no-install-recommends \
$PHPIZE_DEPS \
# Dependency of the PHP intl-extension
libicu-dev \
# Dependencies of PHP gd-extension
libpng-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
# Dependency of PHP zip-extension
libzip-dev \
# Dependency of PHP event-extension
libevent-dev \
libssl-dev \
# Dependency of PHP soap-extension
libxml2-dev \
# Dependency of PHP pdo_pgsql-extension
libpq-dev \
# Dependency of PHP amqp-extension
librabbitmq-dev \
# Dependency of PHP xsl-extension
libxslt1-dev \
# Configure PHP gd-extension
&& docker-php-ext-configure gd \
--enable-gd \
--with-jpeg \
--with-freetype \
--with-webp \
# Install PHP extensions
&& docker-php-ext-install -j "$(nproc --all)" \
pdo_mysql \
pdo_pgsql \
intl \
opcache \
pcntl \
gd \
bcmath \
zip \
soap \
xsl \
# Dependency of PHP event-extension
sockets \
&& pecl install "event-$PHP_EVENT_VERSION" \
# Optional dependency of PHP redis-extension
&& pecl install "igbinary-$PHP_IGBINARY_VERSION" \
&& pecl install --configureoptions 'enable-redis-igbinary="yes"' "redis-$PHP_REDIS_VERSION" \
&& pecl install "amqp-$PHP_AMQP_VERSION" \
&& docker-php-ext-enable --ini-name docker-php-ext-zz-custom.ini \
event \
igbinary \
redis \
amqp \
&& cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
# Purge packages that where only needed for building php extensions
&& apt-get purge --assume-yes \
$PHPIZE_DEPS \
libicu-dev \
libpng-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libzip-dev \
libevent-dev \
libssl-dev \
libxml2-dev \
libpq-dev \
librabbitmq-dev \
# Cleanup
&& rm -rf /var/www/* \
&& apt-get autoremove --assume-yes \
&& apt-get clean --assume-yes \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*

COPY files /

FROM runtime AS builder

ARG UNIQUE_ID_FOR_CACHEFROM=builder

# Latest version of Phive: https://api.github.com/repos/phar-io/phive/releases/latest
ARG PHIVE_VERSION=0.15.3
# Latest version of Composer: https://getcomposer.org/download
ARG COMPOSER_VERSION=2.8.3
# Latest version of Xdebug: https://github.com/xdebug/xdebug/tags or https://pecl.php.net/package/xdebug
ARG XDEBUG_VERSION=3.4.0beta1

RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
# Needed for xdebug extension configuration
$PHPIZE_DEPS \
vim \
git \
unzip \
sqlite3 \
wait-for-it \
# Needed for phive:
gnupg \
# Install Phive
&& curl -fsSLo /usr/local/bin/phive "https://github.com/phar-io/phive/releases/download/$PHIVE_VERSION/phive-$PHIVE_VERSION.phar" \
&& curl -fsSLo /tmp/phive.phar.asc "https://github.com/phar-io/phive/releases/download/$PHIVE_VERSION/phive-$PHIVE_VERSION.phar.asc" \
&& gpg --keyserver keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 \
&& gpg --verify /tmp/phive.phar.asc /usr/local/bin/phive \
&& chmod +x /usr/local/bin/phive \
&& phive update-repository-list \
# Install Composer using Phive
&& phive install --global composer:$COMPOSER_VERSION --trust-gpg-keys CBB3D576F2A0946F \
&& rm -rf /root/.phive \
# Install Xdebug PHP extension
&& pecl install "xdebug-$XDEBUG_VERSION" \
&& docker-php-ext-enable xdebug \
&& cp "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" \
# Cleanup
&& apt-get purge --assume-yes $PHPIZE_DEPS \
&& apt-get autoremove --assume-yes \
&& apt-get clean --assume-yes \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*

FROM builder AS builder_nodejs

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

ARG UNIQUE_ID_FOR_CACHEFROM=builder_nodejs

# Latest version of Node.js: https://nodejs.org
ARG NODE_MAJOR=20

RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
gcc \
g++ \
make \
&& 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 --assume-yes --no-install-recommends \
nodejs \
&& npm uninstall --global npm \
&& corepack install --global npm yarn pnpm \
&& corepack enable npm yarn pnpm \
&& apt-get autoremove --assume-yes \
&& apt-get clean --assume-yes \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*
2 changes: 2 additions & 0 deletions files/usr/local/etc/php/conf.d/010-default.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
memory_limit = 1G
expose_php = Off
191 changes: 191 additions & 0 deletions fpm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Latest version of PHP base image: https://hub.docker.com/_/php?tab=tags
FROM php:8.4.1-fpm-bookworm AS runtime

ARG UNIQUE_ID_FOR_CACHEFROM=runtime

# Latest version of event-extension: https://pecl.php.net/package/event
ARG PHP_EVENT_VERSION=3.1.4
# Latest version of igbinary-extension: https://pecl.php.net/package/igbinary
ARG PHP_IGBINARY_VERSION=3.2.16
# Latest version of redis-extension: https://pecl.php.net/package/redis
ARG PHP_REDIS_VERSION=6.1.0RC2
# Latest version of amqp-extension: https://pecl.php.net/package/amqp
ARG PHP_AMQP_VERSION=2.1.2

ENV SMTPHOST=mail
ENV SMTPEHLO=localhost

WORKDIR /var/www

RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
ca-certificates \
openssl \
curl \
msmtp-mta \
# Dependency of the PHP intl-extension
libicu72 \
# Dependency of the PHP gd-extension
libpng16-16 \
libwebp7 \
libjpeg62-turbo \
libfreetype6 \
# Dependency of PHP zip-extension
libzip4 \
# Dependency of PHP event-extension
libevent-2.1-7 \
libevent-openssl-2.1-7 \
libevent-extra-2.1-7 \
# Dependency of PHP pdo_pgsql-extension
libpq5 \
# Dependency of PHP amqp-extension
librabbitmq4 \
# Dependency of PHP xsl-extension
libxslt1.1 \
# Install packages that are needed for building PHP extensions
&& apt-get install --assume-yes --no-install-recommends \
$PHPIZE_DEPS \
# Dependency of the PHP intl-extension
libicu-dev \
# Dependencies of PHP gd-extension
libpng-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
# Dependency of PHP zip-extension
libzip-dev \
# Dependency of PHP event-extension
libevent-dev \
libssl-dev \
# Dependency of PHP soap-extension
libxml2-dev \
# Dependency of PHP pdo_pgsql-extension
libpq-dev \
# Dependency of PHP amqp-extension
librabbitmq-dev \
# Dependency of PHP xsl-extension
libxslt1-dev \
# Configure PHP gd-extension
&& docker-php-ext-configure gd \
--enable-gd \
--with-jpeg \
--with-freetype \
--with-webp \
# Install PHP extensions
&& docker-php-ext-install -j "$(nproc --all)" \
pdo_mysql \
pdo_pgsql \
intl \
opcache \
pcntl \
gd \
bcmath \
zip \
soap \
xsl \
# Dependency of PHP event-extension
sockets \
&& pecl install "event-$PHP_EVENT_VERSION" \
# Optional dependency of PHP redis-extension
&& pecl install "igbinary-$PHP_IGBINARY_VERSION" \
&& pecl install --configureoptions 'enable-redis-igbinary="yes"' "redis-$PHP_REDIS_VERSION" \
&& pecl install "amqp-$PHP_AMQP_VERSION" \
&& docker-php-ext-enable --ini-name docker-php-ext-zz-custom.ini \
event \
igbinary \
redis \
amqp \
&& cp "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \
# Purge packages that where only needed for building php extensions
&& apt-get purge --assume-yes \
$PHPIZE_DEPS \
libicu-dev \
libpng-dev \
libwebp-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libzip-dev \
libevent-dev \
libssl-dev \
libxml2-dev \
libpq-dev \
librabbitmq-dev \
# Cleanup
&& rm -rf /var/www/* \
&& apt-get autoremove --assume-yes \
&& apt-get clean --assume-yes \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*

COPY files /

FROM runtime AS builder

ARG UNIQUE_ID_FOR_CACHEFROM=builder

# Latest version of Phive: https://api.github.com/repos/phar-io/phive/releases/latest
ARG PHIVE_VERSION=0.15.3
# Latest version of Composer: https://getcomposer.org/download
ARG COMPOSER_VERSION=2.8.3
# Latest version of Xdebug: https://github.com/xdebug/xdebug/tags or https://pecl.php.net/package/xdebug
ARG XDEBUG_VERSION=3.4.0beta1

RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
# Needed for xdebug extension configuration
$PHPIZE_DEPS \
vim \
git \
unzip \
sqlite3 \
wait-for-it \
# Needed for phive:
gnupg \
# Install Phive
&& curl -fsSLo /usr/local/bin/phive "https://github.com/phar-io/phive/releases/download/$PHIVE_VERSION/phive-$PHIVE_VERSION.phar" \
&& curl -fsSLo /tmp/phive.phar.asc "https://github.com/phar-io/phive/releases/download/$PHIVE_VERSION/phive-$PHIVE_VERSION.phar.asc" \
&& gpg --keyserver keys.openpgp.org --recv-keys 0x9D8A98B29B2D5D79 \
&& gpg --verify /tmp/phive.phar.asc /usr/local/bin/phive \
&& chmod +x /usr/local/bin/phive \
&& phive update-repository-list \
# Install Composer using Phive
&& phive install --global composer:$COMPOSER_VERSION --trust-gpg-keys CBB3D576F2A0946F \
&& rm -rf /root/.phive \
# Install Xdebug PHP extension
&& pecl install "xdebug-$XDEBUG_VERSION" \
&& docker-php-ext-enable xdebug \
&& cp "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini" \
# Cleanup
&& apt-get purge --assume-yes $PHPIZE_DEPS \
&& apt-get autoremove --assume-yes \
&& apt-get clean --assume-yes \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*

FROM builder AS builder_nodejs

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

ARG UNIQUE_ID_FOR_CACHEFROM=builder_nodejs

# Latest version of Node.js: https://nodejs.org
ARG NODE_MAJOR=20

RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends \
gcc \
g++ \
make \
&& 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 --assume-yes --no-install-recommends \
nodejs \
&& npm uninstall --global npm \
&& corepack install --global npm yarn pnpm \
&& corepack enable npm yarn pnpm \
&& apt-get autoremove --assume-yes \
&& apt-get clean --assume-yes \
&& rm -rf /var/lib/apt/lists/* \
&& rm -rf /tmp/*