Skip to content

Commit 6a85993

Browse files
committed
chore: cleanup API, fix readme
1 parent ddaa37b commit 6a85993

File tree

5 files changed

+85
-10
lines changed

5 files changed

+85
-10
lines changed

README.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,82 @@
11
# PodKeeper
22

3-
PodKeeper is an open-source library for starting and stopping Docker containers in a way that ensures they won’t linger if the host program crashes or exits unexpectedly without properly stopping them.
3+
> ⚠️ **Warning:** PodKeeper is currently in pre-1.0.0 release. Expect potential changes and experimental features that may not be fully stable yet.
4+
5+
PodKeeper is a node.js open-source library for starting and stopping Docker containers in a way that ensures they won’t linger if the host program crashes or exits unexpectedly without properly stopping them.
6+
7+
PodKeeper is written in TypeScript and comes bundled with TypeScript types.
8+
9+
- [Getting Started](#getting-started)
10+
- [Bundled Services & API](#bundled-services--api)
11+
- [How It Works](#how-it-works)
12+
- [PodKeeper vs. TestContainers](#podkeeper-vs-testcontainers)
13+
14+
## Getting Started
15+
16+
1. Install podkeeper:
17+
18+
```sh
19+
npm i --save-dev podkeeper
20+
```
21+
22+
1. Pull container you wish to launch beforehand:
23+
24+
```sh
25+
docker pull postgres:latest
26+
```
27+
28+
1. Start / stop container programmatically:
29+
30+
```ts
31+
import { Postgres } from 'podkeeper';
32+
33+
const postgres = await Postgres.start();
34+
// do something with container...
35+
await postgres.stop();
36+
```
37+
38+
## Bundled services & API
39+
40+
PodKeeper comes bundled with the following pre-configured services:
41+
42+
* MySQL:
43+
44+
```ts
45+
import { MySQL } from 'podkeeper';
46+
```
47+
48+
* Postgres
49+
50+
```ts
51+
import { Postgres } from 'podkeeper';
52+
```
53+
54+
* Minio
55+
56+
```ts
57+
import { Minio } from 'podkeeper';
58+
```
59+
60+
If a popular service is missing, please do not hesitate to submit a pull request.
61+
Alternatively, you can launch a generic container service with the `GenericService` class:
62+
63+
```ts
64+
import { GenericService } from 'podkeeper';
65+
66+
cosnt service = await GenericService.start({
67+
imageName: string,
68+
ports: number[],
69+
healthcheck?: {
70+
test: string[],
71+
intervalMs: number,
72+
retries: number,
73+
startPeriodMs: number,
74+
timeoutMs: number,
75+
},
76+
command?: string[],
77+
env?: { [key: string]: string | number | boolean | undefined };
78+
});
79+
```
480
581
## How It Works
682
@@ -23,4 +99,4 @@ There are also some notable differences in API design philosophy:
2399
24100
- **Process Behavior**: PodKeeper services prevent the Node.js process from exiting, while TestContainers services do not.
25101
- **Container Pulling**: PodKeeper does not implicitly pull containers, requiring them to be available beforehand, whereas TestContainers lazily pulls containers as needed when launching a service.
26-
102+
- **Healthchecks**: The services that PodKeeper ships out-of-the-box are pre-configured to use proper healthchecks.

src/genericService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function connectWebSocket(address: string, deadline: number): Promise<WebS
2323
}
2424

2525
export class GenericService {
26-
static async launch(options: {
26+
static async start(options: {
2727
imageName: string,
2828
ports: number[],
2929
healthcheck?: {

src/minio.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import ms from 'ms';
22
import { GenericService } from './genericService.js';
33

44
export class Minio {
5-
6-
static async launch({ accessKeyId = 'root', secretAccessKey = 'password' } = {}) {
7-
const service = await GenericService.launch({
5+
static async start({ accessKeyId = 'root', secretAccessKey = 'password' } = {}) {
6+
const service = await GenericService.start({
87
imageName: 'quay.io/minio/minio:latest',
98
ports: [9000, 9090],
109
healthcheck: {

src/mysql.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ const MYSQL_PORT = 3306;
66

77
export class MySQL {
88

9-
static async launch({ db = 'mydatabase', rootPassword = 'rootpassword' } = {}) {
10-
const service = await GenericService.launch({
9+
static async start({ db = 'mydatabase', rootPassword = 'rootpassword' } = {}) {
10+
const service = await GenericService.start({
1111
imageName: 'mysql:latest',
1212
ports: [MYSQL_PORT],
1313
healthcheck: {

src/postgres.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ const IMAGE_NAME = 'postgres:latest';
55
const POSTGRES_PORT = 5432;
66

77
export class Postgres {
8-
static async launch({ user = 'user', password = 'password', db = 'postgres' } = {}) {
9-
const service = await GenericService.launch({
8+
static async start({ user = 'user', password = 'password', db = 'postgres' } = {}) {
9+
const service = await GenericService.start({
1010
imageName: 'postgres:latest',
1111
ports: [POSTGRES_PORT],
1212
healthcheck: {

0 commit comments

Comments
 (0)