Liquibase and its MongoDB extension conveniently packaged in a Docker image that works out of the box.
This dockerfile is also available as a Docker Image on DockerHub: Docker Repository
This repository is forked from https://github.com/mmarcon/liquibase-mongo-docker, all congrats to him !
- Liquibase
- Liquibase official Docker image (without MongoDB extension)
- Liquibase MongoDB extension
First, build the Docker image
$ docker build . --tag "liquibase-mongo:4.16.1"
Then use it as follow.
$ docker run --rm -v \
"`pwd`/example/changelog:/liquibase/changelog" liquibase-mongo:4.16.1 \
--url="mongodb://host.docker.internal:27017/liquibase_test" --changeLogFile=changelog/changelog.xml --logLevel=info update
$ docker run --rm -v \
"`pwd`/example/changelog:/liquibase/changelog" liquibase-mongo:4.16.1 \
--url="mongodb://host.docker.internal:27017/liquibase_test" --logLevel=info tag tagName
$ docker run --rm -v \
"`pwd`/example/changelog:/liquibase/changelog" liquibase-mongo:4.16.1 \
--url="mongodb://host.docker.internal:27017/liquibase_test" --changeLogFile=changelog/changelog.xml --logLevel=info rollbackCount 1
$ docker run --rm -v \
"`pwd`/example/changelog:/liquibase/changelog" liquibase-mongo:4.16.1 \
--url="mongodb://host.docker.internal:27017/liquibase_test" --changeLogFile=changelog/changelog.xml --logLevel=info rollback tagName
Note: Because Liquibase runs inside the Docker container and I am testing it against a local
mongod
running outside docker, I am pointing to it by usinghost.docker.internal:27017
as the host.
- After running
update
You can use Compass to check that the namespaceliquibase_test.myCollection
exists, has an index onname
and some schema validation rules where thename
field is required. You can also use MongoDB for VS Code, connect to your local MongoDB Server and run the verify-update.mongodb playground. - After running
rollbackCount 1
You can use Compass to check that the namespaceliquibase_test.myCollection
exists, has an index onname
and some schema validation rules where thename
andaddress
fields are required. You can also use MongoDB for VS Code, connect to your local MongoDB Server and run the verify-rollback.mongodb playground.
You can run the same playground files from the new MongoDB Shell. For example, to verify the update:
$ mongosh
Current sessionID: 6e6edacc4e2d50aa4430fb22
Connecting to: mongodb://127.0.0.1:27017
Using MongoDB: 4.4.0
Using Mongosh Beta: 1.0.6
For more information about mongosh, please see our docs: https://docs.mongodb.com/mongodb-shell/
> .load ./example/playgrounds/verify-update.mongodb
- The
generateChangeLog
command is currently not supported for MongoDB.
- Add tests to verify that the image is working
- Add automatic update of the Dockerfile when the version of Liquibase changes
- Find a way to generate checksum for dependencies of the docker image