加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

php-GitlabCi使用docker和mysql服务缓慢构建

发布时间:2020-12-16 03:25:59 所属栏目:安全 来源:网络整理
导读:我正在使用gitlab-ci-multirunner 9.3.0和GitLab社区版9.3.5 当我在本地虚拟盒环境中运行php单元测试时,总测试(30)大约需要: Time: 5 minutes,Memory: 96.00MB 在我的gitlab主机上运行相同的测试,总共需要 Time: 41.68 minutes,Memory: 97.75MB 这些测试需

我正在使用gitlab-ci-multirunner 9.3.0和GitLab社区版9.3.5

当我在本地虚拟盒环境中运行php单元测试时,总测试(30)大约需要:

Time: 5 minutes,Memory: 96.00MB

在我的gitlab主机上运行相同的测试,总共需要

Time: 41.68 minutes,Memory: 97.75MB

这些测试需要mysql并在每个测试上执行数据库创建和夹具加载.

我的DockerFile:

FROM tetraweb/php:5.6

# Install additional packages
RUN apt-get clean && apt-get -qq update
RUN apt-get -qq upgrade -y
RUN apt-get install -qq -y apt-utils
RUN apt-get install -qq -y mysql-client libmagickwand-dev libgeoip-dev -y --no-install-recommends
RUN pecl install imagick apcu-4.0.11 geoip
RUN docker-php-ext-enable exif gd gettext intl mcrypt mysql mysqli opcache pdo_mysql zip memcache apcu imagick geoi

我的gitlab-ci.yml:

variables:
  TIMEZONE: Europe/Berlin
  MYSQL_DATABASE: test
  MYSQL_ROOT_PASSWORD: test-root
  MYSQL_USER: test
  MYSQL_PASSWORD: asecurething
  SYMFONY_ENV: "test"

stages:
  - test
  - deploy

test:
  image: test-image-php:5.6
  services:
    - mariadb:latest
  stage: test
  only:
    - branches
  except:
    - master
  script:
      - export COMPOSER_CACHE_DIR=x/cache/composer
      - SYMFONY_ENV=test composer install --no-progress --no-interaction
      - chmod +x bin/console
      - php vendor/phpunit/phpunit/phpunit --coverage-text --colors=never

我真的认为那是造成巨大差异的mysql服务故障.
什么是提高我的phpunit测试性能的最佳方法?

最佳答案
我正在使用gitlab-ci 10.3.0,其中在服务器上的测试花费了40分钟,而在Mac上的测试花费了2分钟.除了Mac使用SSD的硬盘外,服务器的性能均超出Mac.

不知道是否合适的解决方案,但我修改了跑步者的配置以匹配Docker Executor – Mounting a directory in RAM中的设置.

我在config.toml中添加了以下内容:

[runners.docker]
# For the main container
[runners.docker.tmpfs]
    "/var/lib/mysql" = "rw,noexec"

# For services
[runners.docker.services_tmpfs]
    "/var/lib/mysql" = "rw,noexec"

我还设法将服务器上的构建时间减少到2分钟.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读