docker-compose使用gitlab-ci抛出错误

时间:2017-10-09 09:44:19

标签: docker-compose gitlab

我尝试将 Gitlab CI docker-compose 一起使用,但我总是收到此错误:

$ docker-compose up -d --build
Creating network "backoffice_default" with the default driver
Building php
Creating backoffice_database_1 ... 
Creating backoffice_database_1 ... done
Creating backoffice_php_1 ... 
Creating backoffice_php_1 ... done

$ docker-compose exec php composer -v
Traceback (most recent call last):
  File "bin/docker-compose", line 6, in <module>
  File "compose/cli/main.py", line 68, in main
  File "compose/cli/main.py", line 121, in perform_command
  File "compose/cli/main.py", line 464, in exec_command
  File "site-packages/dockerpty/pty.py", line 338, in start
  File "site-packages/dockerpty/io.py", line 32, in set_blocking
ValueError: file descriptor cannot be a negative integer (-1)
Failed to execute script docker-compose

我使用docker和shell runner,如下所示:

[[runners]]
  name = "direct runner"
  url = MY_GITLAB_URL
  token = REPO_GITLAB_TOKEN
  executor = "shell"
  [runners.cache]

这是我的docker-compose.yml文件:

version: '2'

services:

  database:
    image: mysql:latest
    environment:
      MYSQL_DATABASE: database
      MYSQL_ROOT_PASSWORD: mysql_strong_password
      MYSQL_USER: database
      MYSQL_PASSWORD: mysql_strong_password

  php:
    build: ./app/docker
    tty: true
    volumes:
      - ./app/docker/php.ini:/usr/local/etc/php/conf.d/custom.ini
      - ./:/var/www/symfony
    links:
      - database

这是我的.gitlab-ci.yml

stages:
- build
- cleanup_build
- test
- deploy
- cleanup

before_script:
- docker info

build:
  stage: build
  script:
  - docker-compose up -d --build
  - docker-compose exec php composer -v
  - docker-compose exec php composer install
  - docker-compose exec php php bin/console doctrine:schema:create --dump-sql --force
  - docker-compose exec php php bin/console doctrine:fixtures:load -n

cleanup_build:
  stage: cleanup_build
  script:
  - docker-compose config
  - docker-compose ps
  - docker-compose logs php
  - docker-compose logs database
  - exit 1
  when: on_failure

phpunit:
  stage: test
  script:
  - docker-compose exec -T php phpunit -c .

deploy:
  stage: deploy
  script:
  - echo "deploy to staging server"

cleanup:
  stage: cleanup
  script:
  - docker-compose down

你们对如何解决这个问题有什么想法吗? 因为我使用gitlab-runner用户直接从shell尝试并执行相同的cmds我没有任何错误。我尝试使用docker-compose exec标记运行-T并且还有另一个错误:ERROR: Job failed: exit status 1没有附加消息

1 个答案:

答案 0 :(得分:0)

This这个问题帮助我找到了解决该问题的方法。

在执行人员提供了极大帮助之后,只需添加一个-T参数