Run docker-compose build in .gitlab-ci.yml

前端 未结 9 1230
臣服心动
臣服心动 2020-12-12 14:06

I have a .gitlab-ci.yml file which contains following:

image: docker:latest

services:
  - docker:dind
         


        
9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-12 14:41

    If you don't want to provide a custom docker image with docker-compose preinstalled, you can get it working by installing Python during build time. With Python installed you can finally install docker-compose ready for spinning up your containers.

    image: docker:latest
    
    services:
    - docker:dind
    
    before_script:
    - apk add --update python py-pip python-dev && pip install docker-compose # install docker-compose
    - docker version
    - docker-compose version
    
    test:
      cache:
        paths:
        - vendor/
      script:
      - docker-compose up -d
      - docker-compose exec -T php-fpm composer install --prefer-dist
      - docker-compose exec -T php-fpm vendor/bin/phpunit --coverage-text --colors=never --whitelist src/ tests/
    

    Use docker-compose exec with -T if you receive this or a similar error:

    $ docker-compose exec php-fpm composer install --prefer-dist
    Traceback (most recent call last):
      File "/usr/bin/docker-compose", line 9, in 
        load_entry_point('docker-compose==1.8.1', 'console_scripts', 'docker-compose')()
      File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 62, in main
        command()
      File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 114, in perform_command
        handler(command, command_options)
      File "/usr/lib/python2.7/site-packages/compose/cli/main.py", line 442, in exec_command
        pty.start()
      File "/usr/lib/python2.7/site-packages/dockerpty/pty.py", line 338, in start
        io.set_blocking(pump, flag)
      File "/usr/lib/python2.7/site-packages/dockerpty/io.py", line 32, in set_blocking
        old_flag = fcntl.fcntl(fd, fcntl.F_GETFL)
    ValueError: file descriptor cannot be a negative integer (-1)
    ERROR: Build failed: exit code 1
    

提交回复
热议问题