Help us shape the future of Go! Take the 2026 Go Developer Survey

migration

package
v0.130.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package migration converts legacy repository checkouts to the current mirror-and-artifact layout during startup. It reuses the existing Git objects and removes old working-tree files only when they are no longer used.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupRepoLeftovers

func CleanupRepoLeftovers(
	ctx context.Context,
	log *slog.Logger,
	tracker *LeftoverTracker,
	contexts *docker.ContextRegistry,
	dataMountSource string,
	dataMountDestination string,
	repoDir string,
) error

CleanupRepoLeftovers removes legacy on-disk leftovers for a single already-migrated repository directory (repoDir), unless they are still bind-mounted by a running container in any configured Docker context. It is safe to call after every deployment/destroy of repoDir: repositories that were never on the legacy layout, or that have no leftovers, return after at most a single directory read - and, once tracker has recorded repoDir as clean, without any filesystem or Docker access at all.

Unlike Run/RunWithContexts, it does not walk the whole data mount point and does not acquire its own GC lock - callers must already hold at least a shared GC lock on repoDir for the duration of the call (e.g. the deployment pipeline's own stage-1 lock), which already excludes a concurrent GC sweep from touching the same directory.

func MigrateRepository

func MigrateRepository(
	ctx context.Context,
	log *slog.Logger,
	contexts *docker.ContextRegistry,
	dataMountSource string,
	dataMountDestination string,
	repoDir string,
) (bool, error)

MigrateRepository attempts a one-off, single-repository migration of repoDir from the legacy checkout layout to the current mirror-and-artifact store layout, applying the same rules and running-container safety checks as RunWithContexts.

It exists for callers that discover, at deployment time, that repoDir still has an un-migrated legacy ".git" checkout - typically because a startup migration pass deferred it while an old container using the legacy layout was still running, and no doco-cd restart has happened since. Without this, a caller that only checks for the store layout (e.g. GitStore's mirror clone) would otherwise clone a fresh, independent mirror alongside the un-migrated legacy content instead of replacing it.

It reports whether repoDir is usable by the current store after the call. A repository without a valid legacy checkout is usable even if its mirror does not exist yet or a previous clone left an incomplete directory behind: GitStore owns creating or repairing that state. false means a valid legacy checkout is still present and could not be migrated.

Like CleanupRepoLeftovers, it does not acquire its own GC lock - callers must already hold at least a shared GC lock on repoDir for the duration of the call. Unlike CleanupRepoLeftovers, it does perform the mirror bootstrap itself when safe to do so; migrateRepo takes GitStore's own mirror path lock before inspecting or changing migration state, so it can never race another migration or a concurrent GitStore clone/fetch/publish for the same repository.

func Run

func Run(ctx context.Context, log *slog.Logger, apiClient client.APIClient, dataMountDestination string) error

Run migrates legacy repositories below dataMountDestination in place. It is safe to call on every startup and leaves current stores and unrelated directories untouched. Per-repository failures are logged and do not stop the migration pass or application startup.

func RunWithContexts

func RunWithContexts(
	ctx context.Context,
	log *slog.Logger,
	contexts *docker.ContextRegistry,
	dataMountSource string,
	dataMountDestination string,
) error

RunWithContexts migrates legacy repositories while checking every configured Docker context before removing old working-tree files. Both mount paths are checked because deployment labels contain daemon-visible host paths. Discovery failures leave the files untouched.

Types

type LeftoverTracker

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

LeftoverTracker remembers, for the lifetime of the process, which repository directories are already known to be free of legacy leftovers, so CleanupRepoLeftovers can skip redundant checks for them. A repository can never regain a legacy on-disk layout once migrated, so a "clean" entry stays valid forever; the map only grows bounded by the number of distinct repository directories ever deployed.

func NewLeftoverTracker

func NewLeftoverTracker() *LeftoverTracker

NewLeftoverTracker creates an empty LeftoverTracker.

Jump to

Keyboard shortcuts

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