Commit dcd72f91 authored by Cédric Girardot's avatar Cédric Girardot

Build : Ajoute les tests unitaires et fonctionnels dans Jenkins

Change-Id: I78476ec651cb014d6f9d8ca2400442a3881dc334
parent 0c8650c8
......@@ -2,80 +2,80 @@
pipeline {
agent any
environment {
PHP_VERSION = sh(script: './jenkins-env.sh PHP_VERSION', returnStdout: true).trim()
COMPOSER_VERSION = sh(script: './jenkins-env.sh COMPOSER_VERSION', returnStdout: true).trim()
NODE_VERSION = sh(script: './jenkins-env.sh NODE_VERSION', returnStdout: true).trim()
ENVIRONMENT = 'jenkins-review'
}
stages {
stage('Tests') {
failFast true
parallel {
stage('Tests Symfony PHP') {
agent {
dockerfile {
filename 'Dockerfile'
dir './docker/php'
additionalBuildArgs '--build-arg PHP_VERSION=${PHP_VERSION} --build-arg COMPOSER_VERSION=${COMPOSER_VERSION} --build-arg ENVIRONMENT=${ENVIRONMENT}'
args '-v "/var/lib/jenkins/composer/auth.json:/home/.composer/auth.json"'
}
stage('App environment') {
agent {
dockerfile {
filename 'Dockerfile'
dir './docker/lamp'
additionalBuildArgs '--build-arg PHP_VERSION=7.2'
args '-u root --privileged -v "/var/lib/jenkins/composer/auth.json:/home/.composer/auth.json"'
}
}
stages {
stage('Build') {
environment {
YARN_CACHE_FOLDER = "${env.WORKSPACE}/.cache/yarn/v6"
}
stages {
stage("Composer install") {
steps {
dir('appli_sf') {
sh "composer config cache-dir '${env.WORKSPACE}/.cache/.composer'"
sh 'composer install --no-progress --no-suggest --no-interaction --no-scripts'
}
}
}
stage("Symfony linters") {
steps {
dir('appli_sf') {
sh 'bin/console lint:yaml --no-interaction config'
sh 'bin/console lint:yaml --no-interaction translations'
}
}
steps {
sh 'sed -i "s#/var/www/html#${WORKSPACE}/appli_sf/public#" /etc/apache2/sites-available/000-default.conf'
sh '/run.sh'
sh 'cp .env.dist .env'
dir('appli_sf') {
sh 'cp /etc/hosts ~/hosts.new'
sh 'sed -i "s/127.0.0.1.*/127.0.0.1 localhost database/" ~/hosts.new'
sh 'cp -f ~/hosts.new /etc/hosts'
sh 'cp .env.dist .env'
sh "composer config cache-dir '${env.WORKSPACE}/.cache/.composer'"
sh 'composer install --no-progress --no-suggest --no-interaction --no-scripts'
sh 'yarn && yarn run build'
sh 'bin/console doctrine:schema:update --force'
sh 'bin/console cache:clear'
sh 'chown -R www-data: .'
}
stage("Code Sniffer") {
steps {
dir('appli_sf') {
sh './vendor/bin/phpcs'
}
}
}
}
stage("Symfony linters") {
steps {
dir('appli_sf') {
sh 'bin/console lint:yaml --no-interaction config'
sh 'bin/console lint:yaml --no-interaction translations'
}
stage("PHP Lint") {
steps {
dir('appli_sf') {
sh './vendor/bin/phplint --no-progress --no-interaction'
}
}
}
}
stage("Code Sniffer") {
steps {
dir('appli_sf') {
sh './vendor/bin/phpcs'
}
stage("PHPStan") {
steps {
dir('appli_sf') {
sh './vendor/bin/phpstan analyse --no-progress --no-interaction'
}
}
}
}
stage("PHP Lint") {
steps {
dir('appli_sf') {
sh './vendor/bin/phplint --no-progress --no-interaction'
}
}
}
stage('Build Node') {
agent {
dockerfile {
filename 'Dockerfile'
dir './docker/node'
additionalBuildArgs '--build-arg NODE_VERSION=${NODE_VERSION}'
stage("PHPStan") {
steps {
dir('appli_sf') {
sh './vendor/bin/phpstan analyse --no-progress --no-interaction'
}
}
environment {
YARN_CACHE_FOLDER = "${env.WORKSPACE}/.cache/yarn/v6"
}
stage("Unit tests") {
steps {
dir('appli_sf') {
sh 'bin/phpunit tests/UnitTests'
}
}
}
stage("Functional tests") {
steps {
dir("appli_sf") {
sh 'yarn install --frozen-lockfile'
sh 'yarn run build'
dir('appli_sf') {
sh 'bin/phpunit tests/FunctionalTests'
}
}
}
......@@ -89,3 +89,4 @@ pipeline {
}
}
}
......@@ -27,7 +27,7 @@ APP_THEME=
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
#DATABASE_URL="mysqli://user:password@database:3306/database"
DATABASE_URL="mysqli://notaires:password@database:3306/notaires"
DATABASE_URL="mysqli://notaires:password@127.0.0.1:3306/notaires"
###< doctrine/doctrine-bundle ###
###> symfony/mailer ###
......
......@@ -21,6 +21,7 @@
<env name="DATABASE_URL" value="mysqli://notaires:password@database:3306/notaires"/>
<env name="MAILER_DSN" value="smtp://mail:1025"/>
<env name="MAILER_SENDER" value="no-reply@depnot.local"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled" />
</php>
<testsuites>
......
FROM ubuntu:18.04
ENV BOOT2DOCKER_ID 1000
ENV BOOT2DOCKER_GID 50
# Tweaks to give Apache/PHP write permissions to the app
RUN usermod -u ${BOOT2DOCKER_ID} www-data && \
usermod -G staff www-data && \
useradd -r mysql && \
usermod -G staff mysql
RUN groupmod -g $(($BOOT2DOCKER_GID + 10000)) $(getent group $BOOT2DOCKER_GID | cut -d: -f1)
RUN groupmod -g ${BOOT2DOCKER_GID} staff
# Install packages
ENV DEBIAN_FRONTEND noninteractive
RUN set -eux; \
apt-get update; \
apt-get install -y \
supervisor \
wget \
apache2 \
mariadb-server \
php \
php-xml \
php-mysql \
php-pdo \
php-gd \
php-intl \
php-mbstring \
php-zip \
libapache2-mod-php \
curl \
gnupg2 \
jq; \
echo "ServerName localhost" >> /etc/apache2/apache2.conf;
# Install yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn
# Add image configuration and scripts
ADD files/start-apache2.sh /start-apache2.sh
ADD files/start-mysqld.sh /start-mysqld.sh
ADD files/run.sh /run.sh
RUN chmod 755 /*.sh
ADD files/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Remove pre-installed database
RUN rm -rf /var/lib/mysql
# Add MySQL utils
ADD files/create_mysql_users.sh /create_mysql_users.sh
# Add composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" && \
php composer-setup.php && \
php -r "unlink('composer-setup.php');" && \
mv composer.phar /usr/local/bin/composer
# config to enable .htaccess
ADD files/apache_default /etc/apache2/sites-available/000-default.conf
RUN a2enmod rewrite
# Configure /app folder with sample app
RUN mkdir -p /app && rm -fr /var/www/html && ln -s /app /var/www/html
#Environment variables to configure php
ENV PHP_UPLOAD_MAX_FILESIZE 10M
ENV PHP_POST_MAX_SIZE 10M
ENV PHP_VERSION 7.2
WORKDIR /app
CMD ["/run.sh"]
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory />
Options Indexes FollowSymLinks MultiViews
# To make wordpress .htaccess work
AllowOverride All
Require all granted
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
# To make wordpress .htaccess work
AllowOverride All
Require all granted
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
#
# Set HTTPS environment variable if we came in over secure
# channel.
SetEnvIf x-forwarded-proto https HTTPS=on
</VirtualHost>
#!/bin/bash
/usr/bin/mysqld_safe > /dev/null 2>&1 &
RET=1
while [[ RET -ne 0 ]]; do
echo "=> Waiting for confirmation of MySQL service startup"
sleep 5
mysql -uroot -e "status" > /dev/null 2>&1
RET=$?
done
mysql -uroot -e "CREATE USER 'notaires'@'localhost' IDENTIFIED BY 'password'"
mysql -uroot -e "GRANT USAGE ON *.* TO 'notaires'@'%' IDENTIFIED BY 'password'"
mysql -uroot -e "CREATE DATABASE IF NOT EXISTS notaires"
mysql -uroot -e "GRANT ALL PRIVILEGES ON notaires.* TO 'notaires'@'%'"
echo "=> Done!"
mysqladmin -uroot shutdown
#!/bin/bash
#
# Prepare our container for initial boot.
# Where does our MySQL data live?
VOLUME_HOME="/var/lib/mysql"
#######################################
# Use sed to replace apache php.ini values for a given PHP version.
# Globals:
# PHP_UPLOAD_MAX_FILESIZE
# PHP_POST_MAX_SIZE
# PHP_TIMEZONE
# Arguments:
# $1 - PHP version i.e. 5.6, 7.3 etc.
# Returns:
# None
#######################################
function replace_apache_php_ini_values () {
echo "Updating for $1"
sed -ri -e "s/^upload_max_filesize.*/upload_max_filesize = ${PHP_UPLOAD_MAX_FILESIZE}/" \
-e "s/^post_max_size.*/post_max_size = ${PHP_POST_MAX_SIZE}/" /etc/php/$1/apache2/php.ini
sed -i "s/;date.timezone =/date.timezone = Europe\/Paris/g" /etc/php/$1/apache2/php.ini
}
if [ -e /etc/php/$PHP_VERSION/apache2/php.ini ]; then replace_apache_php_ini_values "$PHP_VERSION"; fi
#######################################
# Use sed to replace cli php.ini values for a given PHP version.
# Globals:
# PHP_TIMEZONE
# Arguments:
# $1 - PHP version i.e. 5.6, 7.3 etc.
# Returns:
# None
#######################################
function replace_cli_php_ini_values () {
sed -i "s/;date.timezone =/date.timezone = Europe\/Paris/g" /etc/php/$1/cli/php.ini
}
if [ -e /etc/php/$PHP_VERSION/cli/php.ini ]; then replace_cli_php_ini_values "$PHP_VERSION"; fi
sed -i "s/export APACHE_RUN_GROUP=www-data/export APACHE_RUN_GROUP=staff/" /etc/apache2/envvars
if [ -n "$APACHE_ROOT" ];then
rm -f /var/www/html && ln -s "/app/${APACHE_ROOT}" /var/www/html
fi
mkdir -p /var/run/mysqld /var/lib/mysql
# Setup user and permissions for MySQL and Apache
chmod -R 770 /var/lib/mysql
chmod -R 770 /var/run/mysqld
# Tweaks to give Apache/PHP write permissions to the app
chown -R www-data:staff /var/www
chown -R www-data:staff /app
chown -R www-data:staff /var/lib/mysql
chown -R www-data:staff /var/run/mysqld
chown -R www-data:staff /var/log/mysql
if [ -e /var/run/mysqld/mysqld.sock ]; then rm /var/run/mysqld/mysqld.sock; fi
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mariadb.conf.d/50-server.cnf
sed -i "s/user.*/user = www-data/" /etc/mysql/mariadb.conf.d/50-server.cnf
if [[ ! -d $VOLUME_HOME/mysql ]]; then
echo "=> An empty or uninitialized MySQL volume is detected in $VOLUME_HOME"
echo "=> Installing MySQL ..."
# Try the 'preferred' solution
mysqld --initialize-insecure
# IF that didn't work
if [ $? -ne 0 ]; then
# Fall back to the 'depreciated' solution
mysql_install_db > /dev/null 2>&1
fi
echo "=> Done!"
/create_mysql_users.sh
else
echo "=> Using an existing volume of MySQL"
fi
exec supervisord
#!/bin/bash
source /etc/apache2/envvars
exec apache2 -D FOREGROUND
#!/bin/bash
exec /usr/bin/pidproxy /var/run/mysqld/mysqld.pid /usr/bin/mysqld_safe
[supervisord]
nodaemon=false
[program:mysqld]
command=/start-mysqld.sh
numprocs=1
autostart=true
autorestart=true
[program:apache2]
command=/start-apache2.sh
numprocs=1
autostart=true
autorestart=true
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment