Search code examples
phplaraveldockergitlab-ciphpredis

Gitlab CI configuration with Laravel Docker Redis wrong host or port


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
...

Solution

  • 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:

    variables:
      REDIS_PORT: 6379
    

    If anyone finds documentation about this variable and maybe more options, let me know!