How to test with database requirement

Hello,

I figure here is the best place to ask due to the expertise.

I have a repo is setup with one folder for the back-end and one for the front-end. For my tests in the back-end I require a postgres database. When I am testing locally its fine because I have the database on my laptop but for the gitlab runner I do not know the correct way to set up a database for testing. What would be the correct way to go about this?

Thanks,

Alexander McRae

You could a database as a service for your tests to run against. You will just need to populate the service with data when you are running the tests.
https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-a-service

The services keyword defines just another Docker image that is run during your job and is linked to the Docker image that the image keyword defines. This allows you to access the service image during build time.

The service image can run any application, but the most common use case is to run a database container, e.g., mysql . It’s easier and faster to use an existing image and run it as an additional container than install mysql every time the project is built.

You are not limited to have only database services. You can add as many services you need to .gitlab-ci.yml or manually modify config.toml . Any image found at Docker Hub or your private Container Registry can be used as a service.

Services inherit the same DNS servers, search domains, and additional hosts as the CI container itself.

You can see some widely used services examples in the relevant documentation of CI services examples.

An example of using a Postgres service https://docs.gitlab.com/ee/ci/services/postgres.html

Thank you so much this is exactly what I was looking for! :slight_smile: