Liquibase Kubernetes cannot execute changelog without rebuild docker image

Hello there! (General Kenobi)

First of all I just want to thank the opportunity of having this forum and I apologize if I’m using this in any wrong way

I’m trying to use Liquibase tool with Kubernetes and the problem I’m facing is that I cannot execute liquibase update with the last version of my changelog file.

Dockerfile ready for question .

With this solution, everytime I want to update my changelog file I need to rebuild my liquibase image . I was wondering if there is any better aproach

I was following this tutorial on continuous database integration


and making the necessaries changes so it could work with liquibase instead of flyway
but even with my changesets on configmap the database is not updated

I will present you now my Job and then my Configmap

JOB:

kind: Job
metadata:
name: migration-job
namespace: default
spec:
template:
 spec:
   containers:
     - name: liquibase
       image: 74745757/liquibase4:latest
       args: ["update"]
       env:
         - name: LIQUIBASE_URL
           value: "jdbc:sqlserver://meudbserver.database.windows.net;databaseName=DBTest1"
         - name: LIQUIBASE_CHANGELOG
           value: samplechangelog.sql
         - name: LIQUIBASE_USERNAME
           value: goncalo1
         - name: LIQUIBASE_PASSWORD
           valueFrom:
             secretKeyRef:
               name: goncalo1
               key: password
       volumeMounts:
         - mountPath: "liquibase/changelog"
           name: changelog
   volumes:
     - name: changelog
       configMap:
         name: samplechangelog.sql
   restartPolicy: Never

Configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: samplechangelog.sql
  namespace: default
data:
  liquibaseProperties: |
    --liquibase formatted sql
    --changeset goncalo1:7
    ALTER TABLE carros ADD numero_cavalos integer; 
    --changeset goncalo1:8
    ALTER TABLE carros ADD numero_portas integer; 

If you noticed that the directory where I mount my volume is different from the one specified in the dockerfile, it’s because when update job and change the mountPath directory from “liquibase/changelog” to “liquibase” I get this error

“Error: failed to start container “liquibase”: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused “exec: “/liquibase/liquibase”: stat /liquibase/liquibase: no such file or directory”: unknown”

I also tried to change my dockerfile so the last line could match the directory where I tried to mount my config map
ENV LIQUIBASE_CHANGELOG=/liquibase/changelog/samplechangelog.sql

and after a new image release I start getting this error
“Error: failed to start container “liquibase”: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused “exec: “update”: executable file not found in $PATH”: unknown”

I’m sorry if the thread is getting a little confusing , if you could by any mean help me find a way to get the changelog executed without the need to rebuild my docker image it would be kindly appreciated!

Thank you very much,
Gonçalo

Hi Gonçalo,

It is always a good practice to build a new docker image for your changeset to be released with the one application. Also can you confirm after going into the docker image is your configmap actually gets mounted?

2 Likes

Hi @Goncalo57,
i don’t see the CMD (https://docs.docker.com/engine/reference/builder/#cmd) or ENTRYPOINT (https://docs.docker.com/engine/reference/builder/#entrypoint) at the end of your configuration. First of all i suggest you to take a look at how docker work. (https://docs.docker.com/get-started/).

That container use ```
–rm Automatically remove the container when it exits
and to rebuild and restart the container. If you want i can provide you a docker image that execute the update at start or exposing an api. Let me know.

1 Like