0

I'm working on converting my project's use of Flyway from a gradle task using the Flyway plugin to a gradle task using docker-compose. Currently we have a seperate Ignite compose file that starts the Ignite database, and we are using this task to run the Flyway migrations. I think I've run into an issue where Flyway refuses to recognize the ignite-core file I've copied into the docker container, and I'm at an impasse about how to proceed. I'm still pretty new to Docker and Flyway, so any help would be appreciated!

I am receiving a "org.flyway.core.api.FLywayException: Unable to instantiate JDBC driver: /flyway/drivers/ignite-core-2.9.1.jar", which seems to boil down to a ClassNotFoundException for that file. However, just before the error occurs Flyway claims it is adding /flyway/drivers/ignite-core-2.9.1.core to the classpath.

Flyway Claiming it Added ignite-core to the Classpath

From my understanding, if it is truly finding this file and adding it to the class path my JDBC driver should work. Ignite documentation says "To start using the driver, just add "the file" to your application's classpath."

Things I've tried:

  • Manually specifying the driver using -driver in the docker-compose command for flyway (That's what depicted here).
  • Manually specifying the classpath using the -CP option in the docker-compose command.
  • Using a slightly updated ignite version: ignite-core-2.11.1.jar
  • updating the URL to use localhost instead of 127.0.0.1, as well tried the docker container's name
  • Adding the core file to the /flyway/jars/ directory.
  • Updating permissions of the core file to 777

Some debugging I've done:

  • Having the Dockerfile list out all files in that directory. Confirmed the core file is there.
  • Confirmed both ignite-core-2.9.1 and ignite-core-2.11.1 have the JDBC thin client.

Here's the gradle commands:

task migrateIgnite(type:Exec){
   group = 'Database'
   description = 'Migrate Ignite'
   environment "IGNITE_CONFIG_HOST_PATH", "${project.buildDir}/docker/config/ignite"
   environment "IGNITE_TCP_DISCOVERY_ADDRESS", getIgniteDiscoveryAddrresses()
   environment "DB_URL", "jdbc:ignite:thin//127.0.0.1:10800..10809/"
   environment "DB_USER", "USER"
   environment "DB_PASSWORD", "PASSWORD"
   executable = 'docker-compose'
   workingDir = "$projectDir/build/docker"
   args = ['-f', "$projectDir/build/docker/docker-compose-flyway.yml", 'run', 'dbname']
}

task buildDBMigrations(type: Exec) {
   group = 'Database'
   description = 'Compile database files via Flyway.'
   environment "DB_URL", "jdbc:ignite:thin//127.0.0.1:10800..10809/"
   environment "DB_USER", "USER"
   environment "DB_PASSWORD", "PASSWORD"

   // Build the flyway migrations
   executable = 'docker-compose'
   workingDir = "$projectDir/build/docker"
   args = ['-f', "$projectDir/build/docker/docker-compose-flyway.yml", 'build', 'dbname']
}

The Docker Compose File: (foo-bared a bit at request of management)

Version: '3.4'
services:
  dbname:
    image: the-ignite-image
    command: -X -user=${DB_USER} -password=${DB_PASSWORD} -url=${DB_URL} -driver=/flyway/drivers/ignite-core-2.9.1.jar migrate
    build:
      context: ~/database/flywaydb
      dockerfile: ~/database/flywaydb/Dockerfile
      args:
        docker_repo: ${DOCKER_REPO}
        db_type: ignite
    environment:
      FLYWAY_LOCATIONS: filesystem:/software/migrations/dbname/
      CONFIG_URI: /opt/ignite/apache-ignite/config/ignite-config.xml
      IGNITE_TCP_DISCOVERY_ADDRESSES: ${ACME_IGNITE_TCP_DISCOVERY_ADDRESSES:-127.0.0.1}
      JVM_OPTS: -Djava.net.preferIPv4Stack=true
    volumes:
      - ${IGNITE_CONFIG_HOST_PATH}:/opt/ignite/apache-ignite/config
    hostname: the-ignite-image
    container_name: the-ignite-image
networks:
  project_network:
    external: true
  default:
    external:
      name: project_network
               

The Dockerfile (slimmed down a bit for readability)

ARG docker_repo
FROM ${docker_repo}/flyway:6.4.2

ENV FLYWAYDB_HOME "/flyway"

ARG db_type

WORKDIR /software

USER root

# Grab the Ignite JDBC CLient
ADD --chown=flyway:flyway ignite-dependencies/ /flyway/drivers/
RUN ls /flyway/drivers/

#Conf files
ADD --chown=flyway:flyway conf/ /software/conf

#Common-DB Files
ADD --chown=flyway:flyway common-migrations/dbname /software/migrations/dbname

# Database specific files
ADD --chown=flyway:flyway ${db_type}-migrations/dbname /software/migrations/dbname

#Scripts
ADD --chown=flyway:flyway populateDatabase.sh /software/

USER flyway

The Core file starts its life in ignite-dependencies/ before being copied into /flyway/drivers/ in when I build. I run the build command followed by the migrate command.

Anyone have any insight as to why Flyway can't find the core file?

1 Answers1

0

Did you try with latest version of flyway image? Probably this guidance can help you https://github.com/flyway/flyway-docker. I just tested it locally with ignite 2.12.0 and latest flyway images. Driver mounted to /flyway/drivers is ignite-core-2.12.0.jar.

$ docker run -d -p 10800:10800 apacheignite/ignite:2.12.0
9d763d4119ea15c809b399494e5c54c1fd678803d6c88a5108b3f37613c306f8
$ docker run --rm -v /mnt/c/flyway/drivers:/flyway/drivers -v /mnt/c/flyway/sql:/flyway/sql flyway/flyway -url=jdbc:ignite:thin://host.docker.internal:10800 migrate
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.ignite.internal.util.GridUnsafe$2 (file:/flyway/drivers/ignite-core-2.12.0.jar) to field java.nio.Buffer.address
WARNING: Please consider reporting this to the maintainers of org.apache.ignite.internal.util.GridUnsafe$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Flyway is up to date
Flyway Community Edition 8.5.2 by Redgate
See what's new here: https://flywaydb.org/documentation/learnmore/releaseNotes#8.5.2

Database: jdbc:ignite:thin://host.docker.internal:10800/PUBLIC (Apache Ignite 2.12)
WARNING: Support for Apache Ignite is provided only on a community-led basis, and is not formally supported by Redgate
Successfully validated 1 migration (execution time 00:00.029s)
Creating Schema History table "PUBLIC"."flyway_schema_history" ...
Current version of schema "PUBLIC": << Empty Schema >>
Migrating schema "PUBLIC" to version "1 - Initial" [non-transactional]
Successfully applied 1 migration to schema "PUBLIC", now at version v1 (execution time 00:00.253s)
$ ll /mnt/c/flyway/drivers
total 13808
drwxrwxrwx 1 user user     4096 Mar 11 16:29 ./
drwxrwxrwx 1 user user     4096 Mar 11 15:47 ../
-rwxrwxrwx 1 user user 14135398 Jan 10 11:05 ignite-core-2.12.0.jar*
$ ll /mnt/c/flyway/sql
total 0
drwxrwxrwx 1 user user 4096 Mar 11 15:47 ./
drwxrwxrwx 1 user user 4096 Mar 11 15:47 ../
-rwxrwxrwx 1 user user  164 Mar 11 16:19 V1__Initial.sql*
$ cat /mnt/c/flyway/sql/V1__Initial.sql
CREATE TABLE Person (
  id int PRIMARY KEY,
  city_id int,
  name varchar,
  age int,
  company varchar
) WITH "atomicity=transactional,cachegroup=somegroup";