In previous post, we discussed about the problem of Database deployment and use Liquibase for Database CI/CD purposes. We also discussed the basics of how liquibase works behind the scenes. Now the next step is to install and configure liquibase. The steps here are for Windows OS but Liquibase being a cross-platform tool, the same can be repeated on any major Operating System.
Install Java
Since Liquibase itself is written in Java, we would need to have java installed on the machine where we need to run Liquibase. For this, we can either download Java from package repositories inside various Linux distributions and use package managers like yum/rpm in Red hat based distributions and apt/dpkg in debian based distributions. For Windows OS, we can use chocolatey or direct download it from Oracle and run it.
Note that we only Java Run time environment i.e. JRE and not Java Development Environment (JDK). Howver, if JDK is installed, then it should cover JRE as well. Also, since we are going to use the latest version of liquibase, we need to have Java 1.8 or plus. Once Java is installed, we can check for the proper version installed using java -version
command.
Install Liquibase
For this, we can go to Liquibase site and download the version appropriate for our Operating System. You would see two versions available for download:
Of the above versions, the .zip file is for Windows OS and .tar.gz is for Linux Distributions. Download the file and extract the zip contents to a directory, say C:\Liquibase. Now open environmental variables window and add the path of the extract directory to system variable PATH:
You can also use appropriate commands in PowerShell or bash for same. To verify, it is done properly, open a cmd/terminal window and run:
liquibase --version
You should see an output like below:
Download JDBC Drivers
Liquibase needs database specific JDBC drivers to connect and execute commands on the database in reference. These drivers can be downloaded from Database Vendor site directly. The list of supported databases can be found here.
Download Liquibase using Ansible
We can also setup Liquibase using Ansible. Here’s a quick playbook for setting up liquibase on target group dbservers:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
— # Quick ansible playbook for downloading liquibase | |
– name: download liquibase using ansible | |
hosts: dbservers | |
connection: ssh | |
sudo: yes | |
user: user | |
tasks: | |
– name: Create liquibase directory | |
file: | |
name: /opt/liquibase | |
state: directory | |
mode: 0755 | |
– name: install liquibase | |
unarchive: | |
src: https://github.com/liquibase/liquibase/releases/download/liquibase-parent-{{ liquibase_version }}/liquibase-{{ liquibase_version }}-bin.tar.gz | |
dest: /opt/liquibase | |
copy: no | |
mode: 0755 | |
creates: /opt/liquibase/liquibase | |
– name: add liquibase to PATH | |
raw: PATH=/opt/liquibase:$PATH |
You’ll need to have ansible configured and setup in your environment. We can pass the liquibase_version value at run time using ––extra–vars. Below is one of the sample runs of above playbook:
In the next blog post, we’ll discuss how we can leverage Liquibase for Microsoft SQL server deployments.
[…] previous post, we saw how we can install and configure Liquibase. In this blog post, we’ll see how we can […]
LikeLike
[…] and how it works with demonstration. We have discussed setup and configuration of liquibase in this post. You need to be familiar with the same before moving […]
LikeLike