This is the first time I use gitlab CI, so if there are some observations regarding the configuration it would be great to hear them
I have this configuration of CI pipeline for a laravel project in gitalb, in it, I just run the tests suits with PHPUnit:
image: php:7.2
cache:
paths:
- vendor/
- node_modules/
before_script:
- apt-get update -yqq
- apt-get install git libzip-dev libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq
- docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache bcmath
- pecl install xdebug
- docker-php-ext-enable xdebug
- curl -sS https://getcomposer.org/installer | php
- php composer.phar check-platform-reqs
- php composer.phar install
- cp .env.testing .env
- php artisan key:generate
- php artisan config:clear
test:
script:
- php vendor/bin/phpunit --coverage-text --colors=never
when the test is triggered it took a duration of 12 minutes 20 seconds is there a way to use caching to speed up the job?
In GitLab CI, you can define cache:
to temporary store project dependencies. In your ci.yml, you already did. The majority of the running time of your project pipeline was wasted on apt-get install
. Since to cache dependencies install from apt-get install
will be complicated, build your own docker image that included dependencies from apt-get
for testing will be better.
image: php:7.2
in ci.ymlDockerfile
FROM php:7.2
RUN set -eux; \
apt-get update -yqq; \
apt-get install git libzip-dev libcurl4-gnutls-dev libicu-dev libmcrypt-dev libvpx-dev libjpeg-dev libpng-dev libxpm-dev zlib1g-dev libfreetype6-dev libxml2-dev libexpat1-dev libbz2-dev libgmp3-dev libldap2-dev unixodbc-dev libpq-dev libsqlite3-dev libaspell-dev libsnmp-dev libpcre3-dev libtidy-dev -yqq; \
docker-php-ext-install mbstring pdo_mysql curl json intl gd xml zip bz2 opcache bcmath; \
pecl install xdebug; \
docker-php-ext-enable xdebug
docker build --tag image-name:tag-name --file Dockerfile .
docker tag image-name:tag-name registry.example.com/organization/image-name:tag-name
# I assume you've already authenticated by your registry
docker push registry.example.com/organization/image-name:tag-name
.gitlab-ci.yml
image: registry.example.com/organization/image-name:tag-name
cache:
paths:
- vendor/
- node_modules/
before_script:
- curl -sS https://getcomposer.org/installer | php
- php composer.phar check-platform-reqs
- php composer.phar install
- cp .env.testing .env
- php artisan key:generate
- php artisan config:clear
test:
script:
- php vendor/bin/phpunit --coverage-text --colors=never
And now, commit the changes and push to your GitLab server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With