GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — wiki update: testcontainers magic · Issue #465 · tada/pljava

wiki update: testcontainers magic #465

New issue
Copy link
New issue
Copy link
Open
Open
wiki update: testcontainers magic#465
Copy link

Description

@beargiles
beargiles
opened on Sep 8, 2023
Issue body actions

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.

Reacted by Adrian A.

Activity

  1. jcflack commented on Sep 19, 2023

    @jcflack
    jcflack
    on Sep 19, 2023
    Contributor
    More actions

    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?

  2. jcflack commented on Apr 5, 2024

    @jcflack
    jcflack
    on Apr 5, 2024
    Contributor
    More actions

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.