Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wiki update: testcontainers magic #465

Open
beargiles opened this issue Sep 8, 2023 · 2 comments
Open

wiki update: testcontainers magic #465

beargiles opened this issue Sep 8, 2023 · 2 comments

Comments

@beargiles
Copy link

Someone asked how to use this extension with testcontainers a while back and I had a very long-winded answer (but with sample code!)... then realized I was an idiot and there's a much easier answer that can be added to the wiki.

Using a pre-configured Docker image

When I'm using my custom docker images I use

   PostgreSQLContainer getContainer() {
        DockerImageName imageName = DockerImageName.parse("beargiles/postgres-pljava:15.4").asCompatibleSubstituteFor("postgres");
        PostgreSQLContainer db = new PostgreSQLContainer(ImageName);
        // db.withInitScript("/path/to/initScript");
        db.withImagePullPolicy((s) -> false);
        return db;
    }

The key is the asCompatibleSubstituteFor() call.

The initialization script can load the jars you require, perform any required SQL calls, etc.

Note: I strongly recommend that any initialization scripts be limited to preparing the test data. Any custom
extensions (UDF, UDT, etc.) should be set up using a SQL Deployment Descriptor bundled in your jar(s). This ensures the SQL extensions and your java implementation remain in sync.

You may not need the withImagePullPolicy() call - I might only need it since I'm developing the docker images locally.

Using an official PostgreSQL image

The short answer is that you can't. The initialization scripts can't install system packages.

The long answer is that you could - but it would be difficult. You would need to install pl/java using the Container#withCommand(String) command once the database container is running. That's a multistep process
even if you're taking advantage of the existing Debian packages available on the official PostgreSQL image.

If you're feeling bold look at the first two targets in this Dockerfile.

@jcflack
Copy link
Contributor

jcflack commented Sep 19, 2023

Hi,

Where were you thinking this would go in the wiki? A new "Using a pre-configured Docker image" page? Or were you thinking it would belong on some existing page?

@jcflack
Copy link
Contributor

jcflack commented Apr 5, 2024

Or would you like to host these instructions somewhere on a site or blog you control, and have me add a link on the "Prebuilt packages" wiki page where your Docker images are linked already?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants