Documentation
¶
Overview ¶
Package projects provides utilities for managing Docker Compose projects and their metadata.
Index ¶
- Constants
- Variables
- func BuildAdditiveOverrideEnvContent(gitContent, localContent string) (string, error)
- func BuildEffectiveEnvContent(gitContent, overrideContent string) (string, error)
- func BuildOverrideEnvContent(gitContent, effectiveContent string) (string, error)
- func CleanupRemovedFiles(projectsRoot, projectPath string, oldFiles, newFiles []string) error
- func ComposeDown(ctx context.Context, proj *types.Project, removeVolumes bool) error
- func ComposeFileCandidates() []string
- func ComposeLogs(ctx context.Context, projectName string, out io.Writer, follow bool, ...) error
- func ComposePs(ctx context.Context, proj *types.Project, services []string, all bool) ([]api.ContainerSummary, error)
- func ComposePull(ctx context.Context, proj *types.Project, services []string) error
- func ComposeRestart(ctx context.Context, proj *types.Project, services []string) error
- func ComposeStop(ctx context.Context, proj *types.Project, services []string) error
- func ComposeUp(ctx context.Context, proj *types.Project, services []string, ...) error
- func CopyDirectoryContents(srcDir, destDir string) error
- func CreateUniqueDir(projectsRoot, basePath, name string, perm os.FileMode) (path, folderName string, err error)
- func DefaultSwarmStackEnvTemplate() string
- func DefaultSwarmStackTemplate() string
- func DetectComposeFile(dir string) (string, error)
- func DirectorySyncContentsChanged(projectPath string, syncFiles []SyncFile, oldSyncedFiles []string, ...) (bool, error)
- func EnsureDefaultTemplates(ctx context.Context) error
- func EnsureEnvFile(projectsRoot, dirPath string) error
- func EnsureTemplateDir(ctx context.Context, base string) (dir, composePath, envPath string, err error)
- func GetProjectsDirectory(ctx context.Context, projectsDir string) (string, error)
- func GetTemplatesDirectory(ctx context.Context) (string, error)
- func HasComposeRootKeysInFile(path string) (bool, error)
- func ImportedComposeDescription(dir string) string
- func IsBinaryProjectFileContent(content []byte) bool
- func IsProjectDirectoryEntry(entry os.DirEntry, path string, followSymlinks bool) bool
- func IsProjectDirectoryPath(path string, followSymlinks bool) (bool, error)
- func IsProjectFile(filename string) bool
- func IsSafeSubdirectory(baseDir, subdir string) bool
- func IsWindowsDrivePath(path string) bool
- func ListGlobalComposeContainers(ctx context.Context) ([]container.Summary, error)
- func LoadComposeProject(ctx context.Context, composeFile, projectName, projectsDirectory string, ...) (*composetypes.Project, error)
- func LoadComposeProjectFromDir(ctx context.Context, dir, projectName, projectsDirectory string, ...) (*composetypes.Project, string, error)
- func ParseEnvContent(content string) []env.Variable
- func ReadFolderComposeTemplate(baseDir, folder string) (string, *string, string, bool, error)
- func ReadProjectDirectoryFiles(projectPath string, shownFiles map[string]bool, maxDepth int, ...) ([]project.IncludeFile, error)
- func ReadProjectFiles(projectPath, composePath string) (composeContent, envContent string, err error)
- func RemoveProjectFile(projectsRoot, dirPath, fileName string) error
- func RemoveStaleComposeFiles(projectPath, composeFileName string, syncedFiles []string) error
- func ResolveConfiguredContainerDirectory(configuredPath, defaultPath string) string
- func ResolveDirectoryIdentityInternal(path string) (string, error)
- func SanitizeProjectName(name string) string
- func SaveOrUpdateProjectFiles(projectsRoot, projectPath, composeContent string, envContent *string) error
- func Slugify(in string) string
- func ValidateIncludePathForWrite(projectDir, includePath string) (string, error)
- func WriteComposeFile(projectsRoot, dirPath, content string) error
- func WriteEnvFile(projectsRoot, dirPath, content string) error
- func WriteFileWithPerm(filePath, content string, perm os.FileMode) error
- func WriteIncludeFile(projectDir, includePath, content string) error
- func WriteProjectFile(projectsRoot, dirPath, fileName, content string) error
- func WriteProjectFiles(projectsRoot, dirPath, composeContent string, envContent *string) error
- func WriteSyncedDirectory(projectsRoot, projectPath string, files []SyncFile) ([]string, error)
- func WriteTemplateFile(filePath, content string) error
- func WriteTemplateFiles(composePath, envPath, composeContent, envContent string) (*string, error)
- type ArcaneComposeMetadata
- type Client
- type DiscoveredProjectDir
- type EnvLoader
- type EnvMap
- type IncludeFile
- type PathMapper
- type ProgressWriterKey
- type ProjectEnvMode
- type ProjectEnvState
- type SyncFile
Constants ¶
const ( GlobalEnvFileName = ".env.global" EffectiveEnvFileName = ".env" GitSourceEnvFileName = ".env.git" OverrideEnvFileName = "project.env" )
const (
// ArcaneIconLabel is the full reverse-DNS label key for service-level icons.
ArcaneIconLabel = "com.getarcaneapp.arcane.icon"
)
Variables ¶
var ProjectFileCandidates = []string{
"compose.yaml",
"compose.yml",
"docker-compose.yaml",
"docker-compose.yml",
"podman-compose.yaml",
"podman-compose.yml",
".env",
}
Functions ¶
func BuildAdditiveOverrideEnvContent ¶ added in v1.16.3
BuildAdditiveOverrideEnvContent derives override content from a pre-git local .env file. Like other generated env helpers, the result is normalized and does not preserve comments or original key ordering.
func BuildEffectiveEnvContent ¶ added in v1.16.3
BuildEffectiveEnvContent merges git and override env sources into the effective .env content written to disk. The output is normalized: comments are dropped, keys are sorted, and values are rewritten with Arcane's formatter.
func BuildOverrideEnvContent ¶ added in v1.16.3
BuildOverrideEnvContent derives the editable override file from git-backed and effective env content. The generated output is normalized and does not retain comments or original key ordering.
func CleanupRemovedFiles ¶ added in v1.17.0
CleanupRemovedFiles deletes files that were in the old sync but are not in the new sync. It only removes files that were previously synced (tracked in oldFiles). Empty directories are removed after file deletion. This is a best-effort operation - errors are logged but don't cause failure.
func ComposeDown ¶
func ComposeFileCandidates ¶ added in v1.17.1
func ComposeFileCandidates() []string
ComposeFileCandidates returns the supported compose filenames in Arcane's detection order. A copy is returned so callers can't mutate package state.
func ComposeLogs ¶
func ComposePull ¶ added in v1.17.0
func ComposeRestart ¶
func ComposeStop ¶ added in v1.17.0
func CopyDirectoryContents ¶ added in v1.17.2
func CreateUniqueDir ¶ added in v1.17.0
func CreateUniqueDir(projectsRoot, basePath, name string, perm os.FileMode) (path, folderName string, err error)
CreateUniqueDir creates a unique directory within the allowed projectsRoot. It validates that the created directory is always within projectsRoot.
func DefaultSwarmStackEnvTemplate ¶ added in v1.17.0
func DefaultSwarmStackEnvTemplate() string
func DefaultSwarmStackTemplate ¶ added in v1.17.0
func DefaultSwarmStackTemplate() string
func DetectComposeFile ¶
func DirectorySyncContentsChanged ¶ added in v1.17.2
func EnsureDefaultTemplates ¶ added in v1.17.0
func EnsureEnvFile ¶ added in v1.17.0
func EnsureTemplateDir ¶ added in v1.17.0
func GetProjectsDirectory ¶ added in v1.17.0
func GetTemplatesDirectory ¶ added in v1.17.0
func HasComposeRootKeysInFile ¶ added in v1.17.2
func ImportedComposeDescription ¶ added in v1.17.0
func IsBinaryProjectFileContent ¶ added in v1.17.2
func IsProjectDirectoryEntry ¶ added in v1.17.0
IsProjectDirectoryEntry reports whether a directory entry should be treated as a project directory. Regular directories are always accepted. Symlinked directories are accepted only when enabled.
func IsProjectDirectoryPath ¶ added in v1.17.0
IsProjectDirectoryPath reports whether an existing path should be treated as a project directory. Regular directories are always accepted. Symlinked directories are accepted only when enabled.
func IsProjectFile ¶
IsProjectFile reports whether filename is a known project file or a plausible custom YAML filename worth watching for compose discovery.
func IsSafeSubdirectory ¶ added in v1.17.0
IsSafeSubdirectory returns true if subdir is a subdirectory of baseDir (absolute, normalized)
func IsWindowsDrivePath ¶ added in v1.17.0
IsWindowsDrivePath returns true if the path looks like a Windows drive path (e.g., "C:/path")
func LoadComposeProject ¶
func LoadComposeProject(ctx context.Context, composeFile, projectName, projectsDirectory string, autoInjectEnv bool, pathMapper *PathMapper) (*composetypes.Project, error)
func LoadComposeProjectFromDir ¶
func LoadComposeProjectFromDir(ctx context.Context, dir, projectName, projectsDirectory string, autoInjectEnv bool, pathMapper *PathMapper) (*composetypes.Project, string, error)
func ParseEnvContent ¶ added in v1.17.0
ParseEnvContent parses environment variables from .env file content
func ReadFolderComposeTemplate ¶ added in v1.17.0
func ReadProjectDirectoryFiles ¶ added in v1.17.2
func ReadProjectFiles ¶ added in v1.17.0
func RemoveProjectFile ¶ added in v1.17.0
func RemoveStaleComposeFiles ¶ added in v1.17.2
func ResolveConfiguredContainerDirectory ¶ added in v1.17.0
func ResolveDirectoryIdentityInternal ¶ added in v1.17.0
func SanitizeProjectName ¶ added in v1.17.0
func SaveOrUpdateProjectFiles ¶ added in v1.17.0
func ValidateIncludePathForWrite ¶
ValidateIncludePathForWrite ensures the include path is safe for write operations Returns the validated absolute path to prevent recomputation after validation Only allows writing within the project directory
func WriteComposeFile ¶ added in v1.17.0
WriteComposeFile writes a compose file to the specified directory. It detects existing compose file names (docker-compose.yml, compose.yaml, etc.) and uses the existing name if found, otherwise defaults to compose.yaml projectsRoot is the allowed root directory to prevent path traversal attacks
func WriteEnvFile ¶ added in v1.17.0
WriteEnvFile writes a .env file to the specified directory projectsRoot is the allowed root directory to prevent path traversal attacks
func WriteFileWithPerm ¶ added in v1.17.0
WriteFileWithPerm is a generic file writer with custom permissions
func WriteIncludeFile ¶
WriteIncludeFile writes content to an include file path
func WriteProjectFile ¶ added in v1.17.0
func WriteProjectFiles ¶ added in v1.17.0
WriteProjectFiles writes both compose and env files to a project directory. An empty .env file is always created to prevent compose-go from failing when the compose file references env_file: .env projectsRoot is the allowed root directory to prevent path traversal attacks
func WriteSyncedDirectory ¶ added in v1.17.0
WriteSyncedDirectory writes multiple files to a project directory. It validates all paths are within the project directory and creates subdirectories as needed. Returns the list of written file paths.
func WriteTemplateFile ¶ added in v1.17.0
WriteTemplateFile writes a template file (like .compose.template or .env.template)
func WriteTemplateFiles ¶ added in v1.17.0
Types ¶
type ArcaneComposeMetadata ¶
type ArcaneComposeMetadata struct {
// ProjectIconURL is the URL to an icon representing the entire project.
ProjectIconURL string
// ProjectURLS are additional URLs related to the project (e.g., documentation, homepage).
ProjectURLS []string
// ServiceIcons maps service names to their respective icon identifiers or URLs.
ServiceIcons map[string]string
}
ArcaneComposeMetadata represents Arcane-specific configuration extracted from a Compose file.
func ParseArcaneComposeMetadata ¶
func ParseArcaneComposeMetadata(ctx context.Context, composeFilePath, projectsDirectory string, autoInjectEnv bool) (ArcaneComposeMetadata, error)
ParseArcaneComposeMetadata reads a Docker Compose file and extracts Arcane-specific metadata. When projectsDirectory is set, Arcane's project env loading is used so .env.global is available.
func ParseArcaneComposeMetadataWithEnv ¶
func ParseArcaneComposeMetadataWithEnv(ctx context.Context, composeFilePath string, envMap map[string]string) (ArcaneComposeMetadata, error)
ParseArcaneComposeMetadataWithEnv reads a Docker Compose file and extracts Arcane-specific metadata using a provided environment.
type DiscoveredProjectDir ¶ added in v1.17.0
func DiscoverProjectDirectories ¶ added in v1.17.0
func DiscoverProjectDirectories(root string, followSymlinks bool, maxDepth int) ([]DiscoveredProjectDir, error)
type EnvLoader ¶
type EnvLoader struct {
// contains filtered or unexported fields
}
func NewEnvLoader ¶
func (*EnvLoader) LoadEnvironment ¶
func (l *EnvLoader) LoadEnvironment(ctx context.Context) (envMap EnvMap, injectionVars EnvMap, err error)
LoadEnvironment loads and merges environment variables from all sources: 1. Process environment 2. Global .env.global file (from projects directory) 3. Project-specific .env file (from workdir)
type EnvMap ¶
func ParseProjectEnvContent ¶ added in v1.16.1
ParseProjectEnvContent parses project .env content from a string with variable expansion.
func ParseProjectEnvFile ¶ added in v1.16.1
ParseProjectEnvFile parses a project .env file with variable expansion using the provided context map (e.g. process env). Returns nil without error when the file does not exist. Only the specified file is read — global env files are intentionally not loaded here.
type IncludeFile ¶
type IncludeFile struct {
Path string `json:"path"`
RelativePath string `json:"relative_path"`
Content string `json:"content"`
}
func ParseIncludes ¶
func ParseIncludes(composeFilePath string, envMap EnvMap, includeContent bool) ([]IncludeFile, error)
ParseIncludes reads a compose file and extracts all include directives. envMap is used to expand variables (e.g., ${VAR}) in include paths.
type PathMapper ¶ added in v1.17.0
type PathMapper struct {
// contains filtered or unexported fields
}
PathMapper handles translation between container and host paths
func NewPathMapper ¶ added in v1.17.0
func NewPathMapper(containerDir, hostDir string) *PathMapper
NewPathMapper creates a new path mapper
func (*PathMapper) ContainerToHost ¶ added in v1.17.0
func (pm *PathMapper) ContainerToHost(containerPath string) (string, error)
ContainerToHost translates a container path to host path
func (*PathMapper) IsNonMatchingMount ¶ added in v1.17.0
func (pm *PathMapper) IsNonMatchingMount() bool
func (*PathMapper) TranslateVolumeSources ¶ added in v1.17.0
func (pm *PathMapper) TranslateVolumeSources(project *composetypes.Project) error
TranslateVolumeSources translates all bind mount sources in a compose project
type ProgressWriterKey ¶
type ProgressWriterKey struct{}
ProgressWriterKey can be set on a context to enable JSON-line progress updates. The value must be an io.Writer (typically the HTTP response writer).
type ProjectEnvMode ¶ added in v1.16.3
type ProjectEnvMode string
const ( ProjectEnvModeDirect ProjectEnvMode = "direct" ProjectEnvModeOverride ProjectEnvMode = "override" )
type ProjectEnvState ¶ added in v1.16.3
type ProjectEnvState struct {
Mode ProjectEnvMode
EditableFileName string
EditableContent string
EffectiveContent string
DirectContent string
HasEffective bool
GitContent string
HasGitSource bool
OverrideContent string
HasOverride bool
}
func ReadProjectEnvState ¶ added in v1.16.3
func ReadProjectEnvState(projectPath string) (ProjectEnvState, error)