This project provides lightweight bundles of PostgreSQL binaries with reduced size that are intended for testing purposes. It is a supporting project for the primary io.zonky.test:embedded-database-spring-test and io.zonky.test:embedded-postgres projects. However, with a little effort it can be also applicable with com.opentable:otj-pg-embedded and maybe some other projects.
- Lightweight bundles of PostgreSQL binaries with reduced size (~10MB)
- Embedded PostgreSQL 11+ binaries even for Linux platform
- Configurable version of PostgreSQL binaries
Use with embedded-database-spring-test or embedded-postgres project
All necessary dependencies are already included in these projects, so no further action is required. However, you can change the version of the postgres binaries by following the instructions described in Postgres version.
Use with com.opentable:otj-pg-embedded project
First, you have to add any of the available dependencies to your Maven configuration:
<dependency>
<groupId>io.zonky.test.postgres</groupId>
<artifactId>embedded-postgres-binaries-linux-amd64</artifactId>
<version>11.4.0</version>
<scope>test</scope>
</dependency>
Then you need to implement a custom PgBinaryResolver:
public class CustomPostgresBinaryResolver implements PgBinaryResolver {
public InputStream getPgBinary(String system, String architecture) throws IOException {
ClassPathResource resource = new ClassPathResource(format("postgres-%s-%s.txz", system, architecture));
return resource.getInputStream();
}
}
Alpine variant
public class CustomPostgresBinaryResolver implements PgBinaryResolver {
public InputStream getPgBinary(String system, String architecture) throws IOException {
ClassPathResource resource = new ClassPathResource(format("postgres-%s-%s-alpine_linux.txz", system, architecture));
return resource.getInputStream();
}
}
And finally register it to the junit rule.
@Rule
public SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance()
.customize(builder -> builder.setPgBinaryResolver(new CustomPostgresBinaryResolver()));
The version of the postgres binaries can be managed by importing embedded-postgres-binaries-bom
in a required version into your dependency management section.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.zonky.test.postgres</groupId>
<artifactId>embedded-postgres-binaries-bom</artifactId>
<version>11.1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
A list of all available versions of postgres binaries is here: https://mvnrepository.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom
By default, only dependencies for amd64
architecture, in the io.zonky.test:embedded-database-spring-test and io.zonky.test:embedded-postgres projects, are included.
Support for other architectures can be enabled by adding the corresponding Maven dependencies as shown in the example below.
<dependency>
<groupId>io.zonky.test.postgres</groupId>
<artifactId>embedded-postgres-binaries-linux-i386</artifactId>
<scope>test</scope>
</dependency>
Supported platforms: Darwin
, Windows
, Linux
, Alpine Linux
Supported architectures: amd64
, i386
, arm32v6
, arm32v7
, arm64v8
, ppc64le
Note that not all architectures are supported by all platforms, look here for an exhaustive list of all available artifacts: https://mvnrepository.com/artifact/io.zonky.test.postgres
Since PostgreSQL 10.0
, there are additional artifacts with alpine-lite
suffix. These artifacts contain postgres binaries for Alpine Linux with disabled ICU support for further size reduction.
The project uses a Gradle-based build system. In the instructions
below, ./gradlew
is invoked from the root of the source tree and serves as
a cross-platform, self-contained bootstrap mechanism for the build.
Git, JDK 6 or later and Docker
Be sure that your JAVA_HOME
environment variable points to the jdk1.6.0
folder
extracted from the JDK download.
Compiling non-native architectures rely on emulation, so it is necessary to register qemu-*-static
executables:
docker run --rm --privileged multiarch/qemu-user-static:register --reset
Note that the complete build of all supported architectures is now supported only on Linux platform.
git clone git@github.com:zonkyio/embedded-postgres-binaries.git
Builds all supported artifacts for all supported platforms and architectures, and also builds a BOM to control the versions of postgres binaries.
./gradlew clean install --parallel -Pversion=10.6.0 -PpgVersion=10.6
Note that the complete build can take a very long time, even a few hours, depending on the performance of the machine on which the build is running.
Builds only binaries for a specified platform/submodule.
./gradlew clean :repacked-platforms:install -Pversion=10.6.0 -PpgVersion=10.6
Builds only a single binary for a specified platform and architecture.
./gradlew clean install -Pversion=10.6.0 -PpgVersion=10.6 -ParchName=arm64v8 -PdistName=alpine
It is also possible to include the PostGIS extension by passing the postgisVersion
parameter, e.g. -PpostgisVersion=2.5.2
. Note that this option is not (yet) available for Windows and Mac OS platforms.
Optional parameters:
- postgisVersion
- default value: unset
- supported values: a postgis version number (only 2.5.2+, 2.4.7+, 2.3.9+ versions are supported)
- archName
- default value:
amd64
- supported values:
amd64
,i386
,arm32v6
,arm32v7
,arm64v8
,ppc64le
- default value:
- distName
- default value: debian-like distribution
- supported values: the default value or
alpine
- dockerImage
- default value: resolved based on the platform
- supported values: any supported docker image
- qemuPath
- default value: executables are resolved from
/usr/bin
directory or downloaded from https://github.com/multiarch/qemu-user-static/releases/download/v2.12.0 - supported values: a path to a directory containing qemu executables
- default value: executables are resolved from
The project is released under version 2.0 of the Apache License.