Skip to content

Commit 190d84e

Browse files
committed
update readme
1 parent 18d6111 commit 190d84e

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

README.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
## Introduction
2+
3+
This project provides lightweight bundles of PostgreSQL binaries with reduced size that are intended for testing purposes.
4+
It is a supporting project for the primary [io.zonky.test:embedded-database-spring-test](https://github.com/zonkyio/embedded-database-spring-test) and [io.zonky.test:embedded-postgres](https://github.com/zonkyio/embedded-postgres) projects.
5+
But with a little help it can be also applicable with [com.opentable:otj-pg-embedded](https://github.com/opentable/otj-pg-embedded) and maybe some other projects.
6+
7+
## Use with [embedded-database-spring-test](https://github.com/zonkyio/embedded-database-spring-test) or [embedded-postgres](https://github.com/zonkyio/embedded-postgres) projects
8+
9+
All necessary dependencies are already included in these projects, so no further action is required.
10+
But you can change the version of the binaries by following the instructions described in [Postgres version](#postgres-version).
11+
12+
## Use with [com.opentable:otj-pg-embedded](https://github.com/opentable/otj-pg-embedded) project
13+
14+
Add some of the [available dependencies](https://mvnrepository.com/artifact/io.zonky.test.postgres) to your Maven configuration:
15+
16+
```xml
17+
<dependency>
18+
<groupId>io.zonky.test.postgres</groupId>
19+
<artifactId>embedded-postgres-binaries-linux-amd64</artifactId>
20+
<version>11.1.0</version>
21+
<scope>test</scope>
22+
</dependency>
23+
```
24+
25+
Further, you need to implement a custom [PgBinaryResolver](https://github.com/opentable/otj-pg-embedded/blob/master/src/main/java/com/opentable/db/postgres/embedded/PgBinaryResolver.java):
26+
```java
27+
public class CustomPostgresBinaryResolver implements PgBinaryResolver {
28+
public InputStream getPgBinary(String system, String architecture) throws IOException {
29+
ClassPathResource resource = new ClassPathResource(format("postgres-%s-%s.txz", system, architecture));
30+
return resource.getInputStream();
31+
}
32+
}
33+
```
34+
35+
<details>
36+
<summary>Alpine variant</summary>
37+
38+
```java
39+
public class CustomPostgresBinaryResolver implements PgBinaryResolver {
40+
public InputStream getPgBinary(String system, String architecture) throws IOException {
41+
ClassPathResource resource = new ClassPathResource(format("postgres-%s-%s-alpine_linux.txz", system, architecture));
42+
return resource.getInputStream();
43+
}
44+
}
45+
```
46+
47+
</details><br/>
48+
49+
And register it:
50+
51+
```java
52+
@Rule
53+
public SingleInstancePostgresRule pg = EmbeddedPostgresRules.singleInstance()
54+
.customize(builder -> builder.setPgBinaryResolver(new CustomPostgresBinaryResolver()));
55+
```
56+
57+
## Postgres version
58+
59+
The version of the binaries can be managed by importing `embedded-postgres-binaries-bom` in a required version into your dependency management section.
60+
61+
```xml
62+
<dependencyManagement>
63+
<dependencies>
64+
<dependency>
65+
<groupId>io.zonky.test.postgres</groupId>
66+
<artifactId>embedded-postgres-binaries-bom</artifactId>
67+
<version>11.1.0</version>
68+
<type>pom</type>
69+
<scope>import</scope>
70+
</dependency>
71+
</dependencies>
72+
</dependencyManagement>
73+
```
74+
75+
A list of all available versions of postgres binaries is here: https://mvnrepository.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom
76+
77+
## Supported architectures
78+
79+
By default, only dependencies for `amd64` architecture, in the [io.zonky.test:embedded-database-spring-test](https://github.com/zonkyio/embedded-database-spring-test) and [io.zonky.test:embedded-postgres](https://github.com/zonkyio/embedded-postgres) projects, are included.
80+
Support for other architectures can be enabled by adding the corresponding Maven dependencies as shown in the example below.
81+
82+
```xml
83+
<dependency>
84+
<groupId>io.zonky.test.postgres</groupId>
85+
<artifactId>embedded-postgres-binaries-linux-i386</artifactId>
86+
<scope>test</scope>
87+
</dependency>
88+
```
89+
90+
**Supported platforms:** `Darwin`, `Windows`, `Linux`, `Alpine Linux`
91+
**Supported architectures:** `amd64`, `i386`, `arm32v6`, `arm32v7`, `arm64v8`, `ppc64le`
92+
93+
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
94+
95+
Since `PostgreSQL 10.0`, there are additional artifacts with `alpine-lite` suffix. These artifacts contain postgres binaries for Alpine Linux with disabled [ICU support](https://blog.2ndquadrant.com/icu-support-postgresql-10/) for further size reduction.
96+
97+
## Building from Source
98+
The project uses a [Gradle](http://gradle.org)-based build system. In the instructions
99+
below, [`./gradlew`](http://vimeo.com/34436402) is invoked from the root of the source tree and serves as
100+
a cross-platform, self-contained bootstrap mechanism for the build.
101+
102+
### Prerequisites
103+
104+
[Git](http://help.github.com/set-up-git-redirect), [JDK 6 or later](http://www.oracle.com/technetwork/java/javase/downloads) and [Docker](https://www.docker.com/get-started)
105+
106+
Be sure that your `JAVA_HOME` environment variable points to the `jdk1.6.0` folder
107+
extracted from the JDK download.
108+
109+
Compiling non-native architectures rely on emulation, so it is necessary to register `qemu-*-static` executables:
110+
111+
`docker run --rm --privileged multiarch/qemu-user-static:register --reset`
112+
113+
**Note that the complete build of all supported architectures is now supported only on Linux platform.**
114+
115+
### Check out sources
116+
`git clone [email protected]:zonkyio/embedded-postgres-binaries.git`
117+
118+
### Make complete build
119+
120+
Builds all supported artifacts for all supported platforms and architectures, and also builds a BOM to control the versions of postgres binaries.
121+
122+
`./gradlew clean install --parallel -Pversion=10.6.0 -PpgVersion=10.6`
123+
124+
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.
125+
126+
### Make partial build
127+
128+
Builds only binaries for a specified platform/submodule.
129+
130+
`./gradlew clean :repacked-platforms:install -Pversion=10.6.0 -PpgVersion=10.6`
131+
132+
### Build only a single binary
133+
134+
Builds only a single binary for a specified platform and architecture.
135+
136+
`./gradlew clean install -Pversion=10.6.0 -PpgVersion=10.6 -ParchName=arm64v8 -PdistName=alpine`
137+
138+
Optional parameters:
139+
- *archName*
140+
- default value: `amd64`
141+
- supported values: `amd64`, `i386`, `arm32v6`, `arm32v7`, `arm64v8`, `ppc64le`
142+
- *distName*
143+
- default value: debian-like distribution
144+
- supported values: the default value or `alpine`
145+
- *dockerImage*
146+
- default value: resolved based on the platform
147+
- supported values: any supported docker image
148+
- *qemuPath*
149+
- default value: executables are resolved from `/usr/bin` directory or downloaded from https://github.com/multiarch/qemu-user-static/releases/download/v2.12.0
150+
- supported values: a path to a directory containing qemu executables
151+
152+
## License
153+
The project is released under version 2.0 of the [Apache License](http://www.apache.org/licenses/LICENSE-2.0.html).

0 commit comments

Comments
 (0)