prix
prix

Reputation: 101

GitLab CI run docker container of other Repository

I am generally still relatively new to the GitLab CI topic and unfortunately I cannot test this myself yet, so this is more of a theoretical attempt. I want to start a Docker container from one of my other projects in Gitlab in the CI pipeline of my main project. This Container (I now call it Mock-Container) is created and published in the GitLab CI pipeline of the corresponding project and contains various mocked services. In the project in which I want to run the Mock-Container, it should be able to start that container in the GitLab CI.

I know it is possible to use a build of the project in a different stage in the same pipeline, like here for example:

variables:
  DOCKER_HOST: tcp://docker:2376
  DOCKER_TLS_CERTDIR: "/certs"
  CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
  CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest

is it for example possible if the $CI_REGISTRY_IMAGE used in CONTAINER-IMAGE-Variables is like:

registry.gitlab.com/foo/bar/mainproject

to add a variable here like:

MOCK_CONTAINER_IMAGE: registry.gitlab.com/foo/bar/mockproject:latest

so I could for example could use it in the services list in the test stage:

build:
  stage: build
  image: quay.io/podman/stable
  script:
    - podman login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY --log-level=debug
    - podman build --format docker --pull -t $CONTAINER_TEST_IMAGE .
    - podman push $CONTAINER_TEST_IMAGE

test:
  stage: test
  image:
    name: postman/newman
    entrypoint: [ "" ]
  services:
    - name: $CONTAINER_TEST_IMAGE
      alias: main-project
    - name: $MOCK_CONTAINER_IMAGE
      alias: mock-container
  ...

Is this possible or is there a better way to achieve this.

Upvotes: 0

Views: 1619

Answers (1)

navidanindya
navidanindya

Reputation: 178

If you're asking that you want to set a variable in the .gitlab-ci.yml file with the registry URL of the other container like this:

variables:
  MOCK_CONTAINER_IMAGE: registry.gitlab.com/foo/bar/mockproject:latest

then yes you can. And you can use the variable in different stages in your file as you please. If you want to pull this image here from the registry, you can do that in a stage as well.

Check this reference for more info: https://docs.gitlab.com/ee/ci/yaml/#variables

Upvotes: 2

Related Questions