oci

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

oci

Name

oci - pull OCI artifacts from repositories

Description

oci pulls an OCI artifact into the site using the oras Go SDK. This makes it possible to deploy your zones with a simple oci pull.

The oci plugin starts a service routine that runs during the lifetime of the server. When the service starts, it pulls the artifacts from the repository.

If a pull fails, the service will retry up to three time. Each request will additionally try 3 times if certain response are returned by the repository.

NOTE: This plugin makes use of oras' retry client and will attempt additional retries for each attempt. See oras/registry/remote/retry for the default retry policy.

If the pull was not successful by then, it won't try again until the next interval.

This plugin is inspired by MiekG's git plugin and borrows some syntax and logic.

Syntax

oci REPO [PATH]
  • REPO is the URL to the repository

  • PATH is the path, relative to site root, to pull the artifacts into; default is site root

This simplified syntax pulls the latest tag every 3600 seconds (1 hour) and only works for public repositories.

For more control or to use a private repository, use the following syntax:

oci [REPO PATH] {
  repo              REPO
  path              PATH
  username      USERNAME
  password      PASSWORD
  interval         INTERVAL
}
  • REPO is the URL to the repository; only HTTP/S URLs (http(s):// must be ommitted) are supported.

  • PATH is the path to pull the artifacts into; default is site root (if set). It can be absolute or relative (to site root). See the root plugin.

  • INTERVAl is the number of seconds between pulls; default is 3600 (1 hour), minimum 5.

  • USERNAME is the username to log into the remote repository.

  • PASSWORD is the password to log into the remote repository`

  • IMSECURE if set to "true" connects to the repository with plain HTTP

Examples

Public repository pulled into site root every hour:

example.org {
    root /etc/zones
    oci registry-1.docker.io/ganawaj/demo:0.0.2
}

Private repository pulled into "example.org" directory or /etc/zones/example.org

example.org {
    root /etc/zones
    oci registry-1.docker.io/ganawaj/demo:0.0.2 {
      path example.org
      username ganawaj
      password dckr_pat_THISISANEXAMPLE
      interval 10
    }
}

Local private repository with no authentication using plain HTTP. Tag latest is assummed.

example.org {
    root /etc/zones
    oci localhost:5000/ganawaj/demo {
      path example.org
      insecure true
    }
}

Full example using file plugin assuming demo pulls a db.example.org artifact

example.org {
    root /etc/zones

    oci registry-1.docker.io/ganawaj/demo:0.0.2 {
      path example.org
      username ganawaj
      password dckr_pat_THISISANEXAMPLE
      interval 10
    }

    file example.org/db.example.org
}

Also See

The root plugin for setting the root.

The git plugin for inspiration for this plugin.

The auto or file plugin for reading zone files from disk.

Documentation

Index

Constants

View Source
const (
	// DefaultInterval is the default interval between artifact pulls
	DefaultInterval = 180 * time.Second
	// MinimumInterval is the minimum allowed interval between pulls
	MinimumInterval = 180 * time.Second
)

Variables

View Source
var (
	// DefaultDeadline is the maximum time allowed for a single pull operation
	DefaultDeadline = 60 * time.Second
	// DefaultRetryInterval is the time between retry attempts
	DefaultRetryInterval = 10 * time.Second
	// DefaultRetryCount is the maximum number of retry attempts
	DefaultRetryCount = 3
)
View Source
var (
	// ErrInvalidArtifactIndex is returned when accessing an invalid artifact index
	ErrInvalidArtifactIndex = errors.New("invalid artifact index")
	// ErrEmptyURL is returned when the artifact URL is empty
	ErrEmptyURL = errors.New("empty artifact URL")
	// ErrEmptyPath is returned when the artifact path is empty
	ErrEmptyPath = errors.New("empty artifact path")
)

Functions

func PullWithRetry

func PullWithRetry(ctx context.Context, a *Artifact)

func Start

func Start(a *Artifact, ctx context.Context)

Start starts the artifact pull process in the background.

To attempt to respect the rate limits of the registry: - the pull operation has 60(DefaultDeadline) seconds to complete. - the pull operation will retry every 10 seconds. - the pull operation will try no more than 3 times. The next pull operation is scheduled after a successful pull at the interval specified in the artifact.

Types

type Artifact

type Artifact struct {
	URL      string
	Interval time.Duration
	Path     string

	// credentials and connection settings
	Credential auth.Credential
	// contains filtered or unexported fields
}

Artifact represents a single OCI artifact with its configuration and state

func (*Artifact) Login

func (a *Artifact) Login(ctx context.Context) error

Login authenticates with the registry if required.

func (*Artifact) Prepare

func (a *Artifact) Prepare() error

Prepare initializes the artifact by setting up the repository configuration and performing authentication if credentials are provided.

func (*Artifact) Pull

func (a *Artifact) Pull(ctx context.Context) error

Pull downloads the artifact from the remote repository to the local file system.

func (*Artifact) Reference

func (a *Artifact) Reference() string

Reference returns the tag or digest from the remote reference

func (*Artifact) Registry

func (a *Artifact) Registry() string

Registry returns the registry name from the remote reference

func (*Artifact) Repository

func (a *Artifact) Repository() string

Repository returns the repository name from the remote reference

type OCI

type OCI []*Artifact

OCI is a list of artifacts

func (OCI) Artifact

func (o OCI) Artifact(i int) (*Artifact, error)

Artifact returns the artifact at index i

Jump to

Keyboard shortcuts

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