Services

Covered Gitlab features : services

services

La seule solution pour que ce soit encore plus sale, ça serait de demander aux clients de chier directement par terre ! Je vois que ça.

— Le tavernier
Kaamelott S05E06

Use an external database

Our application is cool, but uses on-memory data. Now we would like to switch data on a postgres database. Services are designed for that and offers you to run a side container linked to your job container to play your tests on a real database !

📝 Instructions

➡️ Modify both unit and e2e tests jobs to add a service using a postgres image :

unit:
    ...
    services:
        - postgres:alpine
    ...

e2e:
    ...
    services:
        - postgres:alpine
    ...

➡️ Modify the src/test/resources/application.yml file with the following :

spring:
  datasource:
    url: jdbc:postgresql://postgres:5432/postgres
    username: postgres
    password: mysecretpassword
  jpa:
    properties:
      hibernate:
        jdbc:
          lob:
            non_contextual_creation: true
    generate-ddl: true
    hibernate:
      ddl-auto: create

➡️ Use git to commit and push your modifications :

git add .
git commit -m "chore(ci): test from a postgres database"
git push

➡️ Follow your job execution and note changes

Tests now use the postgres external database, we are in real conditions !


Inject custom variables

📝 Instructions

➡️ Add the following global variables in your .gitlab-ci.yml :

POSTGRES_DB: postgres
POSTGRES_USER: proxyuser
POSTGRES_PASSWORD: test-password

➡️ Modify the src/test/resources/application.yml file with the following :

spring:
  datasource:
    url: jdbc:postgresql://postgres:5432/postgres
    username: proxyuser
    password: test-password
  jpa:
    properties:
      hibernate:
        jdbc:
          lob:
            non_contextual_creation: true
    generate-ddl: true
    hibernate:
      ddl-auto: create

➡️ Use git to commit and push your modifications :

git add .
git commit -m "chore(ci): change database default credentials"
git push

➡️ Follow your job execution and note changes