GitLab CI & persistent MySQL

Hi,

Is it possible to persist MySQL data across build stages?

I have two different stages - build and deploy. Build successfully creates a MySQL database populated with data, however when I come to the deploy stage (which has build as a dependency) and perform a mysqldump it’s returning an empty database.

Has anyone done this or is there any guides out there for reference?

Thanks

Dont really see why you should want this? Or better said; I dont think you should want to do this.

Anywho;

  1. What type of runner are you using? Docker, shell, ssh?
  2. How many runners do you have?

You should know that every job ran by the runner(s) should be designed as as standalone job or use a single point of reference. E.g. in some of my projects we build docker containers and push them to a registry in the first job and pull them in the second to run tests on them. In my before_script section I define consistent tags for the images so the names persist over jobs.

In your case you could also have a look at the so called build artifacts. I think it’s dirty but you could create an artifact from lets say /var/lib/mysql and use that artifact in the next job to load that directory before starting MySQL.

Thanks for the reply.

My use case is that I want to pull a remote database, build my application and test that a database upgrade works as part of a build/test stage with the staging database. Then for certain branches, on a ‘deploy’ stage, I want to push a review app from scratch where no host/database currently exists.

Currently I’m using the Docker runner and there is just the 1 private runner - /var/lib/mysql would be a good solution but is this volume on the service available to be passed as a build artifact? I thought the stage would be have to be ran as image: mysql to be able to do this?

Hmm, no dont think you can use a service image volume as artifact source. Unless you could mount an exposed volume in your job. I personally prefer to run the ‘service’ containers in my image (required docker-in-docker though) so I can control them.

You could run a mysqldump command at the end of your build job and use that output as an artifact to be used at your deploy job (based on your OP original problem).