Olivier Massot 8 달 전
부모
커밋
4284bd6367
4개의 변경된 파일83개의 추가작업 그리고 66개의 파일을 삭제
  1. 22 3
      .gitlab-ci.yml
  2. 51 0
      Dockerfile
  3. 10 0
      docker/entrypoint.sh
  4. 0 63
      tests/ci_docker_install.sh

+ 22 - 3
.gitlab-ci.yml

@@ -1,20 +1,37 @@
 stages:
+  - build
   - test
 
 variables:
   APP_ENV: staging
   SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY
   XDEBUG_MODE: coverage
+  DOCKER_BUILDKIT: 1
 
 cache:
   paths:
     - ./vendor
+    - ~/.composer/cache
 
-before_script:
-  - bash tests/ci_docker_install.sh > /dev/null
-  - php -v
+build_image:
+  stage: build
+  image: docker:latest
+  services:
+    - docker:dind
+  variables:
+    DOCKER_TLS_CERTDIR: ""
+  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
+  rules:
+    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
 
 unit:
+  image: $CI_REGISTRY_IMAGE:latest
   stage: test
 
   script:
@@ -35,6 +52,7 @@ unit:
 #    - php bin/console d:s:v
 
 static_analysis:
+  image: $CI_REGISTRY_IMAGE:latest
   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,6 +62,7 @@ static_analysis:
       codequality: phpstan.json
 
 code_style:
+  image: $CI_REGISTRY_IMAGE:latest
   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 \
+    && 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