javaspringoracle-databasespring-boottestcontainers

Oracle testcontainer is not starting in the pipeline


I am using Java 21 and Spring Boot 3.3.3, and starting a test container with Oracle DB in my integration tests like this:

build.gradle:

testImplementation "org.testcontainers:oracle-free:1.20.1"

Oracle container setup:

import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.testcontainers.oracle.OracleContainer;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.time.Duration;


public class OracleTestContainerExtension implements BeforeAllCallback {

    private static final String ORACLE_IMAGE = "gvenzl/oracle-free:23.5-slim-faststart";
    private static final String SYSTEM_USERNAME = "SYSTEM";

    private static final OracleContainer ORACLE_CONTAINER = new OracleContainer(ORACLE_IMAGE)
            .withStartupTimeout(Duration.ofMinutes(5))
            .withPassword("test_password")
            .withDatabaseName("test_db")
            .withReuse(true);

    @Override
    public void beforeAll(ExtensionContext context) throws Exception {
        if (!ORACLE_CONTAINER.isRunning()) {
            ORACLE_CONTAINER.start();

            createTablesAndQueues();

            System.setProperty("spring.datasource.url", ORACLE_CONTAINER.getJdbcUrl());
            System.setProperty("spring.datasource.username", SYSTEM_USERNAME);
            System.setProperty("spring.datasource.password", ORACLE_CONTAINER.getPassword());
        }
    }

    private void createTablesAndQueues() throws Exception {
        try (Connection connection = DriverManager.getConnection(
                ORACLE_CONTAINER.getJdbcUrl(),
                SYSTEM_USERNAME,
                ORACLE_CONTAINER.getPassword())) {

            Statement statement = connection.createStatement();
            statement.executeUpdate(loadFromResources("/data/sql/init/init_queue_tables_and_queues.sql"));

            statement.close();
        }
    }
}

Then I use this extension in the test:

@SpringBootTest(webEnvironment = RANDOM_PORT)
@ExtendWith(OracleTestContainerExtension.class)
class IntegrationTests {
  // tests
}

When I start my tests locally, they work, but if I start tests in the pipeline, I receive an error:

ERROR [Test worker] o.t.c.GenericContainer: Log output from the failed container:
    CONTAINER: starting up...
    CONTAINER: first database startup, initializing...
    CONTAINER: starting up Oracle Database...
    LSNRCTL for Linux: Version 23.0.0.0.0 - for Oracle Cloud and Engineered Systems on 25-JUN-2025 13:44:16
    Copyright (c) 1991, 2024, Oracle.  All rights reserved.
    Starting /opt/oracle/product/23ai/dbhomeFree/bin/tnslsnr: please wait...
    TNSLSNR for Linux: Version 23.0.0.0.0 - for Oracle Cloud and Engineered Systems
    System parameter file is /opt/oracle/product/23ai/dbhomeFree/network/admin/listener.ora
    Log messages written to /opt/oracle/diag/tnslsnr/7974453683d2/listener/alert/log.xml
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_FREE)))
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_FREE)))
    STATUS of the LISTENER
    ------------------------
    Alias                     LISTENER
    Version                   TNSLSNR for Linux: Version 23.0.0.0.0 - for Oracle Cloud and Engineered Systems
    Start Date                25-JUN-2025 13:44:17
    Uptime                    0 days 0 hr. 0 min. 0 sec
    Trace Level               off
    Security                  ON: Local OS Authentication
    SNMP                      OFF
    Default Service           FREE
    Listener Parameter File   /opt/oracle/product/23ai/dbhomeFree/network/admin/listener.ora
    Listener Log File         /opt/oracle/diag/tnslsnr/7974453683d2/listener/alert/log.xml
    Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_FREE)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=0.0.0.0)(PORT=1521)))
    The listener supports no services
    The command completed successfully
    ORA-00600: internal error code, arguments: [ksmcsg: failed to get total shm available], [], [], [], [], [], [], [], [], [], [], []
    ORA-27300: OS system dependent operation:Cannot open /proc/sys/kernel/shm failed with status: 75
    ORA-27301: OS failure message: Value too large for defined data type
    ORA-27302: failure occurred at: sskgmgtssa_1

My integration test stage for the GitLab pipeline is:

integration-tests:
  stage: test
  # There is a problem with gradle 8.12
  # Before changing the version to 8.12 you have to check if a test in the services is still running
  # Error loading shared library ld-linux-x86-64.so.2: No such file or directory
  image: dockerhub.devops.mycompany.com/gradle:8.14-jdk21-alpine
  cache:
    key: "$CI_COMMIT_REF_SLUG-gradle"
    paths:
      - ".gradle"
  variables:
    DOCKER_DRIVER: overlay2
    DOCKER_TLS_CERTDIR: "/certs"
    DOCKER_HOST: tcp://docker:2376
    DOCKER_TLS_VERIFY: 1
    DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
  services:
    - name: 'dockerhub.devops.mycompany.com/docker:28.3.0-dind' # DOCKER_DIND_IMAGE
      command: [ '--registry-mirror=https://dockerhub.devops.mycompany.com' ]
      alias: docker
  tags:
    - otc_run_sysbox_xl
  script:
    - $GRADLE_CLI_BIN ${TRACE+--debug} --build-cache --gradle-user-home $GRADLE_USER_HOME/ -x build integrationTest
  rules:
    - if: $GRADLE_INTEGRATION_TESTS_ENABLED == "true"
  needs:
    - gradle-build
  artifacts:
    when: on_success
    expire_in: 1 day
    paths:
      - ./**/build/reports/tests/integrationTest/*

I see that this happened after switching the GitLab runner in our infrastructure, and I can't use the old runner.

I also think the problem might be that Enhanced Container Isolation is enabled, but I haven't been able to figure out how to bypass it to solve my problem.

Any ideas?


Solution

  • From your runner tag otc_run_sysbox_xl I guess you are running on sysbox.

    Looks like you are running into Error Cannot open /proc/sys/kernel/shm failed with status: 75 #909

    It seems to be fixed by Fix access to /proc/sys/kernel/shm* inside container. #105