|
| 1 | +## Docker Environment |
| 2 | + |
| 3 | +If you don't have a build environment setup on your local machine, the project provides a docker container setup for your convenience. As long as Docker is installed, you can use the following commands to run tests: |
| 4 | + |
| 5 | +```sh |
| 6 | +# Build the image: |
| 7 | +docker build -t partman_test_image ./docker |
| 8 | + |
| 9 | +# Start the container. This will initialize and start Postgres, then drop to a shell. |
| 10 | +docker run -it --name partman_test -v "$(pwd):/pg_partman" partman_test_image |
| 11 | +``` |
| 12 | + |
| 13 | +The source code for pg_partman is mounted inside the container rather than included in the build, so any changes can be tested without rebuilding the container. |
| 14 | + |
| 15 | +Example commands to run inside the container: |
| 16 | + |
| 17 | +```sh |
| 18 | +# Convenience script to build and install pg_partman, then create a database named partman_test. |
| 19 | +# This does a fresh build+install each time, and the database is recreated if it already exists. |
| 20 | +docker/build_for_tests.sh |
| 21 | + |
| 22 | +# Run a specific test |
| 23 | +pg_prove -ovf -U postgres -d partman_test test/<test_file_path>.sql |
| 24 | + |
| 25 | +# Build, install, create DB and run all tests |
| 26 | +docker/build_and_test.sh |
| 27 | + |
| 28 | +# The script can run specific tests as well (relative to test/) |
| 29 | +docker/build_and_test.sh <test_file_path>.sql |
| 30 | +``` |
| 31 | + |
| 32 | +You can also start the container and run the tests in one command with: |
| 33 | + |
| 34 | +```sh |
| 35 | +# All tests |
| 36 | +docker run --rm -it -v "$(pwd):/pg_partman" partman_test_image docker/build_and_test.sh |
| 37 | + |
| 38 | +# Specific tests, again relative to test/ |
| 39 | +docker run --rm -it -v "$(pwd):/pg_partman" partman_test_image docker/build_and_test.sh <test_file_path>.sql |
| 40 | +``` |
| 41 | + |
| 42 | +When finished, stop and optionally remove the container. |
| 43 | + |
| 44 | +```sh |
| 45 | +docker stop partman_test |
| 46 | +docker rm partman_test |
| 47 | +``` |
| 48 | + |
| 49 | +### Replicating the CI environment |
| 50 | + |
| 51 | +Both the above image and the GitHub CI pipeline use the [pgxn-tools](https://github.com/pgxn/docker-pgxn-tools) image. The Dockerfile and entrypoint in this folder are meant to ease iterative development, but you can use the standalone entrypoint to run the same steps that CI does. |
| 52 | + |
| 53 | +```sh |
| 54 | +# Install PostgreSQL 17 and run all tests, discarding the container afterwards |
| 55 | +docker run -it --rm -w /pg_partman --volume "$(pwd):/pg_partman" pgxn/pgxn-tools docker/pgxn_standalone_entrypoint.sh 17 |
| 56 | +``` |
0 commit comments