Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BitBucket pipelines with testcontainer not working

I face this error when try to run bitbucket pipelines with test container

Could not start container java.lang.IllegalStateException: Container did not start correctly.

There is no another issues but maybe it's related to Binds? Logs:

"HostConfig":"Binds":["/opt/atlassian/pipelines/agent/build/src/test/resources:/opt/atlassian/pipelines/agent/build/src/test/resources:rw","/var/run/docker.sock:/docker.sock:rw"]

Pipelines config:

pipelines:
  pull-requests:
    '**':
       - step:
           name: Integration tests
           caches:
              - maven
           after-script:
              - pipe: atlassian/checkstyle-report:0.3.0
           script:
              - export TESTCONTAINERS_RYUK_DISABLED=true
              - export TESTCONTAINERS_CHECKS_DISABLE=true
              - mvn -B verify -Dsurefire.skip=true --file pom.xml
           services:
              - docker
       - step:
           name: Build
           caches:
              - maven
           after-script:
              - pipe: atlassian/checkstyle-report:0.3.0
           script:
              - mvn -B package --file pom.xml -DskipTests
           services:
              - docker
definitions:
   services:
      docker:
         memory: 3072

docker-compose.yml

services:
  db:
    image: postgres:14.1
    ports:
       - "5432:5432"
    expose:
       - "5432"
    networks:
       - example-network
    environment:
       - "POSTGRES_USER=${DB_USER:-postgres}"
       - "POSTGRES_PASSWORD=${DB_PASSWORD:-postgres}"
       - "POSTGRES_DB=${DB_SCHEMA:-testdb}"
    logging:
       driver: json-file
       options:
          mode: "non-blocking"
 networks:
    example-network:
       driver: bridge

docker compose container:

    DOCKER_COMPOSE_CONTAINER =
        new DockerComposeContainer(new File("src/test/resources/docker-compose.yml"))
                .withExposedService(SERVICE_NAME, SERVICE_PORT, 
    Wait.forListeningPort());
    DOCKER_COMPOSE_CONTAINER.start();

I also tried without TESTCONTAINERS_CHECKS_DISABLE=true but there was error like

Status 403: {"message":"authorization denied by plugin pipelines: -v only supports $BITBUCKET_CLONE_DIR and its subdirectories"}

Could anyone help with this please?

like image 786
puka Avatar asked Sep 10 '25 23:09

puka


1 Answers

As the error message you got explains, Bitbucket Pipelines Docker engine only lets mounting subdirectories of your project sources.

I don't know why you intend to mount /var/run/docker.sock or if you can avoid it, but the way Bitbucket usually forwards the Docker engine to spawned containers, e.g. in pipes, is by setting

...
--env=DOCKER_HOST="tcp://host.docker.internal:2375" \
--add-host="host.docker.internal:$BITBUCKET_DOCKER_HOST_INTERNAL" \
...

so might need to imitate that.

like image 128
N1ngu Avatar answered Sep 13 '25 13:09

N1ngu