Documentation
¶
Overview ¶
Package justpull pulls container images through a local pull-through proxy that keeps every downloaded byte on disk, so a pull broken by the network, a failed attempt or a restart continues where it stopped instead of starting over.
Docker is pointed at 127.0.0.1:<port>/<repository>, which dockerd treats as an insecure registry by default. It asks the proxy only for the blobs it does not have, on either image store; the proxy fetches them from the real registry, resuming after any break, and serves them while they download, so Docker's own connection never breaks. After a successful pull the image gets its real name, the localhost name is removed and the cached files are deleted.
Index ¶
Constants ¶
const ( // DefaultStallLimit is how long a layer may go without a new byte from // the registry, reconnects included, before the pull fails. A slow link // that keeps moving is never cut off. DefaultStallLimit = 10 * time.Minute // DefaultMaxAge is how long Sweep keeps a cached file after its last // write. DefaultMaxAge = 24 * time.Hour )
Variables ¶
var ErrRefused = errors.New("access refused")
ErrRefused is wrapped by the error of a registry that refused the login, or refused access to the image: a login, or another one, may help.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores blobs on disk by digest and pulls images through them, so a download broken by the network, a failed pull or a restart continues where it stopped. Layout: <dir>/blobs/sha256/<hex> once verified, <hex>.partial while downloading; <dir>/manifests/sha256/<hex> for the manifests relayed, which name an image's blobs for cleanup; <dir>/locks/sha256/<hex>.dl and <hex>.use, the flock(2) files that coordinate the processes sharing the directory.
Several processes, or several Caches, may share a directory. A blob is downloaded by one of them at a time; the others stream it from the cache file as it arrives, and one of them takes the download over from what is on disk if its downloader dies or gives up. Cleanup and Sweep skip blobs another process uses. Unix only (Linux, macOS, the BSDs): New fails elsewhere. A Cache's methods are safe for concurrent use.
func (*Cache) Pull ¶
Pull pulls ref into Docker through the cache. On success the image is known by ref, as after a plain docker pull, and this pull's cached files are gone. On failure or cancel they stay, so the next Pull of an image sharing those layers continues where this one stopped. progress may be nil; it is called from Pull's goroutine.
func (*Cache) Sweep ¶
Sweep deletes cached files that have not been written for MaxAge and are not in use by this or another process, and the lock files of blobs whose files are gone. Pull runs it first; a long-running caller should also run it periodically so a cancelled pull's files go even when no new pull comes.
type Credential ¶
type Credential struct {
Username string
Password string
// IdentityToken is an OAuth2 refresh token. When set it is used
// instead of Username and Password.
IdentityToken string
}
Credential is a registry login, as `docker login` stores it.
type Docker ¶
type Docker interface {
Pull(ctx context.Context, ref string) (io.ReadCloser, error)
Tag(ctx context.Context, source, target string) error
Untag(ctx context.Context, ref string) error
}
Docker is the part of the Docker API a pull needs. References are plain image references. An implementation over the Docker client:
Pull: ImagePull(ref) with no registry auth, returning the progress stream Tag: ImageTag(source, target) Untag: ImageRemove(ref) with Force and PruneChildren off
type Options ¶
type Options struct {
// StallLimit fails a pull when a layer has received no new bytes for
// this long. Zero means DefaultStallLimit.
StallLimit time.Duration
// MaxAge is how long Sweep keeps a cached file after its last write.
// Zero means DefaultMaxAge.
MaxAge time.Duration
// Logger receives warnings that do not fail a pull. Nil means
// slog.Default().
Logger *slog.Logger
// Credentials returns the login for a registry, named as in image
// references: docker.io for Docker Hub, ghcr.io, localhost:5000,
// 127.0.0.1:5000. It is called only when a registry answers 401 with a
// challenge, and may be called concurrently. A zero Credential means
// anonymous; nil means every pull is anonymous.
Credentials func(ctx context.Context, registry string) (Credential, error)
}
Options tunes a Cache. The zero value uses the defaults.
type Progress ¶
Progress is how far a pull's downloads are, in compressed bytes. Layers Docker already has are not counted.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is the proxy of one pull without the Docker calls, for a caller that drives Docker itself: Docker pulls LocalRef, the caller tags the image, and Finish ends the session. Pull is built on it.
func (*Session) Context ¶
Context ends when a layer fails for good, with that failure as its cause, or when Stop runs. The caller then cancels Docker's pull.
func (*Session) Finish ¶
Finish stops the session. After a successful pull it deletes the image's cached blobs, except those another process is using, and its saved manifests; after a failed one they stay, so the next pull of an image sharing those layers continues from them. The error is about deleting.
func (*Session) LayerSize ¶
LayerSize returns the size the image's manifests give for the layer that Docker's progress stream names by its 12-character ID, or 0 if unknown.
type SessionOptions ¶
type SessionOptions struct {
// AllTags serves every tag of the repository and its tag list, for
// docker pull --all-tags. The reference must then name no tag or digest.
AllTags bool
}
SessionOptions tunes a Session. The zero value serves the image the reference names.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
justpull
command
Command justpull is docker pull through a cache that keeps every downloaded byte, so a broken pull continues where it stopped.
|
Command justpull is docker pull through a cache that keeps every downloaded byte, so a broken pull continues where it stopped. |
|
internal
|
|
|
dockerconfig
Package dockerconfig finds the registry login the docker CLI would use, from DOCKER_AUTH_CONFIG, its config file and its credential helpers.
|
Package dockerconfig finds the registry login the docker CLI would use, from DOCKER_AUTH_CONFIG, its config file and its credential helpers. |
|
engine
Package engine talks to the Docker daemon that the user's docker command reaches, whatever its context, DOCKER_HOST or transport, without the Docker SDK.
|
Package engine talks to the Docker daemon that the user's docker command reaches, whatever its context, DOCKER_HOST or transport, without the Docker SDK. |
|
fakedocker
Package fakedocker is a Docker for tests.
|
Package fakedocker is a Docker for tests. |
|
fakereg
Package fakereg is an in-process OCI registry for tests: images with random layers, a paged tag list, optional bearer auth, an optional login (basic, or for the token), optional redirects to a separate storage host whose links expire, scripted faults on blob GETs, and an optional rate limit on blob bodies.
|
Package fakereg is an in-process OCI registry for tests: images with random layers, a paged tag list, optional bearer auth, an optional login (basic, or for the token), optional redirects to a separate storage host whose links expire, scripted faults on blob GETs, and an optional rate limit on blob bodies. |
|
proxyimage
Package proxyimage makes the image that runs the justpull proxy present in Docker: imported from the Linux binary a release build embeds, or pulled.
|
Package proxyimage makes the image that runs the justpull proxy present in Docker: imported from the Linux binary a release build embeds, or pulled. |