Docker Compose for Perl DBD::Pg (PostgreSQL)


These files were used to set up a local development environment for the Perl module DBD::Pg


git clone https://github.com/bucardo/dbdpg.git
cd dbdpg

Put the two files in that folder:


examples/compose-for-dbd-pg/Dockerfile
FROM perl:5.36
RUN apt-get update && \
    apt-get install -y libaspell-dev
RUN cpanm --notest DBI Perl::Critic Text::SpellChecker Devel::Cover


# docker build -t dbdpg .
# docker run -it --workdir /opt -v$(pwd):/opt --name dbdpg dbdpg bash
# docker container start -i dbdpg

examples/compose-for-dbd-pg/docker-compose.yaml
version: '3.8'
services:
  client:
    build: .
    volumes:
    - .:/opt
    links:
    - mypostgres
    command: tail -f /dev/null
    working_dir: /opt
    environment:
      AUTHOR_TESTING: 1
      RELEASE_TESTING: 1
      DBI_DSN: "dbi:Pg:dbname=test_db;host=mypostgres"
      DBI_PASS: secret
      DBI_USER: test_user
  mypostgres:
    image: postgres:15.2
    environment:
      POSTGRES_USER: test_user
      POSTGRES_PASSWORD: secret
      POSTGRES_DB: test_db
    volumes:
      - database-data:/var/lib/postgresql/data/

volumes:
  database-data:

In one terminal start Docker compose:


docker-compose up

In another terminal connect to the client container


docker exec -it dbdpg_client_1 bash

Now you can run the tests:


perl Makefile.PL
make
AUTHOR_TESTING=1
RELEASE_TESTING=1
make test

And you can also generate test coverage report:


cover -test