I’m working on a Gitlab CI configuration in the .gitlab-ci.yml file for a Laravel project which uses redis as Cache Driver. Within this configuration file I use an image which has all the linux packages, php extension which are used on our production environment. This includes the redis extension installed by pecl so phpredis can be used within Laravel.
After spending a fair amount of time into learning the process of continuous integration and the configuration of the gitlab ci file I encountered the following error on deploy of the image:
In PhpRedisConnector.php line 126:
Redis::connect() expects parameter 2 to be int, string given
parameter should be only the port as an int but somehow turned into tcp://111.111.11.11:6379
As documented https://docs.gitlab.com/ee/ci/services/redis.html the host in your .env should be redis so I had. Dumping the config during the deploy resulted in port being some tcp://111.111.11.11:6379 connection string and host being empty. There is no way this is changed within our application or any extension we use.
I use the https://hub.docker.com/_/redis/ as a service in the .gitlab-ci.yml.
...
services:
- name: redis:4
...
2
Answers
Solution found here: https://laracasts.com/discuss/channels/testing/gitlab-ci-weird-redis-host
This variable isn't documented anywhere but somehow it solves the problem. Add the following to your .gitlab-ci.yml file:
If anyone finds documentation about this variable and maybe more options, let me know!
This is expected behaviour from Docker.
In Gitlab CI, all
services
you define will be linked with your container which is running your job using Docker linking system.As describe here, when we link containers, Docker automatically creates ENVs in format:
And those ENVs from Docker will override yours.
alias
here will be the hostname of your container you defined inservices
. For example you define these services in your.gitlab-ci.yml
:So Docker will create the following ENVs respectively:
And note that, as described here, by default the following ENVs are also auto created based on service image’s name:
So in your code if you have any variable that has same name with the ones Docker creates, you may need to change your variable’s name otherwise it’ll be override by Docker. Or you can use the solution from
@MmynameStackflow
above, passvariables
in your Gitlab CI config file to override what Docker does.