Services
Covered Gitlab features : 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.
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 ! |
🚨 Solution
Project : https://gitlab.com/gitlab-workshop/solutions/blob/226c045240c0362f2bf28fedbfc092ba5d1fb591/ // REF(services:database)
Pipeline : https://gitlab.com/gitlab-workshop/solutions/pipelines/275964665 // REF(services:database)
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
🚨 Solution
Project : https://gitlab.com/gitlab-workshop/solutions/blob/650e90701f9477cb117cde490a541dd73dd46fb1/ // REF(services:variables)
Pipeline : https://gitlab.com/gitlab-workshop/solutions/pipelines/275964804 // REF(services:variables)