Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing extra commands to a docker image from bitbucket-piplines.yml

Trying to set the default charset and collation of a mysql:5.7 docker image using Bitbucket Pipelines, the documentation is a little vague mentioning:

If you need to configure the underlying database engine further, refer to the official Docker Hub image for details.

This page that the bitbucket documentation sends you to suggests that it is possible... at least via docker:

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

So my question is how do I pass these parameters in: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

I have seen people use command: parameter in the YML for bitbucket-pipelines however the pipeline config editor on bitbucket says it's not valid there:

definitions:
  services:
    mysql:
      image: mysql:5.7
      command: ['--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']
      ports:
        - "3306:3306"
      variables:
        MYSQL_DATABASE: $MY_DATABASE
        MYSQL_ROOT_PASSWORD: $MY_PW
like image 256
zanderwar Avatar asked Nov 14 '22 22:11

zanderwar


1 Answers

It seems that it is not possible to pass commands to containers that run as services at this point. I was able to find the schema of the YAML file that defines the pipelines (check line 365). Not only you can't set the command, but you also can't set the ports. Fortunately, 3306 is the default one.

As as workaround I'd suggest you build your own Docker image, based on the mysql:5.7 and change the CMD statement to mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci (you can see how the mysql image's CMD look's like from here). After that, you have to push the image to a registry to which your Bitbucket runner has access to and use this image for your pipeline.

The following Dockerfile might do the job for you:

FROM mysql:5.7

CMD ["mysqld", "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci"]

At the end, your definition will look like this:

definitions:
  services:
    mysql:
      image: your-custom-mysql-image:5.7
      variables:
        MYSQL_DATABASE: $MY_DATABASE
        MYSQL_ROOT_PASSWORD: $MY_PW
like image 199
theUndying Avatar answered Dec 15 '22 16:12

theUndying