4

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?

1 Answer 1

7

Build your own docker image

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.

Steps

  1. write a dockerfile
  2. build, push your docker image to somewhere
  3. replace image: php:7.2 in ci.yml
  4. commit, push your change and run pipeline in GitLab

Dockerfile

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

Build, Push image to somewhere

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

update .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

Last step

And now, commit the changes and push to your GitLab server.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.