I try to use Gitlab CI with docker-compose but I always get this error :
$ 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
I use docker with shell
runner, as follows :
[[runners]]
name = "direct runner"
url = MY_GITLAB_URL
token = REPO_GITLAB_TOKEN
executor = "shell"
[runners.cache]
Here's my docker-compose.yml
file :
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
And here's my .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
Do you guys have any idea on how to resolve this ?
Because I tried directly from shell using gitlab-runner
user and executing the same cmds i didn't have any error. I tried to run the docker-compose exec
with the -T
flag and there is another error : ERROR: Job failed: exit status 1
with no additionnal message
This question help me find how to solve that problem.
Simply adding a -T
arg after the exec helped tremendously
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