Integración pruebas unitarias con CI. #11

Merged
narenas merged 10 commits from helpers/ci-integration into main 2024-09-26 12:01:01 +02:00
3 changed files with 126 additions and 0 deletions

46
Jenkinsfile vendored 100644
View File

@ -0,0 +1,46 @@
pipeline {
agent {
node {
label 'jenkins-slave'
}
}
stages {
stage('Build Environmen') {
steps {
//Build environment
sh 'docker compose -f docker-compose-ci.yaml 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'
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 /report/phpunit.xml'
sh 'docker cp ogcore-php:/report/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 -f docker-compose-ci.yaml down'
sh 'docker compose -f docker-compose-ci.yaml rm -f'
}
}
}

View File

@ -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:

View File

@ -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