Is it possible to configure N postgresql service instance in a GitLab CI?
Asked Answered
R

1

10

Is there a way to configure 5 postgresql instance in a Gitlab CI?

This is my configuration:

image: something:latest

variables:
  SPRING_PROFILES_ACTIVE: gitlab-ci
  POSTGRES_USER: gitlab-ci
  POSTGRES_PASSWORD: gitlab-ci
  POSTGRES_DB: DATA_V1
  LDAP_DOMAIN: domain.com
  LDAP_ORGANISATION: org
  LDAP_ADMIN_PASSWORD: hello-ci

services:
- name: docker:dind
- name: osixia/openldap:1.1.9
- name: postgres:10.0-alpine
  alias: user-management-db
- name: postgres:10.0-alpine
  alias: company-management-db

It generate errors in CI :

[0;m[0KStarting service docker:dind ...
[0;m[0KPulling docker image docker:dind ...
[0;m[0KUsing docker image docker:dind ID=sha256:4998cc824d9ac8e4be3bb89afa004c87911e796cde15f0676d437fcb8a8dd06b for docker service...
[0;m[0KStarting service osixia/openldap:1.1.9 ...
[0;m[0KPulling docker image osixia/openldap:1.1.9 ...
[0;m[0KUsing docker image osixia/openldap:1.1.9 ID=sha256:0670342c5b82a10b014f0cf1060752ccb740cd8bd28a704ac3fa1191a4e31594 for osixia/openldap service...
[0;m[0KStarting service postgres:10.0-alpine ...
[0;m[0KPulling docker image postgres:10.0-alpine ...
[0;m[0KUsing docker image postgres:10.0-alpine ID=sha256:0f0ff37589e948e31d9e64bb6c1b31cdbd4d7d0336b656cb6094be568e54ad04 for postgres service...
[0;m[0;33mWARNING: Service postgres:10.0-alpine is already created. Ignoring.
[0;m[0KStarting service postgres:10.0-alpine ...
[0;m[0KPulling docker image postgres:10.0-alpine ...
[0;m[0KUsing docker image postgres:10.0-alpine ID=sha256:0f0ff37589e948e31d9e64bb6c1b31cdbd4d7d0336b656cb6094be568e54ad04 for postgres service...
[0;m[0;33mWARNING: Service postgres:10.0-alpine is already created. Ignoring.
[0;m[0KStarting service postgres:10.0-alpine ...
[0;m[0KPulling docker image postgres:10.0-alpine ...
[0;m[0KUsing docker image postgres:10.0-alpine ID=sha256:0f0ff37589e948e31d9e64bb6c1b31cdbd4d7d0336b656cb6094be568e54ad04 for postgres service...
[0;m[0;33mWARNING: Service postgres:10.0-alpine is already created. Ignoring.
[0;m[0KStarting service postgres:10.0-alpine ...
[0;m[0KPulling docker image postgres:10.0-alpine ...
[0;m[0KUsing docker image postgres:10.0-alpine ID=sha256:0f0ff37589e948e31d9e64bb6c1b31cdbd4d7d0336b656cb6094be568e54ad04 for postgres service...
[0;m[0;33mWARNING: Service postgres:10.0-alpine is already created. Ignoring.
[0;m[0KStarting service postgres:10.0-alpine ...
[0;m[0KPulling docker image postgres:10.0-alpine ...
[0;m[0KUsing docker image postgres:10.0-alpine ID=sha256:0f0ff37589e948e31d9e64bb6c1b31cdbd4d7d0336b656cb6094be568e54ad04 for postgres service...
[0;m[0;33mWARNING: Service postgres:10.0-alpine is already created. Ignoring.
[0;m[0KStarting service postgres:10.0-alpine ...
[0;m[0KPulling docker image postgres:10.0-alpine ...
[0;m[0KUsing docker image postgres:10.0-alpine ID=sha256:0f0ff37589e948e31d9e64bb6c1b31cdbd4d7d0336b656cb6094be568e54ad04 for postgres service...
[0;m[0;33mWARNING: Service postgres:10.0-alpine is already created. Ignoring.

It also can't be configured individually with variables that way.

So far my workaround was to create only one service with multiple database that won't be always possible. (two ldap for example)

Did anybody have ever tried such configuration in Gitlab-CI?

Seems like it has been repaired in gitlab 9.3 https://gitlab.com/gitlab-org/gitlab-runner/merge_requests/639/pipelines

Rovelli answered 4/11, 2017 at 18:22 Comment(0)
D
3

It's possible. For example:

unit-test:
  services:
    - name: registry.company.com/postgres:14.6
      alias: db1
      variables:
        POSTGRES_DB: "db1"
        POSTGRES_USER: "user1"
        POSTGRES_PASSWORD: "pw1"
        POSTGRES_INITDB_ARGS: "--encoding=UTF8 --no-locale"
    - name: registry.company.com/postgres:14.6
      alias: db2
      variables:
        POSTGRES_DB: "db2"
        POSTGRES_USER: "user2"
        POSTGRES_PASSWORD: "pw2"
        POSTGRES_INITDB_ARGS: "--encoding=UTF8 --no-locale"

This will start two postgreses, one reachable under the hostname db1 and the other with the hostname db2.

Here is the documentation: https://docs.gitlab.com/ee/ci/services/index.html#available-settings-for-services

Derwood answered 27/1, 2023 at 15:13 Comment(1)
It must have changed since I post, because I was using a custom image for N containers as this was before not possible.Rovelli

© 2022 - 2024 — McMap. All rights reserved.