include:
  - project: gitlab-ci-cd/general
    ref: main
    file: '/tagrelease.yml'

variables:
  SUPPORT_LATEST_TAG: 1
  VERSION: ${CI_COMMIT_TAG}

before_script:
  - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY

php:
  stage: build
  parallel:
    matrix:
      - ALPINE: '3.12'
        PHP: '7.4'
      - ALPINE: '3.12'
        PHP: '8.0'
      - ALPINE: '3.15'
        PHP: '8.1'
      - ALPINE: '3.17'
        PHP: '8.2'
      - ALPINE: '3.18'
        PHP: '8.3'
  script:
    - docker build --pull --build-arg ALPINE_VERSION=${ALPINE} --build-arg PHP_MAJOR_VERSION=${PHP} --build-arg VERSION=${VERSION} -t ${CI_REGISTRY_IMAGE}/php-${PHP}:${VERSION} .
    - docker push ${CI_REGISTRY_IMAGE}/php-${PHP}:${VERSION}
    - docker tag ${CI_REGISTRY_IMAGE}/php-${PHP}:${VERSION} ${CI_REGISTRY_IMAGE}/php-${PHP}:latest
    - docker push ${CI_REGISTRY_IMAGE}/php-${PHP}:latest
  only:
    - tags
