From b2db582f02f1497d4b4da788ccc687c8e1c99fbf Mon Sep 17 00:00:00 2001 From: adrinr Date: Mon, 30 Jan 2023 18:15:29 +0000 Subject: [PATCH] Use docker compose for test-containers --- hosting/.env | 2 - hosting/docker-compose.test.yaml | 59 ++++++++++++++++++++++++++ jestTestcontainersConfigGenerator.js | 17 +++----- packages/worker/src/tests/jestSetup.ts | 6 +-- 4 files changed, 67 insertions(+), 17 deletions(-) create mode 100644 hosting/docker-compose.test.yaml diff --git a/hosting/.env b/hosting/.env index 7616487c40..c5638a266f 100644 --- a/hosting/.env +++ b/hosting/.env @@ -8,8 +8,6 @@ MINIO_ACCESS_KEY=budibase MINIO_SECRET_KEY=budibase COUCH_DB_PASSWORD=budibase COUCH_DB_USER=budibase -COUCHDB_PASSWORD=budibase -COUCHDB_USER=budibase REDIS_PASSWORD=budibase INTERNAL_API_KEY=budibase diff --git a/hosting/docker-compose.test.yaml b/hosting/docker-compose.test.yaml new file mode 100644 index 0000000000..bd329f1869 --- /dev/null +++ b/hosting/docker-compose.test.yaml @@ -0,0 +1,59 @@ +version: "3" + +# optional ports are specified throughout for more advanced use cases. + +services: + minio-service: + restart: on-failure + # Last version that supports the "fs" backend + image: minio/minio:RELEASE.2022-10-24T18-35-07Z + ports: + - 9000 + - 9001 + environment: + MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY} + MINIO_SECRET_KEY: ${MINIO_SECRET_KEY} + command: server /data --console-address ":9001" + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"] + interval: 30s + timeout: 20s + retries: 3 + + couchdb-service: + # platform: linux/amd64 + restart: on-failure + image: budibase/couchdb + environment: + - COUCHDB_PASSWORD=${COUCH_DB_PASSWORD} + - COUCHDB_USER=${COUCH_DB_USER} + ports: + - 5984 + - 4369 + - 9100 + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:5984/_up"] + interval: 30s + timeout: 20s + retries: 3 + + redis-service: + restart: on-failure + image: redis + command: redis-server --requirepass ${REDIS_PASSWORD} + ports: + - 6379 + healthcheck: + test: ["CMD", "redis-cli", "ping"] + + # wait-for-load: + # container_name: wait + # image: curlimages/curl + # depends_on: + # minio-service: + # condition: service_healthy + # couchdb-service: + # condition: service_healthy + # redis-service: + # condition: service_healthy + # restart: always diff --git a/jestTestcontainersConfigGenerator.js b/jestTestcontainersConfigGenerator.js index ad032ed82e..ba91090a91 100644 --- a/jestTestcontainersConfigGenerator.js +++ b/jestTestcontainersConfigGenerator.js @@ -1,16 +1,9 @@ - - module.exports = dependenciesEnv => { return { - devEnv: { - image: "budibase/dependencies", - tag: "latest", - ports: [6379, 5984, 9000], - env: dependenciesEnv, - wait: { - type: "text", - text: "Test environment started...", - }, - } + dockerCompose: { + composeFilePath: "../../hosting", + composeFile: "docker-compose.test.yaml", + startupTimeout: 10000, + }, } } diff --git a/packages/worker/src/tests/jestSetup.ts b/packages/worker/src/tests/jestSetup.ts index 89ffb85b95..1e98c528fd 100644 --- a/packages/worker/src/tests/jestSetup.ts +++ b/packages/worker/src/tests/jestSetup.ts @@ -30,14 +30,14 @@ const globalSafe = global as any overrideConfigValue( "COUCH_DB_PORT", - globalSafe.__TESTCONTAINERS_DEVENV_PORT_5984__ + globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"] ) overrideConfigValue( "COUCH_DB_URL", - `http://${globalSafe.__TESTCONTAINERS_DEVENV_IP__}:${globalSafe.__TESTCONTAINERS_DEVENV_PORT_5984__}` + `http://${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_COUCHDB-SERVICE-1_PORT_5984__"]}` ) overrideConfigValue( "MINIO_URL", - `http://${globalSafe.__TESTCONTAINERS_DEVENV_IP__}:${globalSafe.__TESTCONTAINERS_DEVENV_PORT_9000__}` + `http://${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_IP__"]}:${globalSafe["__TESTCONTAINERS_MINIO-SERVICE-1_PORT_9000__"]}` )