10

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
zanderwar
  • 3,440
  • 3
  • 28
  • 46

1 Answers1

2

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
theUndying
  • 1,526
  • 3
  • 11
  • https://jira.atlassian.com/browse/BCLOUD-16016 I still tried to find in the configuration how to fix it, but really, there is no such possibility, as bitbucket itself says. The only option is to create your own image. – Oleh Diachenko Aug 04 '22 at 14:01