1

using ballerina v.1.0.1. on Mac. On host I put MySQL driver to /Library/Ballerina/ballerina-1.0.1/distributions/jballerina-1.0.1/bre/lib , run ballerine code and I was eble to connecto to DB.

When I created docker image with build command and spin a docker in compose env it failed with

ApplicationError message=error in sql connector configuration: Failed to get driver instance for jdbcUrl=jdbc:mysql://mysql:3306/api_svc?serverTimezone=UTC:No suitable driver at ballerinax.java_jdbc:createClient(jdbc_client.bal:87) ballerinax.java_jdbc.Client:__init(client_endpoint.bal:27)

Question: How can I mount properly MySQL driver in docker image? I cannot find any reference in the documentation.

Thanks,

lpastor
  • 169
  • 10
  • Are you using @docker annotation to create the Dockerfile or you have your own Dockerfile ? – hYk Oct 06 '19 at 09:42

2 Answers2

3

Another option is to package the MySQL driver jar with the executable jar file of your Ballerina program. This way, you don't need to copy files to the docker container, because ballerina build command produces a self-contained executable jar with all the dependencies.

In order to do this, you need to create a Ballerina project and a module. This guide contains more information on Ballerina projects.

Then, copy and paste the following section to the Ballerina.toml in your project directory.

[platform]
target = "java8"

    [[platform.libraries]]
    path = "<path-to-the-mysql-driver-jar-file>"
    modules = ["<name-of-the-ballerina-module>"]

Sameera Jayasoma
  • 1,545
  • 8
  • 12
  • yes, this worked like a charm ... One question: is path need to be absolute or can be relative from .toml level? I put my driver on same level and it worked. – lpastor Oct 06 '19 at 01:35
  • Path can be relative. Example: https://github.com/ballerina-platform/ballerina-lang/blob/master/tests/jballerina-integration-test/src/test/resources/packaging/balopath/case3/TestProject1/Ballerina.toml#L11 – hYk Oct 06 '19 at 09:39
0

You can copy files in to your docker images using the @docker:CopyFiles annotation. Example:

@docker:Config {}
@docker:CopyFiles {
    files: [
        { sourceFile: "./conf/data.txt", target: "/home/ballerina/data/data.txt" }
    ]
}

@docker:Expose {}
listener http:Listener helloWorldEP = new(9090);

Check this sample: https://github.com/ballerinax/docker/tree/master/samples/sample5

To add it to the ballerina distribution in the docker image you can copy to this target:

@docker:CopyFiles {
    files: [
        { sourceFile: "./libs/mysql-driver.jar", target: "/ballerina/runtime/bre/lib/" }
    ]
}
hYk
  • 764
  • 1
  • 8
  • 21
  • hmm. problem is when I attach to running ballerina container in /home there is only ballerina folder in with my module .jar. Im not coftable just blindly put diver in folder that not exist... I need to try and let you know – lpastor Oct 06 '19 at 01:33