From 45231350410c3fec7e214bf3ebceaaed79b81964 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 14:01:35 +0200 Subject: [PATCH 01/10] Creating first Jenkinsfile for testing --- Jenkinsfile | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..30daa2d --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,29 @@ +pipeline { + agent { + node { + label 'jenkins-slave' + } + } + + stages { + stage('Build Environmen') { + steps { + sh 'docker compose up --build -d' + } + } + stage('Install dependencies') { + steps { + sh 'docker exec ogcore-php composer install' + sh 'docker exec ogcore-php php bin/console lexik:jwt:generate-keypair --overwrite' + sh 'docker exec ogcore-php php bin/console doctrine:migrations:migrate --no-interaction' + sh 'docker exec ogcore-php php bin/console doctrine:fixtures:load --no-interaction' + sh 'docker exec ogcore-php php bin/console app:load-default-user-groups' + } + } + stage('Tests') { + steps { + sh 'docker compose exec php bin/phpunit' + } + } + } +} From 784fbfe89c6db21bdc2de533c37489ab69c4559c Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 14:29:40 +0200 Subject: [PATCH 02/10] Collecting report after execute tests --- Jenkinsfile | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 30daa2d..6f60e72 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,13 +17,30 @@ pipeline { sh 'docker exec ogcore-php php bin/console lexik:jwt:generate-keypair --overwrite' sh 'docker exec ogcore-php php bin/console doctrine:migrations:migrate --no-interaction' sh 'docker exec ogcore-php php bin/console doctrine:fixtures:load --no-interaction' - sh 'docker exec ogcore-php php bin/console app:load-default-user-groups' } } stage('Tests') { steps { - sh 'docker compose exec php bin/phpunit' + sh 'docker compose exec php bin/phpunit --log-junit phpunit.xml' } } } + post { + always { + xunit ( + testTimeMargin: '3000', + thresholdMode: 'percent', + thresholds: [ + skipped: 0, + unstable: 0, + failed: 0 + ], + tools: [ + PHPUnitJunit( + pattern: 'phpunit.xml' + ) + ] + ) + } + } } From 4ca1c51e7a04e560d4c48f80becb5fe5bcfc356b Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 14:32:35 +0200 Subject: [PATCH 03/10] Fix typo collecting info --- Jenkinsfile | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6f60e72..df1de67 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -28,13 +28,7 @@ pipeline { post { always { xunit ( - testTimeMargin: '3000', - thresholdMode: 'percent', - thresholds: [ - skipped: 0, - unstable: 0, - failed: 0 - ], + thresholds: [ skipped(failureThreshold: 0) , failed(failureThreshold: 0) ], tools: [ PHPUnitJunit( pattern: 'phpunit.xml' From 64848705b926c2063d64558ce6fc5294c7beef4d Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 15:46:04 +0200 Subject: [PATCH 04/10] Fixing typo in Jenkins --- Jenkinsfile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index df1de67..7575da5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,11 +29,7 @@ pipeline { always { xunit ( thresholds: [ skipped(failureThreshold: 0) , failed(failureThreshold: 0) ], - tools: [ - PHPUnitJunit( - pattern: 'phpunit.xml' - ) - ] + tools: [ PHPUnit(pattern: 'phpunit.xml') ] ) } } From 3db25efbcffafd430dc7c7e9c0c59f9a964ade7a Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 16:11:26 +0200 Subject: [PATCH 05/10] Clean workspace and add some comments --- Jenkinsfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 7575da5..7da3621 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,11 +8,13 @@ pipeline { stages { stage('Build Environmen') { steps { + # Build environment sh 'docker compose up --build -d' } } stage('Install dependencies') { steps { + # Install dependencies sh 'docker exec ogcore-php composer install' sh 'docker exec ogcore-php php bin/console lexik:jwt:generate-keypair --overwrite' sh 'docker exec ogcore-php php bin/console doctrine:migrations:migrate --no-interaction' @@ -21,16 +23,21 @@ pipeline { } stage('Tests') { steps { + # Run tests sh 'docker compose exec php bin/phpunit --log-junit phpunit.xml' } } } post { always { + # Publish JUnit test results xunit ( thresholds: [ skipped(failureThreshold: 0) , failed(failureThreshold: 0) ], tools: [ PHPUnit(pattern: 'phpunit.xml') ] ) + # Remove containers + sh 'docker compose down' + sh 'docker compose rm -f' } } } From 7425b549403032fe005b8be9d20853db039e91f3 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 16:13:03 +0200 Subject: [PATCH 06/10] Fix type --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7da3621..9ebbc9e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,13 +8,13 @@ pipeline { stages { stage('Build Environmen') { steps { - # Build environment + //Build environment sh 'docker compose up --build -d' } } stage('Install dependencies') { steps { - # Install dependencies + // Install dependencies sh 'docker exec ogcore-php composer install' sh 'docker exec ogcore-php php bin/console lexik:jwt:generate-keypair --overwrite' sh 'docker exec ogcore-php php bin/console doctrine:migrations:migrate --no-interaction' @@ -23,19 +23,19 @@ pipeline { } stage('Tests') { steps { - # Run tests + // Run tests sh 'docker compose exec php bin/phpunit --log-junit phpunit.xml' } } } post { always { - # Publish JUnit test results + // Publish JUnit test results xunit ( thresholds: [ skipped(failureThreshold: 0) , failed(failureThreshold: 0) ], tools: [ PHPUnit(pattern: 'phpunit.xml') ] ) - # Remove containers + // Remove containers sh 'docker compose down' sh 'docker compose rm -f' } From 5f6e2e86105bd46a0db45631f743ba532b8dee78 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 18:01:07 +0200 Subject: [PATCH 07/10] Fixing typo as threshols are characters and not integers --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9ebbc9e..4833c3c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,7 +32,7 @@ pipeline { always { // Publish JUnit test results xunit ( - thresholds: [ skipped(failureThreshold: 0) , failed(failureThreshold: 0) ], + thresholds: [ skipped(failureThreshold: '0') , failed(failureThreshold: '0') ], tools: [ PHPUnit(pattern: 'phpunit.xml') ] ) // Remove containers From 77ef4aca3f5040999b3ea794c5233d5dfd2d5f43 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 18:28:46 +0200 Subject: [PATCH 08/10] Avoid using volumes for static content for jenkins --- docker-compose-ci.yaml | 49 +++++++++++++++++++++++++++++++++++ docker/Dockerfile-jenkins-php | 31 ++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 docker-compose-ci.yaml create mode 100644 docker/Dockerfile-jenkins-php diff --git a/docker-compose-ci.yaml b/docker-compose-ci.yaml new file mode 100644 index 0000000..d6442f7 --- /dev/null +++ b/docker-compose-ci.yaml @@ -0,0 +1,49 @@ +services: + database: + container_name: ogcore-database + image: mariadb:10.11 + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: ogcore + MYSQL_PASSWORD: root + MYSQL_USER: admin + ports: + - 3336:3306 + volumes: + - database_data:/var/lib/mysql + networks: + - ogcore-network + + nginx: + container_name: ogcore-nginx + build: + context: . + dockerfile: ./docker/Dockerfile-nginx + depends_on: + - php + ports: + - 8080:80 + volumes: + - ./public:/var/www/html/public:cached + networks: + - ogcore-network + + php: + container_name: ogcore-php + build: + context: . + dockerfile: ./docker/Dockerfile-jenkins-php + depends_on: + - database + environment: + XDEBUG_CLIENT_HOST: 127.17.0.1 + XDEBUG_CLIENT_PORT: 9003 + PHP_IDE_CONFIG: serverName=ogcore + networks: + - ogcore-network + +volumes: + database_data: + +networks: + ogcore-network: diff --git a/docker/Dockerfile-jenkins-php b/docker/Dockerfile-jenkins-php new file mode 100644 index 0000000..370b3c2 --- /dev/null +++ b/docker/Dockerfile-jenkins-php @@ -0,0 +1,31 @@ +FROM php:8.3-fpm-alpine +ENV COMPOSER_ALLOW_SUPERUSER=1 + +# Install PHP extensions +RUN docker-php-ext-install pdo mysqli pdo_mysql opcache + +# Install Zip and more extension +RUN apk add --no-cache bash libzip-dev zip unzip +RUN docker-php-ext-install zip + +# Install Composer +RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer +RUN composer self-update + +# Install bash +RUN apk add --no-cache bash git jq moreutils openssh rsync yq + +ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ +RUN chmod +x /usr/local/bin/install-php-extensions +RUN install-php-extensions sockets + +# Add xdebug +RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS +RUN apk add --update linux-headers +RUN pecl install xdebug +RUN docker-php-ext-enable xdebug +RUN apk del -f .build-deps + +COPY ./docker/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini +COPY . /var/www/html + From ec86e867c342142d8d35ac09e0f57babf357c15e Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 18:30:21 +0200 Subject: [PATCH 09/10] Build container for CI --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4833c3c..d226d6d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,7 @@ pipeline { stage('Build Environmen') { steps { //Build environment - sh 'docker compose up --build -d' + sh 'docker compose -f docker-compose-ci.yaml up --build -d' } } stage('Install dependencies') { From 440a5f8bf1c0cfd387fc538b47765f11165ec606 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Wed, 25 Sep 2024 18:42:18 +0200 Subject: [PATCH 10/10] Adjust to copy the report --- Jenkinsfile | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d226d6d..faa778c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -19,12 +19,15 @@ pipeline { sh 'docker exec ogcore-php php bin/console lexik:jwt:generate-keypair --overwrite' sh 'docker exec ogcore-php php bin/console doctrine:migrations:migrate --no-interaction' sh 'docker exec ogcore-php php bin/console doctrine:fixtures:load --no-interaction' + // Create report directory + sh 'docker exec ogcore-php mkdir -p /report' } } stage('Tests') { steps { // Run tests - sh 'docker compose exec php bin/phpunit --log-junit phpunit.xml' + sh 'docker compose exec php bin/phpunit --log-junit /report/phpunit.xml' + sh 'docker cp ogcore-php:/report/phpunit.xml .' } } } @@ -36,8 +39,8 @@ pipeline { tools: [ PHPUnit(pattern: 'phpunit.xml') ] ) // Remove containers - sh 'docker compose down' - sh 'docker compose rm -f' + sh 'docker compose -f docker-compose-ci.yaml down' + sh 'docker compose -f docker-compose-ci.yaml rm -f' } } }