publish

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 24 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.

Documentation

Overview

Package publish implements "semaphore-cli publish": it reads a directory of flag files and flag-set documents, builds the manifest and publishes both to S3 with controlplane/s3publish, and "semaphore-cli publish verify", which checks what the bucket holds.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnknownFile is returned for a file that is not a document of the layout.
	ErrUnknownFile = errors.New("unknown file")
	// ErrDuplicateObject is returned when two files give one object name.
	ErrDuplicateObject = errors.New("duplicate object name")
	// ErrNoDocuments is returned when the directory holds no document.
	ErrNoDocuments = errors.New("no documents found")
	// ErrNotRegular is returned for a symbolic link, a named pipe, a device or a socket: the loader reads regular
	// files only, never follows a link and never opens a file that could block.
	ErrNotRegular = errors.New("not a regular file")
	// ErrSourceTooLarge is returned when the tree holds more files, or more bytes in distinct documents, than the
	// publisher accepts. It is detected while the tree is read, before the rest is loaded into memory.
	ErrSourceTooLarge = errors.New("source tree is over the limits")
	// ErrFileTooLarge is returned for a file over the size limit of an object. It is refused before it is read.
	ErrFileTooLarge = errors.New("file is over the size limit")
)

Errors of the source loader. Test them with errors.Is.

View Source
var (
	// ErrNoControlPlane is returned when the bootstrap file has no controlPlane section.
	ErrNoControlPlane = errors.New("the bootstrap file has no controlPlane section")
	// ErrNotS3 is returned when the control-plane connection is neither an S3 nor a file connection.
	ErrNotS3 = errors.New("the controlPlane connection is neither an s3 nor a file connection")
)

Errors of the target resolution. Test them with errors.Is.

Functions

func HelpVars

func HelpVars() kong.Vars

HelpVars returns the kong interpolation variables used by Cmd help tags.

func LoadSource

func LoadSource(fsys fs.FS, display string, limits SourceLimits) ([]s3publish.Object, error)

LoadSource reads the documents of a source tree. The layout:

flags/<name>.yaml|yml|json      a flag file (kind flags)
flagsets/<name>.yaml|yml|json   a flag-set document (kind flagSets)

The object name is the file name without its extension; the format comes from the extension (yml is yaml). Names starting with a dot are ignored. Any other file is an error, so a typo is not silently skipped. display is put before the relative path in messages. The objects come in path order. Only regular files and directories are accepted: a symbolic link, a named pipe, a device or a socket is an error that names it (nothing is followed or opened). A file larger than maxObjectBytes (zero means controlplane.DefaultMaxObjectBytes) is refused from its size, before it is read.

func RewriteDashVerify

func RewriteDashVerify(args []string) ([]string, bool)

RewriteDashVerify rewrites a bare "verify" immediately after the first "--" to "./verify" so Kong dispatches it to the <dir> branch rather than the "verify" subcommand.

func Run

func Run(ctx context.Context, args []string, streams *helper.Streams, deps Deps) error

Run parses args against Cmd and executes publish or publish verify with injected context, streams, and deps.

Types

type ApplyCmd

type ApplyCmd struct {
	Dir string `arg:"" help:"Source directory containing flags/, flagsets/ and segments/." name:"dir"`
}

ApplyCmd uploads source documents from a directory and writes the manifest.

func (ApplyCmd) Run

func (a ApplyCmd) Run(ctx context.Context, parent *Cmd, streams *helper.Streams, deps *Deps) error

Run executes the publish operation against ApplyCmd.Dir.

type Cmd

type Cmd struct {
	Config      string `help:"${helpPubConfig}"   name:"config"                   short:"c"`
	Bucket      string `help:"${helpPubBucket}"   name:"bucket"`
	Prefix      string `help:"${helpPubPrefix}"   name:"prefix"`
	Region      string `help:"${helpPubRegion}"   name:"region"`
	Endpoint    string `help:"${helpPubEndpoint}" name:"endpoint"`
	Channel     string `help:"${helpPubChannel}"  name:"channel"`
	Connection  string `help:"${helpPubConn}"     name:"connection"`
	ManifestKey string `help:"${helpPubMKey}"     name:"manifest-key"`
	Output      string `default:"text"            help:"${helpOut}"               name:"output"     short:"o"`
	Generation  uint64 `default:"0"               help:"${helpPubGen}"            name:"generation"`
	DryRun      bool   `help:"${helpPubDryRun}"   name:"dry-run"`
	Replace     bool   `help:"${helpPubReplace}"  name:"replace-invalid-manifest"`
	SignKeyID   string `help:"${helpSignID}"      name:"signing-key-id"`
	SignKeyFile string `help:"${helpSignFile}"    name:"signing-key-file"`
	SignKeyEnv  string `help:"${helpSignEnv}"     name:"signing-key-env"`

	TrustedKeys []string `help:"${helpTrustedKey}" name:"trusted-key" placeholder:"ID=FILE" sep:"none"`

	Dir    ApplyCmd  `arg:"" help:"Source directory containing flags/, flagsets/ and segments/."`
	Verify VerifyCmd `cmd:"" help:"${helpPubVerify}"`

	Rollback RollbackCmd `cmd:"" help:"${helpPubRollback}"`
	Promote  PromoteCmd  `cmd:"" help:"${helpPubPromote}"`
	Keygen   KeygenCmd   `cmd:"" help:"${helpPubKeygen}"`
	// contains filtered or unexported fields
}

Cmd publishes flag files and flag-set documents to S3 behind a manifest, and verifies the bucket.

func (*Cmd) Help

func (*Cmd) Help() string

Help returns the detailed description of publish for kong's help output.

func (*Cmd) SetDashVerifyDir

func (c *Cmd) SetDashVerifyDir(enabled bool)

SetDashVerifyDir records whether a bare "verify" directory appeared after "--" so it is not confused with the "verify" subcommand.

type Deps

type Deps struct {
	// LookupEnv reads an environment variable (secret references of the bootstrap file).
	LookupEnv func(string) (string, bool)
	// ReadFile reads a file (the bootstrap file and its secret files).
	ReadFile func(string) ([]byte, error)
	// OpenDir opens the source directory.
	OpenDir func(dir string) fs.FS
	// NewAPI builds the API of the target (the spec is nil for a file store). Nil means the connection factory of the
	// relay for S3 (it honours ConnectionOptions) and a [filepublish.Store] for a file store.
	NewAPI func(ctx context.Context, spec *connection.S3Spec, name string) (s3publish.API, error)
	// Now stamps createdAt of the manifest.
	Now func() time.Time
	// FileOptions returns the options of the file store of a file target, applied after the options of the command (a
	// test drives the lock wait with a timer of its own). Nil means none.
	FileOptions func() []filepublish.Option
	// ConnectionOptions are passed to the connection factory (a round tripper that counts requests, for example).
	ConnectionOptions []connection.Option
}

Deps are the parts of the outside world that the commands use. Production code uses DefaultDeps; tests and the end-to-end tests replace what they need.

func DefaultDeps

func DefaultDeps() Deps

DefaultDeps returns the dependencies of the real command.

type KeygenCmd added in v0.3.0

type KeygenCmd struct {
	PrivateKey string `help:"${helpKeygenPrivate}" name:"private-key" required:"true"`
	PublicKey  string `help:"${helpKeygenPublic}"  name:"public-key"`
}

KeygenCmd creates a key pair for manifest signing.

func (KeygenCmd) Help added in v0.3.0

func (KeygenCmd) Help() string

Help returns the detailed description of publish keygen for kong's help output.

func (KeygenCmd) Run added in v0.3.0

func (k KeygenCmd) Run(_ context.Context, parent *Cmd, streams *helper.Streams, _ *Deps) error

Run creates the key pair.

type PromoteCmd

type PromoteCmd struct {
	From         string `help:"${helpPromFrom}"   name:"from"          placeholder:"CHANNEL" required:"true"`
	To           string `help:"${helpPromTo}"     name:"to"            placeholder:"CHANNEL" required:"true"`
	CreateTarget bool   `help:"${helpPromCreate}" name:"create-target"`

	SignUnverified bool `help:"${helpSignUnverified}" name:"sign-unverified-content"`
}

PromoteCmd copies the live objects of one channel to a new generation of another channel.

func (PromoteCmd) Help

func (PromoteCmd) Help() string

Help returns the detailed description of publish promote for kong's help output.

func (PromoteCmd) Run

func (c PromoteCmd) Run(ctx context.Context, parent *Cmd, streams *helper.Streams, deps *Deps) error

Run executes the promotion.

type RollbackCmd

type RollbackCmd struct {
	To uint64 `help:"${helpPubTo}" name:"to" placeholder:"GENERATION" required:"true"`

	SignUnverified bool `help:"${helpSignUnverified}" name:"sign-unverified-content"`
}

RollbackCmd restores the objects of an older generation as a new, higher generation.

func (RollbackCmd) Help

func (RollbackCmd) Help() string

Help returns the detailed description of publish rollback for kong's help output.

func (RollbackCmd) Run

func (r RollbackCmd) Run(ctx context.Context, parent *Cmd, streams *helper.Streams, deps *Deps) error

Run executes the rollback.

type SourceLimits

type SourceLimits struct {
	MaxObjects     int
	MaxObjectBytes int64
	MaxTotalBytes  int64
}

SourceLimits bound what LoadSource retains. A zero value means the default of the reader: 20000 files (controlplane.DefaultMaxObjects), 16 MiB per file and 1 GiB for the distinct documents.

type VerifyCmd

type VerifyCmd struct{}

VerifyCmd checks the manifest and every listed object in the bucket without writing.

func (VerifyCmd) Help

func (VerifyCmd) Help() string

Help returns the detailed description of publish verify for kong's help output.

func (VerifyCmd) Run

func (VerifyCmd) Run(ctx context.Context, parent *Cmd, streams *helper.Streams, deps *Deps) error

Run executes the bucket verification check.

Jump to

Keyboard shortcuts

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