Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

4.2 KB
Raw Blame
# Backing services for the backend test suites, deliberately separate from
# docker-compose.dev.yml so a test run cannot reach the data you develop against.
#
# That separation is not tidiness. The e2e harness (backend/e2e-test/vitest-environment-knex.ts)
# runs `DROP SCHEMA public CASCADE` on whatever database it is pointed at, before every run.
#
# Run through `make test-api-e2e`, which starts what it needs; `make down-test-suite-containers`
# tears it down. There are no volumes, so nothing here outlives the containers.

# Fixed so the project, and therefore the network name the test container joins, does not
# depend on the checkout directory.
name: infisical-test

services:
  db:
    image: postgres:14-alpine
    # Published so a suite can also be run from the host. A full run brings this stack up
    # alongside the dev stack, so the ports must not clash with it.
    ports:
      - "5436:5432"
    environment:
      POSTGRES_PASSWORD: infisical
      POSTGRES_USER: infisical
      POSTGRES_DB: infisical-test
    # Matches the dev database. The suite holds enough locks in one transaction to need it.
    command: postgres -c max_locks_per_transaction=512
    # `up --wait` treats a container with no healthcheck as ready once it is running, which for
    # Postgres is before it accepts connections, so the suite would fail on connect instead of
    # waiting for it.
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U infisical -d infisical-test"]
      interval: 2s
      timeout: 3s
      retries: 30

  redis:
    image: redis
    environment:
      - ALLOW_EMPTY_PASSWORD=yes
    ports:
      - "6380:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 2s
      timeout: 3s
      retries: 30

  # The suites themselves. Runs the same FIPS image as the dev stack, which is where the
  # native dependencies the suites need live (SoftHSM2, the Oracle client, the FIPS OpenSSL
  # build), and which pins the Node version so the host's does not matter.
  #
  # Behind a profile so `up` brings up only the backing services. `make test-api-e2e` runs it
  # with `compose run`, which starts its dependencies and waits for them to report healthy.
  api-tests:
    profiles: ["runner"]
    build:
      context: ./backend
      dockerfile: Dockerfile.dev.fips
      args:
        TOOLCHAIN_IMAGE: ${TOOLCHAIN_IMAGE:-ghcr.io/infisical/backend-fips-toolchain:main}
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      DB_CONNECTION_URI: postgres://infisical:infisical@db:5432/infisical-test?sslmode=disable
      REDIS_URL: redis://redis:6379
      AUTH_SECRET: something-random
      ENCRYPTION_KEY: p5e5k2j3+HIErjm02dzSrlhXc1xhdgoWvC6pox410rE=
      NODE_ENV: test
      # Defaults to info. Overridable so a run being debugged can see the queue lifecycle lines
      # without editing this file.
      PINO_LOG_LEVEL: ${PINO_LOG_LEVEL:-info}
      # The heap is set explicitly because Node derives its default from available memory, so
      # without this the suite's budget depends on the host: a 16GB CI runner gets about 4GB
      # and boots fine, while an 8GB Docker Desktop VM gets ~2GB and dies during environment
      # setup, before a single spec runs. Booting the whole server needs more than 2GB.
      NODE_OPTIONS: --force-fips --max-old-space-size=4096
      TELEMETRY_ENABLED: "false"
      # The secret rotation specs need these plus `make up-rotation-databases`. Left empty
      # otherwise, which is how a run without them behaves anyway.
      E2E_TEST_ORACLE_DB_19_HOST: ${E2E_TEST_ORACLE_DB_19_HOST:-}
      E2E_TEST_ORACLE_DB_19_USERNAME: ${E2E_TEST_ORACLE_DB_19_USERNAME:-}
      E2E_TEST_ORACLE_DB_19_PASSWORD: ${E2E_TEST_ORACLE_DB_19_PASSWORD:-}
      E2E_TEST_ORACLE_DB_19_DATABASE: ${E2E_TEST_ORACLE_DB_19_DATABASE:-}
    # The image bakes a copy of the source; these shadow it so a run uses the working tree and
    # editing a test needs no rebuild. Anything outside them (package.json, tsconfig.json) does.
    volumes:
      - ./backend/src:/app/src
      - ./backend/e2e-test:/app/e2e-test
      - ./backend/vitest.e2e.config.mts:/app/vitest.e2e.config.mts
      - ./backend/vitest.unit.config.mts:/app/vitest.unit.config.mts