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 ¶
- Variables
- func HelpVars() kong.Vars
- func LoadSource(fsys fs.FS, display string, limits SourceLimits) ([]s3publish.Object, error)
- func RewriteDashVerify(args []string) ([]string, bool)
- func Run(ctx context.Context, args []string, streams *helper.Streams, deps Deps) error
- type ApplyCmd
- type Cmd
- type Deps
- type PromoteCmd
- type RollbackCmd
- type SourceLimits
- type VerifyCmd
Constants ¶
This section is empty.
Variables ¶
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.
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 LoadSource ¶
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 ¶
RewriteDashVerify rewrites a bare "verify" immediately after the first "--" to "./verify" so Kong dispatches it to the <dir> branch rather than the "verify" subcommand.
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.
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"`
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}"`
// contains filtered or unexported fields
}
Cmd publishes flag files and flag-set documents to S3 behind a manifest, and verifies the bucket.
func (*Cmd) SetDashVerifyDir ¶
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 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"`
}
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.
type RollbackCmd ¶
type RollbackCmd struct {
To uint64 `help:"${helpPubTo}" name:"to" placeholder:"GENERATION" required:"true"`
}
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.
type SourceLimits ¶
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.