Commit 1bc34dcc authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'master' into 'master'

feat: alpine compatibility

Closes #20

See merge request to-be-continuous/php!51
parents c513c788 1378659b
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ the image.

For this, you may use the following files (located in `PHP_PROJECT_DIR`):

* `.php_apt_get` containing required system libraries (in a single line),
* `.php_packages` containing required system libraries (in a single line),
* `.php_pecl` containing required PECL extensions (in a single line),
* `.php_ext` containing required PHP extensions (in a single line).

@@ -62,7 +62,7 @@ More info [in _How to install more PHP extensions_ chapter](https://hub.docker.c

Example: a project requires `php-gd` and `php-zip` extensions (themselves requiring `libzip-dev` and `libpng-dev` libraries)

`.php_apt_get`:
`.php_packages`:

```text
libzip-dev libpng-dev
+59 −18
Original line number Diff line number Diff line
@@ -257,24 +257,74 @@ stages:
    log_info "... done"
  }

  function maybe_install_pkg() {
    pkg_name="$1"
    cmd_name="${2:-$pkg_name}"
    if ! command -v "$cmd_name" > /dev/null
    then
      log_info "$pkg_name not found: install..."
      if command -v apt-get > /dev/null
      then
        apt-get -yqq install "$pkg_name" || log_warn "... failed to install $pkg_name"
      elif command -v apk > /dev/null
      then
        apk add -q --no-cache "$pkg_name" || log_warn "... failed to install $pkg_name"
      elif command -v yum > /dev/null
      then
        yum install -yq "$pkg_name" || log_warn "... failed to install $pkg_name"
      elif command -v dnf > /dev/null
      then
        dnf install -yq "$pkg_name" || log_warn "... failed to install $pkg_name"
      elif command -v zypper > /dev/null
      then
        zypper -nq install "$pkg_name" || log_warn "... failed to install $pkg_name"
      else
        log_error "... didn't find any known package manager to install $pkg_name!"
        exit 1
      fi
    fi
  }

  # install PHP system dependencies
  function install_project_deps() {
    if [[ -f ".php_apt_get" ]]
    # prepare package manager
    if command -v apt-get > /dev/null
    then
      log_info "file \\e[33;1m.php_apt_get\\e[0m found: install project system dependencies..."
      # shellcheck disable=SC2046
      apt-get install -yqq $(cat .php_apt_get)
      apt-get -yqq update
    fi

    if [[ -f ".php_pecl" ]]
    # install zip & unzip (required to unzip dist packages) git (required by composer) linux-headers $PHPIZE_DEPS (required by pecl)
    packages="zip unzip git linux-headers $PHPIZE_DEPS"
    for pkg in $packages
    do
      maybe_install_pkg "$pkg"
    done

    packages_file=".php_packages"
    if [[ -f ".php_apt_get" ]]
    then
      log_info "file \\e[33;1m.php_pecl\\e[0m file found: install project extensions..."
      log_warn "using .php_apt_get is deprecated: use .php_packages instead"
      packages_file=".php_apt_get"
    fi
    if [[ -f "$packages_file" ]]
    then
      log_info "file \\e[33;1m.php_packages\\e[0m found: install project system dependencies..."
      # shellcheck disable=SC2013
      for pkg in $(cat "$packages_file")
      do
        maybe_install_pkg "$pkg"
      done
    fi

    # set proxy for pear
    # shellcheck disable=SC2154
    if [[ "${http_proxy}"  ]]; 
    then
      pear config-set http_proxy "${http_proxy}"
    fi
    if [[ -f ".php_pecl" ]]
    then
      log_info "file \\e[33;1m.php_pecl\\e[0m file found: install project extensions..."
      # shellcheck disable=SC2046
      pecl install $(cat .php_pecl)
    fi
@@ -338,9 +388,6 @@ stages:
    - !reference [.php-scripts]
    - install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
    - cd $PHP_PROJECT_DIR
    # install zip & unzip (required to unzip dist packages) git (required by composer)
    - apt-get update -yqq
    - apt-get install zip unzip git -yqq
    # install project system dependencies (if any)
    - install_project_deps
    # install project dependencies
@@ -358,12 +405,6 @@ php-unit:
  stage: build
  script:
    # install Xdebug
    - |
      # set proxy for pear
      if [[ "${http_proxy}" ]];
      then
        pear config-set http_proxy "${http_proxy}"
      fi
    - pecl install xdebug
    - docker-php-ext-enable xdebug
    - set_xdebug_mode