Skip to content

Please run service containers in dedicated network to reach all together

Description

According to the documentation you just link (--link) service containers to runner.

Firstly linking deprecated in docker. Second it does not allow reach one service to another.

My intention use services for testing application to do not manage containers lifecycle and I have tried something similar to:

main-build-job:
  stage: build
  script:
    -- <something which build and push "${PRIVATE_DOCKER_REGISTRY}/ourapp:${CI_BUILD_REF}_${CI_PIPELINE_ID}">

test-rest:
  stage: test
  variables:
    GIT_STRATEGY: "none"
  services:
    - ${PRIVATE_DOCKER_REGISTRY}/testdb:latest
    - ${PRIVATE_DOCKER_REGISTRY}/ourapp:${CI_BUILD_REF}_${CI_PIPELINE_ID}
  script:
    - >
      i=0; until sleep 1 && (( i++ )) && http --check-status --timeout 1 "http://egaisapp:8080/portal-api/rest/check/db/version"; do
        [ $i -ge $WAIT_START_TIMEOUT_SEC ] && echo "Timeout wait APP start!" && exit 2
        echo "Waiting APP start (res: $?). Attempt: $i"
      done
    - time ./gradlew --no-daemon --stacktrace :portal-api:rest-client:test

What problem there is ourapp container can't reach testdb

Proposal

On start stage generate unique name as you do with runner containers and create network like runner-713101cd-project-15-concurrent-network. Then attach all containers (including runner) to it on start. And delete on job end with containers.

Links / references

In https://gitlab.com/gitlab-org/gitlab-ce/issues/25000 I request much more expensive request which may supersede this one.