Browse Source

Merge branch 'V8-7250-ci---trouver-un-moyen-dviter-de-' into release/2.5

Olivier Massot 7 months ago
parent
commit
81c0a2fbb5
4 changed files with 92 additions and 71 deletions
  1. 31 8
      .gitlab-ci.yml
  2. 51 0
      Dockerfile
  3. 10 0
      docker/entrypoint.sh
  4. 0 63
      tests/ci_docker_install.sh

+ 31 - 8
.gitlab-ci.yml

@@ -1,5 +1,7 @@
 stages:
+  - build
   - test
+  - analysis
 
 variables:
   APP_ENV: staging
@@ -9,14 +11,29 @@ variables:
 cache:
   paths:
     - ./vendor
+    - ./composer.lock
+    - ~/.composer/cache
 
-before_script:
-  - bash tests/ci_docker_install.sh > /dev/null
-  - php -v
+build_image:
+  stage: build
+  image: docker:20.10
+  before_script:
+    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
+  script:
+    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
+    - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest
+    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
+    - docker push $CI_REGISTRY_IMAGE:latest
+
+.default_config: &default_config
+  image: $CI_REGISTRY_IMAGE:latest
+  before_script:
+    - composer config -g cache-dir .composer-cache
+    - HOST=ci composer install --prefer-dist --no-progress --no-interaction
 
 unit:
+  <<: *default_config
   stage: test
-
   script:
     - php vendor/phpunit/phpunit/phpunit --configuration phpunit.xml.dist --colors=never --no-interaction --testsuite=unit
     #- php vendor/phpunit/phpunit/phpunit --configuration phpunit.xml.dist --colors=never --no-interaction --no-coverage --testsuite=application
@@ -31,10 +48,14 @@ unit:
   coverage: '/^\s*Lines:\s*\d+.\d+\%/'
 
 #doctrine:
+#  <<: *default_config
+#  stage: test
 #  script:
 #    - php bin/console d:s:v
 
-static_analysis:
+code_quality:
+  <<: *default_config
+  stage: analysis
   script:
     - php vendor/bin/phpstan analyse -c phpstan.neon.dist --error-format gitlab > phpstan.json  # Display code quality in MR
     - php vendor/bin/phpstan analyse -c phpstan.neon.dist
@@ -44,8 +65,10 @@ static_analysis:
       codequality: phpstan.json
 
 code_style:
+  <<: *default_config
+  stage: analysis
+  before_script:
+    - composer config -g cache-dir .composer-cache
+    - HOST=ci composer install --prefer-dist --no-progress --no-interaction
   script:
     - php vendor/bin/php-cs-fixer check --config=.php-cs-fixer.dist.php
-
-
-

+ 51 - 0
Dockerfile

@@ -0,0 +1,51 @@
+FROM php:8.2-fpm
+
+# Installation des dépendances système
+RUN apt-get update && apt-get install -yqq --no-install-recommends \
+    apt-utils gnupg git build-essential openssh-client zip \
+    unzip zlib1g-dev libicu-dev g++ libzip-dev libpng-dev libtidy-dev libssl-dev \
+    libxslt-dev libxrender-dev libxrender1 libxt6 libxtst6 openssh-server \
+    xorg iputils-ping wget gdebi ca-certificates wget \
+    fontconfig acl procps libmagickwand-dev imagemagick \
+    && apt-get clean \
+    && rm -rf /var/lib/apt/lists/*
+
+# Installation des extensions PHP
+RUN docker-php-ext-install intl zip xsl \
+    && pecl install xdebug imagick \
+    && docker-php-ext-enable xdebug imagick
+
+# Configure docker
+#docker-php-ext-configure intl
+#docker-php-ext-install intl opcache pdo_mysql exif bcmath calendar gd tidy
+#docker-php-ext-enable libxslt-dev
+#docker-php-ext-enable intl
+#docker-php-ext-enable exif
+#docker-php-ext-enable tidy
+#docker-php-ext-install zip
+#docker-php-ext-install xsl
+#pecl install apcu-5.1.21
+
+# Configuration SSH
+RUN mkdir -p /root/.ssh && \
+    chmod 700 /root/.ssh && \
+    echo "StrictHostKeyChecking no" >> /root/.ssh/config
+
+# Installation de Composer
+COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
+
+# Configuration PHP
+RUN echo "memory_limit=2096M" > /usr/local/etc/php/conf.d/memory-limit.ini
+
+# Configuration Git
+RUN git config --global user.email "exploitation@opentalent.fr" && \
+    git config --global user.name "git"
+
+
+WORKDIR /app
+
+COPY docker/entrypoint.sh /entrypoint.sh
+RUN chmod +x /entrypoint.sh
+
+ENTRYPOINT ["/entrypoint.sh"]
+

+ 10 - 0
docker/entrypoint.sh

@@ -0,0 +1,10 @@
+#!/bin/bash
+
+# Configuration SSH au démarrage du conteneur
+if [ ! -z "$SSH_PRIVATE_KEY" ]; then
+    eval $(ssh-agent -s)
+    echo "$SSH_PRIVATE_KEY" | ssh-add -
+fi
+
+# Exécute la commande passée au conteneur
+exec "$@"

+ 0 - 63
tests/ci_docker_install.sh

@@ -1,63 +0,0 @@
-#!/bin/bash
-# Setup a php:8.2-fpm docker image
-
-# We need to install dependencies only for Docker
-[[ ! -e /.dockerenv ]] && exit 0
-
-# Quit on error
-set -xe
-
-# Install packages
-apt-get update
-apt-get install -yqq --fix-missing apt-utils gnupg git build-essential openssh-client zip
-
-apt-get update
-
-apt-get install -yqq --fix-missing --no-install-recommends unzip zlib1g-dev libicu-dev g++ \
-                               libzip-dev libpng-dev libtidy-dev libssl-dev \
-                               libxslt-dev libxrender-dev libxrender1 libxt6 libxtst6 openssh-server \
-                               xorg iputils-ping wget gdebi ca-certificates wget \
-                               fontconfig acl procps libmagickwand-dev imagemagick
-
-apt-get clean
-rm -r /var/lib/apt/lists/*
-
-# Configure docker
-#docker-php-ext-configure intl
-#docker-php-ext-install intl opcache pdo_mysql exif bcmath calendar gd tidy
-#docker-php-ext-enable libxslt-dev
-#docker-php-ext-enable intl
-#docker-php-ext-enable exif
-#docker-php-ext-enable tidy
-#docker-php-ext-install zip
-#docker-php-ext-install xsl
-#pecl install apcu-5.1.21
-
-pecl install imagick
-docker-php-ext-enable imagick
-
-# Install XDebug (required for coverage)
-pecl install xdebug
-docker-php-ext-enable xdebug
-
-# Run ssh-agent and add private key (/!\ Attention: la configuration du SSH est indispensable pour pouvoir cloner notre repo foselastica)
-eval $(ssh-agent -s)
-mkdir -p ~/.ssh
-chmod 700 ~/.ssh
-echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
-ssh-add <(echo "$SSH_PRIVATE_KEY")
-git config --global user.email "exploitation@opentalent.fr"
-git config --global user.name "git"
-
-# Install composer
-curl -sS https://composer.github.io/installer.sig > installer.sig
-php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
-php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
-php composer-setup.php
-php -r "unlink('composer-setup.php'); unlink('installer.sig');"
-
-# Config php
-echo "memory_limit=2096M" > /usr/local/etc/php/conf.d/memory-limit.ini
-
-# Install modules
-HOST=ci php composer.phar install --no-interaction --ignore-platform-reqs