Documentation
¶
Overview ¶
Package shared contiene utilidades y helpers para operaciones comunes en los pipelines. shared/cloner.go
Package shared contiene utilidades y helpers para operaciones comunes en los pipelines. shared/https_cloner.go
Package shared provides shared functionality for pipeline implementations.
Index ¶
- func CloneRepo(ctx context.Context, client *dagger.Client, opts GitCloneOpts, protocol string) (*dagger.Directory, error)
- func GenerateTag(ctx context.Context, client *dagger.Client, src *dagger.Directory) (string, error)
- func RunTestsWithCoverage(ctx context.Context, client *dagger.Client, src *dagger.Directory, ...) error
- func ValidateRequiredSecrets(operation string) error
- type CloneOptions
- type Cloner
- type CredentialSource
- type DockerDeployer
- type GitCloneOpts
- type GitCredentials
- type GoBuilder
- type HTTPSCloner
- type RepoCloner
- type SSHCloner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CloneRepo ¶
func CloneRepo(ctx context.Context, client *dagger.Client, opts GitCloneOpts, protocol string) (*dagger.Directory, error)
CloneRepo es una función helper que usa el clonador por defecto
func GenerateTag ¶
GenerateTag generates a tag and saves it on the host as .tag_name. It prioritizes the TAG_NAME environment variable; otherwise, it uses `git rev-parse --short HEAD` to generate the tag.
Parameters:
- ctx: The context for managing execution.
- client: The Dagger client used to execute pipeline operations.
- src: A pointer to a Dagger directory representing the source repository.
Returns:
- A string representing the generated tag.
- An error if the tag generation or saving process fails.
func RunTestsWithCoverage ¶
func RunTestsWithCoverage(ctx context.Context, client *dagger.Client, src *dagger.Directory, coverage float64, goVersion string) error
RunTestsWithCoverage runs the tests for the project with coverage.
Parameters:
- ctx: The context for managing execution.
- client: The Dagger client used for container operations.
- src: The source directory of the cloned repository.
- coverage: The coverage threshold for the tests.
- goVersion: The Go version to use for testing (e.g., "1.26.7").
Returns:
- An error if the tests fail, otherwise nil.
func ValidateRequiredSecrets ¶
ValidateRequiredSecrets validates that required secrets exist for the given operation. Operations like "push" require authentication, while "clone" might work with anonymous access.
Types ¶
type CloneOptions ¶
type CloneOptions struct {
// Timeout is the maximum time allowed for cloning
Timeout time.Duration
// MaxRetries is the maximum number of retries
MaxRetries int
// RetryDelay is the time between retries
RetryDelay time.Duration
// ShallowClone indicates whether a shallow clone should be done
ShallowClone bool
// Depth is the depth of the clone if it's shallow
Depth int
}
CloneOptions configures the behavior of cloning
func DefaultCloneOptions ¶
func DefaultCloneOptions() CloneOptions
DefaultCloneOptions returns the default options
type Cloner ¶
type Cloner interface {
Clone(ctx context.Context, client *dagger.Client, opts GitCloneOpts) (*dagger.Directory, error)
}
Cloner define la interfaz para clonar repositorios
type CredentialSource ¶
type CredentialSource string
CredentialSource indica de dónde vienen las credenciales
const ( SourceCI CredentialSource = "CI" SourcePAT CredentialSource = "PAT" SourceSSH CredentialSource = "SSH" SourceAnonymous CredentialSource = "ANONYMOUS" )
type DockerDeployer ¶
type DockerDeployer struct {
Client *dagger.Client
ImageName string // ejemplo: registry.gitlab.com/mi-org/mi-proyecto/servicio
Source *dagger.Directory // directorio con Dockerfile
RegistryUser string // normalmente "gitlab-ci-token"
RegistryPass *dagger.Secret // CI_JOB_TOKEN o GITLAB_PAT como secreto
Tag string // ejemplo: "latest", "v1.2.3", "sha"
}
DockerDeployer encapsula la lógica para construir y publicar una imagen Docker.
func NewDockerDeployer ¶
func NewDockerDeployer(client *dagger.Client, imageName string, src *dagger.Directory, tag, user, pass string) *DockerDeployer
NewDockerDeployer crea una instancia del deployer, asegurando que la contraseña se maneje como secreto.
func (*DockerDeployer) BuildAndPush ¶
func (d *DockerDeployer) BuildAndPush(ctx context.Context) error
BuildAndPush construye la imagen y la publica en la registry.
type GitCloneOpts ¶
type GitCloneOpts struct {
Repo string // URL del repositorio
Branch string // Rama a clonar
Name string // Nombre del directorio destino
UserEmail string // Email del usuario Git
UserName string // Nombre del usuario Git
SSHKey string // Clave SSH (opcional)
}
GitCloneOpts contiene las opciones para clonar un repositorio
type GitCredentials ¶
GitCredentials representa las credenciales para autenticación Git
func ResolveGitCredentials ¶
func ResolveGitCredentials() (*GitCredentials, error)
ResolveGitCredentials intenta obtener credenciales de múltiples fuentes
func (*GitCredentials) String ¶
func (c *GitCredentials) String() string
String implementa fmt.Stringer para logging seguro
func (*GitCredentials) Validate ¶
func (c *GitCredentials) Validate() error
Validate verifica si las credenciales son válidas.
type GoBuilder ¶
type GoBuilder struct {
Client *dagger.Client
Source *dagger.Directory
GoModCache *dagger.CacheVolume
GoBuildCache *dagger.CacheVolume
GoVersion string
}
GoBuilder encapsulates the logic for building Go binaries.
Fields:
- Client: The Dagger client used to execute pipeline operations.
- Source: The source directory containing the Go project files.
- GoModCache: The cache volume for Go modules.
- GoBuildCache: The cache volume for Go build artifacts.
- GoVersion: The configurable version of Go to use for the build.
Note: Dagger handles connection management internally. The client should be created once at the application level and reused throughout the pipeline.
func NewGoBuilder ¶
NewGoBuilder creates a new instance of GoBuilder.
Parameters:
- client: The Dagger client used for pipeline operations. Must be a valid, connected client. Connection management is handled by Dagger internally.
- src: The source directory containing the Go project files.
- version: The Go version to use for the build (e.g., "1.21", "1.26.7").
Returns:
- A pointer to a new GoBuilder instance.
func (*GoBuilder) Build ¶
func (b *GoBuilder) Build(ctx context.Context, outPath string, target string, env map[string]string) (string, error)
Build compiles the Go binary based on the provided parameters.
This method uses Dagger's immutable API to build a container, compile the Go binary, and export it to the host filesystem. Dagger handles connection management internally, so no manual reconnection logic is needed.
Parameters:
- ctx: The context for managing execution and cancellation.
- outPath: The output path where the compiled binary will be exported.
- target: The name of the output binary file.
- env: A map of custom environment variables to set during the build.
Returns:
- A string representing the path to the exported binary (same as outPath).
- An error if the build process fails. Errors are propagated from Dagger and may include connection issues, build failures, or export errors.
type HTTPSCloner ¶
type HTTPSCloner struct {
// contains filtered or unexported fields
}
func NewHTTPSCloner ¶
func NewHTTPSCloner(opts ...CloneOptions) *HTTPSCloner
NewHTTPSCloner creates a new HTTPS cloner with custom options
type RepoCloner ¶
type RepoCloner interface {
Clone(ctx context.Context, client *dagger.Client, opts GitCloneOpts) (*dagger.Directory, error)
}
RepoCloner interface allows multiple auth modes.