testcontainers/testcontainers-java

Support init scripts for `MongoDBContainer` without manually customizing the `WaitStrategy`

Open

#3.066 geöffnet am 1. Aug. 2020

Auf GitHub ansehen
 (16 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Java (1.588 Forks)batch import
good first issuemodules/mongodbtype/feature

Repository-Metriken

Stars
 (7.535 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 2T 17h) (2 gemergte PRs in 30 T)

Beschreibung

A container initialized as follows, fails to start:

MongoDBContainer c = new MongoDBContainer(MONGO_IMAGE)
		.withEnv("MONGO_INITDB_ROOT_USERNAME", "root")
		.withEnv("MONGO_INITDB_ROOT_PASSWORD", "password" )
		.withFileSystemBind("init/mongo-init.js",
			"/docker-entrypoint-initdb.d/mongo-init.js", BindMode.READ_ONLY)
		;
		c.start()

Not sure but probably because the docker-entrypoint.sh, in case of presence of init-db scripts, does a shutdown and a restart of the process after executing them:

if [ -n "$shouldPerformInitdb" ]; then
...
		echo
		for f in /docker-entrypoint-initdb.d/*; do
			case "$f" in
				*.sh) echo "$0: running $f"; . "$f" ;;
				*.js) echo "$0: running $f"; "${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f"; echo ;;
				*)    echo "$0: ignoring $f" ;;
			esac
			echo
		done

		"${mongodHackedArgs[@]}" --shutdown
		rm -f "$pidfile"
...

Contributor Guide