workspace

package
v1.33.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package workspace contains functionality to manage a user's local workspace. This includes creating an application directory, reading and writing a summary file to associate the workspace with the application, and managing infrastructure-as-code files. The typical workspace will be structured like:

.
├── copilot                        (application directory)
│   ├── .workspace                 (workspace summary)
│   ├── my-service
│   │   └── manifest.yml           (service manifest)
|   |   environments
|   |   └── test
│   │       └── manifest.yml       (environment manifest for the environment test)
│   ├── buildspec.yml              (legacy buildspec for the pipeline's build stage)
│   ├── pipeline.yml               (legacy pipeline manifest)
│   ├── pipelines
│   │   ├── pipeline-app-beta
│   │   │   ├── buildspec.yml      (buildspec for the pipeline 'pipeline-app-beta')
│   ┴   ┴   └── manifest.yml       (pipeline manifest for the pipeline 'pipeline-app-beta')
└── my-service-src                 (customer service code)

Index

Constants

View Source
const (
	// CopilotDirName is the name of the directory where generated infrastructure code for an application will be stored.
	CopilotDirName = "copilot"
	// SummaryFileName is the name of the file that is associated with the application.
	SummaryFileName = ".workspace"
	// AddonsParametersFileName is the name of the file that define extra parameters for an addon.
	AddonsParametersFileName = "addons.parameters.yml"
)

Variables

View Source
var ErrNoPipelineInWorkspace = errors.New("no pipeline manifest found in the workspace")

ErrNoPipelineInWorkspace means there was no pipeline manifest in the workspace dir.

View Source
var ErrTraverseUpShouldStop = errors.New("should stop")

ErrTraverseUpShouldStop signals that TraverseUp should stop.

Functions

func IsEmptyErr added in v1.24.0

func IsEmptyErr(err error) bool

IsEmptyErr returns true if the error is related to an empty workspace.

func IsInGitRepository added in v0.3.0

func IsInGitRepository(fs FileStat) bool

IsInGitRepository returns true if the current working directory is a git repository.

func TraverseUp added in v1.29.0

func TraverseUp(startDir string, maxLevels int, process TraverseUpProcessFn) (string, error)

TraverseUp traverses at most `maxLevels` up from the starting directory, invoke TraverseUpProcessFn at each level, and returns the value that it gets TraverseUpProcessFn process upon receiving an ErrTraverseUpShouldStop signal. If after traversing up `maxLevels`, it still hasn't received a ErrTraverseUpShouldStop signal, it will return ErrTargetNotFound.

Types

type EnvironmentManifest added in v1.19.0

type EnvironmentManifest []byte

EnvironmentManifest represents raw local environment manifest.

type ErrFileExists

type ErrFileExists struct {
	FileName string
}

ErrFileExists means we tried to create an existing file.

func (*ErrFileExists) Error

func (e *ErrFileExists) Error() string

type ErrFileNotExists added in v1.13.0

type ErrFileNotExists struct {
	FileName string
}

ErrFileNotExists means we tried to read a non-existing file.

func (*ErrFileNotExists) Error added in v1.13.0

func (e *ErrFileNotExists) Error() string

type ErrNoAssociatedApplication added in v1.24.0

type ErrNoAssociatedApplication struct{}

ErrNoAssociatedApplication means we couldn't locate a workspace summary file.

func (*ErrNoAssociatedApplication) Error added in v1.24.0

func (*ErrNoAssociatedApplication) RecommendActions added in v1.24.0

func (_ *ErrNoAssociatedApplication) RecommendActions() string

RecommendActions suggests steps clients can take to mitigate the .workspace file not found error.

type ErrTargetNotFound added in v1.29.0

type ErrTargetNotFound struct {
	// contains filtered or unexported fields
}

ErrTargetNotFound means that we couldn't locate the target file or the target directory.

func (*ErrTargetNotFound) Error added in v1.29.0

func (e *ErrTargetNotFound) Error() string

type ErrWorkspaceNotFound added in v1.13.0

type ErrWorkspaceNotFound struct {
	*ErrTargetNotFound
	// contains filtered or unexported fields
}

ErrWorkspaceNotFound means we couldn't locate a workspace root.

func (*ErrWorkspaceNotFound) Error added in v1.13.0

func (e *ErrWorkspaceNotFound) Error() string

func (*ErrWorkspaceNotFound) RecommendActions added in v1.24.0

func (_ *ErrWorkspaceNotFound) RecommendActions() string

RecommendActions suggests steps clients can take to mitigate the copilot/ directory not found error.

type FileStat added in v0.3.0

type FileStat interface {
	Stat(name string) (os.FileInfo, error)
}

FileStat wraps the os.Stat function.

type PipelineManifest added in v1.16.0

type PipelineManifest struct {
	Name string // Name of the pipeline inside the manifest file.
	Path string // Absolute path to the manifest file for the pipeline.
}

PipelineManifest holds identifying information about a pipeline manifest file.

type Summary

type Summary struct {
	Application string `yaml:"application"` // Name of the application.
	Path        string `yaml:"-"`           // Absolute path to the summary file.
}

Summary is a description of what's associated with this workspace.

type TraverseUpProcessFn added in v1.29.0

type TraverseUpProcessFn func(dir string) (result string, err error)

TraverseUpProcessFn represents a function that TraverseUp invokes at each level of traversal. If TraverseUpProcessFn returns an ErrTraverseUpShouldStop, TraverseUp will stop traversing, return the result and a nil error. If TraverseUpProcessFn returns some other error, TraverseUp will stop traversing, return an empty string and the error. If TraverseUpProcessFn returns a nil error, TraverseUp will keep traversing up the directory tree.

type WorkloadManifest added in v1.13.0

type WorkloadManifest []byte

WorkloadManifest represents raw local workload manifest.

func (WorkloadManifest) WorkloadType added in v1.13.0

func (w WorkloadManifest) WorkloadType() (string, error)

WorkloadType returns the workload type of the manifest.

type Workspace

type Workspace struct {
	CopilotDirAbs string // TODO: make private by adding mocks for selector unit testing.
	// contains filtered or unexported fields
}

Workspace typically represents a Git repository where the user has its infrastructure-as-code files as well as source files.

func Create added in v1.24.0

func Create(appName string, fs afero.Fs) (*Workspace, error)

Create creates a new Workspace in the current working directory for appName with summary if it doesn't already exist.

func Use added in v1.24.0

func Use(fs afero.Fs) (*Workspace, error)

Use returns an existing workspace, searching for a copilot/ directory from the current wd, up to 5 levels above. It returns ErrWorkspaceNotFound if no copilot/ directory is found.

func (*Workspace) DeleteWorkspaceFile

func (ws *Workspace) DeleteWorkspaceFile() error

DeleteWorkspaceFile removes the .workspace file under copilot/ directory. This will be called during app delete, we do not want to delete any other generated files.

func (*Workspace) EnvAddonFileAbsPath added in v1.26.0

func (ws *Workspace) EnvAddonFileAbsPath(fName string) string

EnvAddonFileAbsPath returns the absolute path of an addon file for environments.

func (*Workspace) EnvAddonFilePath added in v1.24.0

func (ws *Workspace) EnvAddonFilePath(fName string) string

EnvAddonFilePath returns the path under the workspace of an addon file for environments.

func (*Workspace) EnvAddonsAbsPath added in v1.26.0

func (ws *Workspace) EnvAddonsAbsPath() string

EnvAddonsAbsPath returns the absolute path for the addons/ directory of environments.

func (*Workspace) EnvOverridesPath added in v1.26.0

func (ws *Workspace) EnvOverridesPath() string

EnvOverridesPath returns the default path to the overrides/ directory for environments.

func (*Workspace) HasEnvironments added in v1.26.0

func (ws *Workspace) HasEnvironments() (bool, error)

HasEnvironments returns true if the workspace manages environments.

func (*Workspace) ListEnvironments added in v1.19.0

func (ws *Workspace) ListEnvironments() ([]string, error)

ListEnvironments returns the name of the environments in the workspace.

func (*Workspace) ListFiles added in v1.24.0

func (ws *Workspace) ListFiles(dirPath string) ([]string, error)

ListFiles returns a list of file paths to all the files under the dir.

func (*Workspace) ListJobs added in v1.13.0

func (ws *Workspace) ListJobs() ([]string, error)

ListJobs returns the names of all jobs in the workspace.

func (*Workspace) ListPipelines added in v1.16.0

func (ws *Workspace) ListPipelines() ([]PipelineManifest, error)

ListPipelines returns all pipelines in the workspace.

func (*Workspace) ListServices added in v1.13.0

func (ws *Workspace) ListServices() ([]string, error)

ListServices returns the names of the services in the workspace.

func (*Workspace) ListWorkloads added in v1.13.0

func (ws *Workspace) ListWorkloads() ([]string, error)

ListWorkloads returns the name of all the workloads in the workspace (could be unregistered in SSM).

func (*Workspace) Path added in v1.14.0

func (ws *Workspace) Path() string

Path returns the absolute path to the workspace.

func (*Workspace) PipelineOverridesPath added in v1.29.0

func (ws *Workspace) PipelineOverridesPath(name string) string

PipelineOverridesPath returns the default path to the overrides/ directory for a given pipeline.

func (*Workspace) ProjectRoot added in v1.28.0

func (ws *Workspace) ProjectRoot() string

ProjectRoot returns a path to the presumed root of the project, the directory that contains the copilot dir and .workspace file.

func (*Workspace) ReadEnvironmentManifest added in v1.19.0

func (ws *Workspace) ReadEnvironmentManifest(mftDirName string) (EnvironmentManifest, error)

ReadEnvironmentManifest returns the contents of the environment's manifest under copilot/environments/{name}/manifest.yml.

func (*Workspace) ReadFile added in v1.24.0

func (ws *Workspace) ReadFile(fPath string) ([]byte, error)

ReadFile returns the content of a file. Returns ErrFileNotExists if the file does not exist.

func (*Workspace) ReadPipelineManifest

func (ws *Workspace) ReadPipelineManifest(path string) (*manifest.Pipeline, error)

ReadPipelineManifest returns the contents of the pipeline manifest under the given path.

func (*Workspace) ReadWorkloadManifest added in v0.4.0

func (ws *Workspace) ReadWorkloadManifest(mftDirName string) (WorkloadManifest, error)

ReadWorkloadManifest returns the contents of the workload's manifest under copilot/{name}/manifest.yml.

func (*Workspace) Rel added in v1.16.0

func (ws *Workspace) Rel(path string) (string, error)

Rel returns the relative path to path from the workspace copilot directory.

func (*Workspace) Summary

func (ws *Workspace) Summary() (*Summary, error)

Summary returns a summary of the workspace. The method assumes that the workspace exists and the path is known.

func (*Workspace) WorkloadAddonFileAbsPath added in v1.26.0

func (ws *Workspace) WorkloadAddonFileAbsPath(wkldName, fName string) string

WorkloadAddonFileAbsPath returns the absolute path of an addon file for a given workload.

func (*Workspace) WorkloadAddonFilePath added in v1.24.0

func (ws *Workspace) WorkloadAddonFilePath(wkldName, fName string) string

WorkloadAddonFilePath returns the path under the workspace of an addon file for a given workload.

func (*Workspace) WorkloadAddonsAbsPath added in v1.26.0

func (ws *Workspace) WorkloadAddonsAbsPath(name string) string

WorkloadAddonsAbsPath returns the absolute path for the addons/ directory file path of a given workload.

func (*Workspace) WorkloadExists added in v1.26.0

func (ws *Workspace) WorkloadExists(name string) (bool, error)

WorkloadExists returns true if a workload exists in the workspace.

func (*Workspace) WorkloadOverridesPath added in v1.26.0

func (ws *Workspace) WorkloadOverridesPath(name string) string

WorkloadOverridesPath returns the default path to the overrides/ directory for a given workload.

func (*Workspace) Write added in v1.26.0

func (ws *Workspace) Write(content encoding.BinaryMarshaler, path string) (string, error)

Write writes the content under the path relative to "copilot/" directory. If successful returns the full path of the file, otherwise an empty string and an error.

func (*Workspace) WriteEnvironmentManifest added in v1.20.0

func (ws *Workspace) WriteEnvironmentManifest(marshaler encoding.BinaryMarshaler, name string) (string, error)

WriteEnvironmentManifest writes the environment manifest under the copilot/environments/{name}/ directory. If successful returns the full path of the file, otherwise returns an empty string and the error.

func (*Workspace) WriteJobManifest added in v0.5.0

func (ws *Workspace) WriteJobManifest(marshaler encoding.BinaryMarshaler, name string) (string, error)

WriteJobManifest writes the job's manifest under the copilot/{name}/ directory.

func (*Workspace) WritePipelineBuildspec

func (ws *Workspace) WritePipelineBuildspec(marshaler encoding.BinaryMarshaler, name string) (string, error)

WritePipelineBuildspec writes the pipeline buildspec under the copilot/pipelines/{name}/ directory. If successful returns the full path of the file, otherwise returns an empty string and the error.

func (*Workspace) WritePipelineManifest

func (ws *Workspace) WritePipelineManifest(marshaler encoding.BinaryMarshaler, name string) (string, error)

WritePipelineManifest writes the pipeline manifest under the copilot/pipelines/{name}/ directory. If successful returns the full path of the file, otherwise returns an empty string and the error.

func (*Workspace) WriteServiceManifest

func (ws *Workspace) WriteServiceManifest(marshaler encoding.BinaryMarshaler, name string) (string, error)

WriteServiceManifest writes the service's manifest under the copilot/{name}/ directory.

Jump to

Keyboard shortcuts

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