dbdocker

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package dbdocker runs a one-off database container so pggen can introspect a schema without a database of its own.

It holds the parts that don't care which database is running — building an image from a Dockerfile and init scripts, starting and stopping the container, capturing its logs, picking a host port. The database-specific pieces (the image, the port it listens on, how to tell it is ready) come from Config; see internal/pgdocker and internal/chdocker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitScriptNames

func InitScriptNames(initScripts []string) []string

InitScriptNames returns the name each init script takes in the build context, numbered so the image runs them in order.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client controls a running database container.

func Start

func Start(ctx context.Context, cfg Config) (_ *Client, mErr error)

Start builds an image from cfg and runs it, returning once the database is ready.

func (*Client) GetContainerLogs

func (c *Client) GetContainerLogs() (logs string, mErr error)

GetContainerLogs returns all stdout and stderr logs for the container. Useful to enrich output when pggen fails to start the container.

func (*Client) Port

func (c *Client) Port() ports.Port

Port returns the host port the database is published on.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context) error

Stop stops the running container, if any.

type Config

type Config struct {
	// Name of the database, used in log and error messages.
	Name string
	// Dockerfile is the full contents of the Dockerfile to build. It should
	// copy each entry of InitScripts, by base name, wherever the image expects
	// initialization scripts.
	Dockerfile string
	// InitScripts are host paths to schema files, added to the build context
	// under a numeric prefix so they run in the order given.
	InitScripts []string
	// Env is the container environment, like "POSTGRES_HOST_AUTH_METHOD=trust".
	Env []string
	// Cmd overrides the image command, if set.
	Cmd []string
	// Port the database listens on inside the container, like "5432/tcp".
	Port nat.Port
	// Tmpfs mounts, used to keep the data directory off disk.
	Tmpfs map[string]string
	// WaitReady blocks until the database accepts connections on the host port.
	WaitReady func(ctx context.Context, port ports.Port) error
}

Config describes the container to run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL