Skip to content

Commit

Permalink
Add liquibase
Browse files Browse the repository at this point in the history
  • Loading branch information
mblaschke committed Oct 10, 2016
1 parent b99e229 commit 18e06ef
Show file tree
Hide file tree
Showing 14 changed files with 324 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ web: webdevops/apache webdevops/apache-dev webdevops/nginx webdevops/nginx

applications: webdevops/typo3 webdevops/piwik

misc: webdevops/mail-sandbox webdevops/sphinx
misc: webdevops/mail-sandbox webdevops/sphinx webdevops/liquibase

test:
cd "test/" && make all
Expand Down Expand Up @@ -168,3 +168,6 @@ webdevops/varnish:

webdevops/certbot:
bash bin/build.sh certbot "${DOCKER_REPOSITORY}/certbot" "${DOCKER_TAG_LATEST}"

webdevops/liquibase:
bash bin/build.sh liquibase "${DOCKER_REPOSITORY}/liquibase" "${DOCKER_TAG_LATEST}"
39 changes: 39 additions & 0 deletions docker/liquibase/latest/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#+++++++++++++++++++++++++++++++++++++++
# Dockerfile for webdevops/liquibase:latest
# -- automatically generated --
#+++++++++++++++++++++++++++++++++++++++

FROM java:latest

MAINTAINER [email protected]
LABEL vendor=WebDevOps.io
LABEL io.webdevops.layout=8
LABEL io.webdevops.version=0.56.1

ENV LIQUIBASE_VERSION "3.5.1"
ENV LIQUIBASE_DRIVER "com.mysql.jdbc.Driver"
ENV LIQUIBASE_CLASSPATH "/usr/share/java/mysql.jar"
ENV LIQUIBASE_URL ""
ENV LIQUIBASE_USERNAME ""
ENV LIQUIBASE_PASSWORD ""
ENV LIQUIBASE_CHANGELOG "/liquibase/changelog.xml"
ENV LIQUIBASE_CONTEXTS ""
ENV LIQUIBASE_OPTS ""

COPY conf/ /opt/docker/

RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
libmysql-java \
&& wget -q -O/tmp/liquibase.tar.gz "https://github.com/liquibase/liquibase/releases/download/liquibase-parent-${LIQUIBASE_VERSION}/liquibase-${LIQUIBASE_VERSION}-bin.tar.gz" \
&& mkdir -p /opt/liquibase \
&& tar -xzf /tmp/liquibase.tar.gz -C /opt/liquibase \
&& rm -f /tmp/liquibase.tar.gz \
&& chmod +x /opt/liquibase/liquibase \
&& ln -s /opt/liquibase/liquibase /usr/local/bin/ \
&& chmod +x /opt/docker/bin/entrypoint.sh \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/*

ENTRYPOINT ["/opt/docker/bin/entrypoint.sh"]

12 changes: 12 additions & 0 deletions docker/liquibase/latest/Dockerfile.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{ docker.fromOfficial("java") }}

{{ docker.version() }}

{{ environment.liquibase('3.5.1') }}

{{ docker.copy('conf/', '/opt/docker/') }}

{{ liquibase.default() }}

{{ docker.entrypoint("/opt/docker/bin/entrypoint.sh") }}

167 changes: 167 additions & 0 deletions docker/liquibase/latest/conf/bin/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
#!/bin/bash

set -o pipefail
set -o errtrace
set -o nounset
set -o errexit

LIQUIBASE_OPTS="$LIQUIBASE_OPTS --defaultsFile=/liquibase.properties"

echo -n > /liquibase.properties

## Database driver
if [[ -n "$LIQUIBASE_DRIVER" ]]; then
echo "driver: ${LIQUIBASE_DRIVER}" >> /liquibase.properties
fi

## Classpath
if [[ -n "$LIQUIBASE_CLASSPATH" ]]; then
echo "classpath: ${LIQUIBASE_CLASSPATH}" >> /liquibase.properties
fi

## Database url
if [[ -n "$LIQUIBASE_URL" ]]; then
echo "url: ${LIQUIBASE_URL}" >> /liquibase.properties
fi

## Database username
if [[ -n "$LIQUIBASE_USERNAME" ]]; then
echo "username: ${LIQUIBASE_USERNAME}" >> /liquibase.properties
fi

## Database password
if [[ -n "$LIQUIBASE_PASSWORD" ]]; then
echo "password: ${LIQUIBASE_PASSWORD}" >> /liquibase.properties
fi

## Database contexts
if [[ -n "$LIQUIBASE_CONTEXTS" ]]; then
echo "contexts: ${LIQUIBASE_CONTEXTS}" >> /liquibase.properties
fi

## Database changelog file
if [[ -n "$LIQUIBASE_CHANGELOG" ]]; then
echo "changeLogFile: ${LIQUIBASE_CHANGELOG}" >> /liquibase.properties
fi

function executeLiquibase() {
exec /opt/liquibase/liquibase $LIQUIBASE_OPTS "$@"
}


if [[ "$#" -ge 1 ]]; then
TASK="$1"
shift

case "$TASK" in
## Custom liquibase command
liquibase)
executeLiquibase "$@"
;;

## Database Update Commands
update|updateCount|updateSQL|updateCountSQL) ;&
## Database Rollback Commands
rollback|rollbackToDate|rollbackCount|rollbackSQL|rollbackToDateSQL|rollbackCountSQL|updateTestingRollback) ;&
## Diff Commands
diff|diffChangeLog) ;&
## Documentation Commands
dbDoc) ;&
## Maintenance Commands
status|validate|changelogSync|changelogSyncSQL|markNextChangeSetRan|listLocks|releaseLocks|dropAll|clearCheckSums)
if [[ "$#" -eq 0 ]]; then
executeLiquibase "$TASK"
else
executeLiquibase "$TASK" "$@"
fi
;;

## show configuration
showConf)
cat /liquibase.properties
;;

## Help
help)
cat <<EOF
Database Update Commands
-------------------------------------------------------------------------------
update Updates database to current version.
updateCount <value> Applies the next <value> change sets.
updateSQL Writes SQL to update database to current
version to STDOUT.
updateCountSQL <value> Writes SQL to apply the next <value>
change sets to STDOUT.
Database Rollback Commands
-------------------------------------------------------------------------------
rollback <tag> Rolls back the database to the state it
was in when the tag was applied.
rollbackToDate <date/time> Rolls back the database to the state it
was in at the given date/time.
rollbackCount <value> Rolls back the last <value> change sets.
rollbackSQL <tag> Writes SQL to roll back the database to
the state it was in when the tag was
applied to STDOUT.
rollbackToDateSQL <date/time> Writes SQL to roll back the database to
the state it was in at the given date/time
version to STDOUT.
rollbackCountSQL <value> Writes SQL to roll back the last <value>
change sets to STDOUT.
futureRollbackSQL Writes SQL to roll back the database to
the current state after the changes in
the changeslog have been applied.
updateTestingRollback Updates the database, then rolls back
changes before updating again.
generateChangeLog generateChangeLog of the database to
standard out. v1.8 requires the dataDir
parameter currently.
Diff Commands
-------------------------------------------------------------------------------
diff [diff parameters] Writes description of differences to
standard out.
diffChangeLog [diff parameters] Writes Change Log XML to update the base
database to the target database to
standard out.
Documentation Commands
-------------------------------------------------------------------------------
dbDoc <outputDirectory> Generates Javadoc-like documentation based
on current database and change log.
Maintenance Commands
-------------------------------------------------------------------------------
tag <tag> "Tags" the current database state for
future rollback.
tagExists <tag> Checks whether the given tag is already
existing.
status Outputs count (list if --verbose) of unrun
change sets.
validate Checks the changelog for errors.
changelogSync Mark all changes as executed in the
database.
changelogSyncSQL Writes SQL to mark all changes as executed
in the database to STDOUT.
markNextChangeSetRan Mark the next change set as executed in
the database.
listLocks Lists who currently has locks on the
database changelog.
releaseLocks Releases all locks on the database
changelog.
dropAll Drops all database objects owned by the
user. Note that functions, procedures
and packages are not dropped
(limitation in 1.8.1).
clearCheckSums Removes current checksums from database.
On next run checksums will be recomputed.
EOF
exit 1
;;

## Default task (eg. sh, bash)
*)
exec "$TASK" "$@"
;;
esac
fi
32 changes: 32 additions & 0 deletions documentation/docs/content/DockerImages/dockerfiles/liquibase.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
===================
webdevops/liquibase
===================

The certbot images are based on ``java`` with liquibase and mysql driver

Docker image tags
-----------------

====================== ==========================
Tag Distribution name
====================== ==========================
``latest`` Based on official java
====================== ==========================

Environment variables
---------------------

========================== ============================ ==============================================
Environment variable Description Default
========================== ============================ ==============================================
``LIQUIBASE_VERSION`` Installed Liquibase version *not changeable*
``LIQUIBASE_DRIVER`` Database driver ``com.mysql.jdbc.Driver``
``LIQUIBASE_CLASSPATH`` Java class path ``/usr/share/java/mysql.jar``
``LIQUIBASE_URL`` DB url *empty* (eg. ``jdbc:mysql://host/app``)
``LIQUIBASE_USERNAME`` DB username *empty*
``LIQUIBASE_PASSWORD`` DB password *empty*
``LIQUIBASE_CHANGELOG`` Changelog file ``/liquibase/changelog.xml``
``LIQUIBASE_CONTEXTS`` Server contexts *empty*
``LIQUIBASE_OPTS`` Additional options *empty*
========================== ============================ ==============================================

1 change: 1 addition & 0 deletions documentation/docs/content/DockerImages/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Docker images
dockerfiles/hhvm
dockerfiles/hhvm-apache
dockerfiles/hhvm-nginx
dockerfiles/liquibase
dockerfiles/mail-sandbox
dockerfiles/nginx
dockerfiles/nginx-dev
Expand Down
12 changes: 12 additions & 0 deletions template/Dockerfile/environment.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ ENV APPLICATION_PATH /app
ENV APPLICATION_UID 1000
ENV APPLICATION_GID 1000
{%- endmacro %}

{% macro liquibase(version) -%}
ENV LIQUIBASE_VERSION "{{ version }}"
ENV LIQUIBASE_DRIVER "com.mysql.jdbc.Driver"
ENV LIQUIBASE_CLASSPATH "/usr/share/java/mysql.jar"
ENV LIQUIBASE_URL ""
ENV LIQUIBASE_USERNAME ""
ENV LIQUIBASE_PASSWORD ""
ENV LIQUIBASE_CHANGELOG "/liquibase/changelog.xml"
ENV LIQUIBASE_CONTEXTS ""
ENV LIQUIBASE_OPTS ""
{%- endmacro %}
16 changes: 16 additions & 0 deletions template/Dockerfile/images/liquibase.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% import 'Dockerfile/provision.jinja2' as provision %}

{% macro default(role='') -%}
RUN apt-get update \
&& apt-get install -yq --no-install-recommends \
libmysql-java \
&& wget -q -O/tmp/liquibase.tar.gz "https://github.com/liquibase/liquibase/releases/download/liquibase-parent-${LIQUIBASE_VERSION}/liquibase-${LIQUIBASE_VERSION}-bin.tar.gz" \
&& mkdir -p /opt/liquibase \
&& tar -xzf /tmp/liquibase.tar.gz -C /opt/liquibase \
&& rm -f /tmp/liquibase.tar.gz \
&& chmod +x /opt/liquibase/liquibase \
&& ln -s /opt/liquibase/liquibase /usr/local/bin/ \
&& chmod +x /opt/docker/bin/entrypoint.sh \
&& apt-get clean \
&& rm -r /var/lib/apt/lists/*
{%- endmacro %}
1 change: 1 addition & 0 deletions template/Dockerfile/layout.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
{% import 'Dockerfile/images/samson-deployment.jinja2' as samsonDeployment %}
{% import 'Dockerfile/images/varnish.jinja2' as varnish %}
{% import 'Dockerfile/images/certbot.jinja2' as certbot %}
{% import 'Dockerfile/images/liquibase.jinja2' as liquibase %}
#+++++++++++++++++++++++++++++++++++++++
# Dockerfile for webdevops/{{ Dockerfile.image }}:{{ Dockerfile.tag }}
# -- automatically generated --
Expand Down
3 changes: 3 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ sphinx:

certbot:
bash ./run.sh certbot

liquibase:
bash ./run.sh liquibase
15 changes: 15 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,21 @@ ENV VARNISH_BACKEND_HOST \"google.com\"
waitForTestRun
}

#######################################
# webdevops/liquibase
#######################################

#[[ $(checkTestTarget liquibase) ]] && {
# setupTestEnvironment "liquibase"
#
# # setSpecTest "base"
# setEnvironmentOsFamily "debian"
#
# OS_VERSION="3" runTestForTag "latest"
#
# waitForTestRun
#}

echo ""
echo " >>> finished, all tests PASSED <<<"
echo ""
4 changes: 4 additions & 0 deletions test/spec/collection/liquibase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
shared_examples 'collection::liquibase' do
include_examples 'liquibase::liquibase'
end

13 changes: 13 additions & 0 deletions test/spec/docker/liquibase_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'serverspec'
require 'docker'
require 'spec_helper'

describe "Dockerfile" do
before(:all) do
@image = Docker::Image.build_from_dir('.', { 'dockerfile' => ENV['DOCKERFILE'] })
set :docker_image, @image.id
end

include_examples 'collection::liquibase'

end
5 changes: 5 additions & 0 deletions test/spec/shared/liquibase/liquibase.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
shared_examples 'liquibase::liquibase' do
describe command('liquibase --version') do
its(:exit_status) { should eq 0 }
end
end

0 comments on commit 18e06ef

Please sign in to comment.