Git Product home page Git Product logo

liquibase-docker's Introduction

liquibase-docker

A lightweight Docker for running Liquibase

DockerHub: liquibase - GitHub: liquibase-docker

Liquibase Docker images with drivers

Liquibase by itself cannot connect to a database. To do actual database work, you will need a JDBC driver.

⚠ You probably want one of these other Docker images where I've bundled a database driver alongside Liquibase ⚠

DockerHub Image GitHub Source
liquibase-postgres liquibase-postgres-docker
liquibase-mysql liquibase-mysql-docker
liquibase-mariadb liquibase-mariadb-docker
liquibase-sqlite liquibase-sqlite-docker

Usage

Using your own derived Dockerfile

You can use this image by creating your own Dockerfile which inherits using a FROM line:

FROM kilna/liquibase-mysql-docker
ENV LIQUIBASE_HOST=database.server
ENV LIQUIBASE_DATABASE=dbname
ENV LIQUIBASE_USERNAME=user
ENV LIQUIBASE_PASSWORD=pass
COPY changelog.xml /workspace

Make sure to create an appropriate changelog.xml in the same directory as your Dockerfile.

Then you can build your derived Dockerfile to an image tagged 'changelog-image':

$ docker build --tag changelog-image .

Any time you make changes to the example project, you'll need to re-run the docker build command above, or you can using docker volumes as described below to sync local filesystem changes into the container. To run liquibase using the new image you can:

$ docker run changelog-image liquibase updateTestingRollback

Since the working directory within the container is /workspace, and since the entrypoint generates a a liquibase.properties file using the provided environment variables, it will know to look for changelog.xml by default and apply the change. See the environment variables below to change this behavior.

Using the image directly with a mounted docker volume

If you'd like to apply a changelog to a MySQL database without deriving your own container, run the contiainer appropriate to your database like so... where /local/path/to/changelog/ is the directory where a valid changelog.xml exists:

$ docker run -e LIQUIBASE_HOST=database.server -e LIQUIBASE_USERNAME=user -e LIQUIBASE_PASSWORD=pass \
    -e LIQUIBASE_DATABASE=dbname -v /local/path/to/changelog/:/workspace/ kilna/liquibase-mysql \
    liquibase updateTestingRollback

Environment Variables and liquibase.properties

This docker image has a working Liquibase executable in the path, and an entrypoint which auto-generates a liquibase.properties file.

In order to create the liquibase.properties file, it uses the follow environment variables when the image is started with 'docker run':

Environment Variable Purpose Default
LIQUIBASE_HOST Database host to connect to* db
LIQUIBASE_PORT Database port to connect to* driver-specific integer
example: 3306 for MySQL/MariaDB
LIQUIBASE_DATABASE Database name to connect to† liquibase
LIQUIBASE_USERNAME Username to connect to database as* liquibase
LIQUIBASE_PASSWORD Password for username* liquibase
LIQUIBASE_CHANGELOG Default changelog filename to use changelog.xml
LIQUIBASE_LOGLEVEL Log level as defined by Liquibase
Valid values: debug, info, warning, severe, off
info
LIQUIBASE_CLASSPATH JDBC driver filename driver-specific
example: /opt/jdbc/mysql-jdbc.jar
LIQUIBASE_DRIVER JDBC object path driver-specific
example: org.mariadb.jdbc.Driver
LIQUIBASE_URL JDBC URL for connection driver-specific
example: jdbc:mariadb://${HOST}:${PORT}/${DATABASE}
LIQUIBASE_DEBUG If set to 'yes', when docker run is executed, will show the values of all LIQUIBASE_* environment variables and describes any substitutions performed on liquibase.properties unset

* Not applicable to file-based databases (SQLite) - † Used as the filename for file-based databases (SQLite)

The generated liquibase.properties file is loaded into the default working dir /workspace (which is also shared as a docker volume). The /workspace/liquibase.properties file will have any variables substituted each time a 'docker run' command is performed... so you can load your own /workspace/liquibase.properties file and put ${HOST} in it, and it will be replaced with the LIQUIBASE_HOST environment variable.

If you want to see what the contents of the generated liquibase.properties file are, you can:

$ docker run image-name cat liquibase.properties

liquibase-docker's People

Contributors

kilna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

liquibase-docker's Issues

Write docs

Can't expect people to use it if they don't know how to use it :)

Telnet disappears from container if you rebuild

because alpine-java:8 has dropped several packages
alpine-java:8 has been updated, as of 10 days ago, without releasing a new version.
The underlying alpine has moved forward in versions and several included packages are no longer present in the underlying busybox (eg: telnet) having being moved to -extras.
as of gliderlabs/docker-alpine#397
(i was rebuilding this from source so that i could use a newer liquibase version)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.