Add PHP, Composer to workspace default image

MR - Add php and composer to workspace default image (gitlab-build-images!936 - merged)

Description

Add php and composer to workspace default image, so the default image could support more needs.

There is no existing support for php in the repo, and we should add script for installing them.

Acceptance criteria

  • Add script for install php and composer
  • enable our script in Dockerfile.custom and scripts/lib/custom-docker-build
  • Add proper workspace default image job variable

Implementation plan

example script

#!/bin/bash

set -xeou pipefail

PHP_VERSION=${1:-"8.1.0"}
PHP_DOWNLOAD_SHA256=${2:-"some-sha256-hash"} # You can specify the sha256 hash for the downloaded PHP package.
COMPOSER_VERSION=${3:-"2.4.4"}

# Function to install PHP
function install_php() {
  # Download and install PHP
  PHP_DOWNLOAD_URL="https://www.php.net/distributions/php-${PHP_VERSION}.tar.bz2"

  echo "Downloading PHP ${PHP_VERSION}..."
  curl -fsSL "$PHP_DOWNLOAD_URL" -o php.tar.bz2
  echo "${PHP_DOWNLOAD_SHA256} php.tar.bz2" | sha256sum -c -

  # Extract PHP source
  tar -xjf php.tar.bz2 -C /usr/local/
  rm php.tar.bz2

  cd /usr/local/php-${PHP_VERSION}

  # Prepare the build environment
  ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --enable-soap --enable-sockets --with-openssl --enable-bcmath --with-curl --enable-intl --enable-fpm --enable-mbregex
  make -j$(nproc) && make install

  # Set symlinks for php and php-fpm commands
  ln -s /usr/local/php/bin/php /usr/local/bin/php
  ln -s /usr/local/php/sbin/php-fpm /usr/local/sbin/php-fpm

  # Verify PHP installation
  php -v
}

# Function to install Composer
function install_composer() {
  # Download Composer installer
  echo "Downloading Composer..."
  curl -fsSL https://getcomposer.org/installer -o composer-installer.php

  # Install Composer
  php composer-installer.php --install-dir=/usr/local/bin --filename=composer

  # Clean up the installer
  rm composer-installer.php

  # Verify Composer installation
  composer --version
}

# Install PHP
install_php

# Install Composer
install_composer

echo "PHP and Composer installed successfully!"
Edited by zli