I am trying to run a custom task by implementing customChange.
Here are my files:
Dockerfile
FROM liquibase:4.29
WORKDIR /node-app
USER root
COPY . .
RUN apt update -y
RUN apt install default-jdk -y
RUN javac -cp /liquibase/internal/lib/liquibase-core.jar RunCustomCommand.java
RUN jar cf run-custom-command.jar RunCustomCommand.class
CMD [ "sh" ]
RunCustomCommand.java
package com.example;
import liquibase.change.custom.CustomTaskChange;
import liquibase.database.Database;
import liquibase.exception.CustomChangeException;
import liquibase.exception.SetupException;
import liquibase.exception.ValidationErrors;
import liquibase.resource.ResourceAccessor;
public class RunCustomCommand implements CustomTaskChange {
private ResourceAccessor resourceAccessor;
@Override
public void execute(Database database) throws CustomChangeException {
System.out.printf("Hello %s!", "World");
}
@Override
public String getConfirmationMessage() {
return "Custom task executed successfully.";
}
@Override
public void setUp() throws SetupException {
// Any setup logic here
}
@Override
public void setFileOpener(ResourceAccessor resourceAccessor) {
this.resourceAccessor = resourceAccessor;
}
@Override
public ValidationErrors validate(Database database) {
return new ValidationErrors();
}
}
changelog.xml
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">
<changeSet id="21" author="nvoxland">
<customChange class="com.example.RunCustomCommand">
</customChange>
</changeSet>
</databaseChangeLog>
docker-compose.yml
version: "3.1"
services:
lobo-liquibase:
container_name: test-liquibase
build:
context: ./
dockerfile: Dockerfile
command: update --classpath=/node-app/run-custom-command.jar --changelog-file=changelog.xml --username=postgres --password=postgres --url=jdbc:postgresql://db:5432/postgres
networks:
- test-liqui
networks:
test-liqui:
However, I always get this error
test-liquibase | ERROR: Exception Details
test-liquibase | ERROR: Exception Primary Class: ClassNotFoundException
test-liquibase | ERROR: Exception Primary Reason: com.example.RunCustomCommand
test-liquibase | ERROR: Exception Primary Source: PostgreSQL 11.22
test-liquibase |
test-liquibase | Unexpected error running Liquibase: com.example.RunCustomCommand
I have been stuck with this for a week now, is there anything wrong with my setup?