kontext

package module
v0.0.0-...-631f8aa Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2019 License: Apache-2.0 Imports: 18 Imported by: 1

README

Kontext

Overview

This repository contains an EXPERIMENTAL PROTOTYPE, with the goal of uploading a local source context (e.g. a local directory) for use in the Knative Build CRD (or compatible definitions).

The high-level objectives of this prototype are:

  1. Aim for a level of incrementality akin to the "GCS Fetcher" currently available in the Knative Build CRD,
  2. Work through vendor-agnostic / standardized APIs,
  3. Don't require implementation-specific knowledge of how the Build CRD works.
How it works (tl;dr)

This tool works by essentially creating a self-extracting source-context, which when run expands the files collected from the local directory into /workspace.

How it works (detail)

Similar to ko, this tool assembles a container image directly (without Docker), which effectively looks like:

# This effectively does a: cp -r /var/run/kontext /workspace
FROM <image pre-built from ./cmd/extractor>

# Add the directory containing the desired context under this path.
ADD ./dir /var/run/kontext

# Add a manifest of the files included (more on this later)
ADD <manifest> /var/lib/kontext/manifest.json

So without Docker, we effectively assemble the source directory into a container image, which can be done by invoking:

go run ./cmd/kontext/main.go --directory=/path/to/directory --tag=gcr.io/project/image:tag

This can then be supplied to the Build CRD's custom source step like:

spec:
  source:
    custom:
      image: gcr.io/project/image:tag

Or tested locally via:

docker pull gcr.io/project/image:tag
docker run -ti --rm -v /path/on/host:/workspace gcr.io/project/image:tag
How it is incremental

On subsequent invocations, kontext first cracks open the target image (if it exists) and extracts the manifest file, which reflects the state of the /var/run/kontext directory once mounted by an overlayfs. Leveraging this context, it can compute a "delta" layer, which only contains changed files. For example:

FROM <previous iteration of the target image>

# Based on the manifest of the previous image, a single layer
# is added that adds any changed files, and "whites out" any
# files/directories that have been removed.
ADD <ONLY CHANGED FILES> /var/run/kontext

# Add a new manifest of the files included.
ADD <manifest> /var/lib/kontext/manifest.json

So for example, if the directory being uploaded as context is:

a/
  b
  c       <-- new
  d

foo/
  bar     <-- new

baz/
  blah/
    bleh  <-- changed

gone/
  ...     <-- all removed.

Then the "delta" layer would only contain:

a/
  c

foo/
  bar

baz/
  blah/
    bleh

.wh.gone  <-- "whiteout" file

TODOs

  • Handle layer limits
  • Handle symlinks
  • Heuristics around whether to reuse the previous image at all

Documentation

Index

Constants

View Source
const (
	BasePath     = "/var/run/kontext"
	ManifestPath = "/var/lib/kontext/manifest.json"
)

Variables

View Source
var (
	ErrNoChange = errors.New("no change in source context (or empty)")
)

Functions

func BuildImage

func BuildImage(directory, tag string, rebase bool) error

func BuildImageWithFilter

func BuildImageWithFilter(directory, tag string, rebase bool, filter func(path string) (bool, error)) error

Types

This section is empty.

Directories

Path Synopsis
cmd
pkg
manifest
Package manifest contains the type and methods used for synthesizing and manipulating manifest files outlining the contents of a particular directory when it is joined together by an overlayfs.
Package manifest contains the type and methods used for synthesizing and manipulating manifest files outlining the contents of a particular directory when it is joined together by an overlayfs.

Jump to

Keyboard shortcuts

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