usecase

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultCommonProjectPath = "common"

DefaultCommonProjectPath 는 공용 프로젝트의 기본 경로다.

GitLab 의 Container/Package Registry 는 프로젝트 종속이라, 조직 공용 베이스 이미지와 npm/maven 패키지를 두려면 그것을 소유할 프로젝트가 하나 필요하다. 이름은 조직 관례에 따라 바꿀 수 있다.

View Source
const DeployTokenVariable = scaffold.DeployTokenVar

DeployTokenVariable 은 CI 의 deploy 단계가 매니페스트를 되쓸 때 쓰는 변수다. 렌더러가 만드는 스크립트와 이름이 같아야 한다.

Variables

View Source
var (
	ErrStackNotFound    = errors.New("referenced stack does not exist")
	ErrStackOrgMismatch = errors.New("stack belongs to a different organization")
)

Sentinel errors for cross-context validation.

Functions

func BuildStepPlan

func BuildStepPlan(pipeline *domain.Pipeline, manifestTypes ...[]string) []string

func OTLPEndpointFor

func OTLPEndpointFor(ctx context.Context, reader port.StackReader, stackID string) string

OTLPEndpointFor 는 배포되는 앱에 넣어 줄 수집기 주소를 찾는다.

배포 경로가 둘이라(파이프라인 배포, 직접 배포) 각자 구현하면 한쪽만 고쳐져 "어떤 경로로 배포했느냐에 따라 추적이 되기도 하고 안 되기도 하는" 상태가 된다. 그래서 판단을 여기 하나로 모은다.

조회에 실패하거나 스택에 수집기가 없으면 빈 값을 돌려준다. 관측은 부가 기능이고, 그것 때문에 배포가 실패하면 더 나쁘다. 빈 값이면 호출부가 관련 환경변수를 아예 넣지 않는다 — 닿지 않는 주소를 박으면 앱이 영원히 재시도한다.

Types

type CreatePipeline

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

CreatePipeline creates a new pipeline configuration.

func NewCreatePipeline

func NewCreatePipeline(
	pipelineRepo port.PipelineRepository,
	templateRepo port.PipelineTemplateRepository,
	stackReader ...port.StackReader,
) *CreatePipeline

NewCreatePipeline constructs a CreatePipeline use case.

func (*CreatePipeline) Execute

Execute creates a new pipeline.

func (*CreatePipeline) WithRepositoryProvisioner

func (uc *CreatePipeline) WithRepositoryProvisioner(p RepositoryProvisioner) *CreatePipeline

WithRepositoryProvisioner 는 저장소 프로비저닝 기능을 켠다.

주입하지 않으면 ProvisionRepository 요청이 오류가 된다 — 조용히 무시하면 사용자는 저장소가 만들어진 줄 알고 기다리게 된다.

type CreatePipelineInput

type CreatePipelineInput struct {
	Name           string
	ExecutionMode  string
	TemplateID     string
	OrgID          string
	ClusterID      string
	StackID        string // optional — links pipeline to a stack
	Namespace      string
	AppType        domain.AppType
	GitRepoURL     string
	DockerfilePath string
	DockerContext  string
	EnvVars        map[string]string
	// ProvisionRepository 가 true 면 앱 저장소를 만들고 스캐폴딩을 커밋한 뒤
	// Argo CD Application 까지 연결한다. StackID 가 필요하다.
	ProvisionRepository bool
	// RequestedByEmail 은 요청한 사람의 이메일이다. 저장소가 든 조직의 멤버로
	// 넣는 데 쓴다 — 넣지 않으면 자기 저장소를 보지도 못한다.
	RequestedByEmail string
	// Port / Replicas 는 스캐폴딩 매니페스트에 반영된다.
	Port     int32
	Replicas int32
	// RegistryCredentials 는 외부 레지스트리 자격증명이다.
	RegistryCredentials map[string]string
}

CreatePipelineInput holds the parameters for creating a new pipeline.

type CreatePipelineOutput

type CreatePipelineOutput struct {
	Pipeline     *domain.Pipeline
	StackWarning string `json:"stack_warning,omitempty"` // non-empty when stack exists but is not completed

	// 아래는 저장소 프로비저닝을 수행했을 때만 채워진다.
	RepositoryPath         string   `json:"repository_path,omitempty"`
	ArgoApplicationCreated bool     `json:"argo_application_created,omitempty"`
	MissingVariables       []string `json:"missing_variables,omitempty"`
	Warnings               []string `json:"warnings,omitempty"`
	// ScaffoldSkipped 는 이미 있던 저장소라 스캐폴딩을 쓰지 않았음을 알린다.
	// 사용자가 파일이 갱신됐다고 오해하면 배포되지 않는 원인을 엉뚱한 데서 찾는다.
	ScaffoldSkipped bool `json:"scaffold_skipped,omitempty"`
}

CreatePipelineOutput holds the result of creating a pipeline.

type DeletePipeline

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

DeletePipeline 은 파이프라인과, 사용자가 고른 부수 리소스를 지운다.

func NewDeletePipeline

func NewDeletePipeline(
	pipelines port.PipelineRepository,
	factory port.SCMBundleFactory,
	kubeconfig port.KubeconfigProvider,
) *DeletePipeline

func (*DeletePipeline) Execute

Execute 는 고른 리소스를 지운 뒤 파이프라인 레코드를 지운다.

순서가 중요하다. 레코드를 먼저 지우면 저장소 경로·클러스터·네임스페이스를 잃어 남은 리소스를 찾을 방법이 없어진다.

요청한 삭제가 하나라도 실패하면 레코드를 남기고 오류를 돌려준다. 레코드가 사라지면 사용자는 목록에서 파이프라인을 못 보는데 리소스는 남아 있어, 다시 시도할 방법조차 없어지기 때문이다.

func (*DeletePipeline) WithWorkloadDeleter

func (uc *DeletePipeline) WithWorkloadDeleter(d port.WorkloadDeleter) *DeletePipeline

WithWorkloadDeleter 는 직접 배포 워크로드 정리 경로를 배선한다.

type DeletePipelineInput

type DeletePipelineInput struct {
	PipelineID string
	// DeleteClusterResources 는 Argo CD Application 과 그것이 배포한 워크로드를 지운다.
	DeleteClusterResources bool
	// DeleteRepository 는 소스 저장소를 지운다. 되돌릴 수 없다.
	DeleteRepository bool
	// DeleteImages 는 레지스트리의 이미지 저장소를 지운다.
	DeleteImages bool
}

DeletePipelineInput 은 무엇까지 지울지 고른 결과다.

셋 다 기본값 false 다. 파이프라인 레코드만 지우는 것이 종전 동작이고, 그보다 파괴적인 일은 사용자가 명시적으로 골라야 한다.

type DeletePipelineOutput

type DeletePipelineOutput struct {
	ClusterResourcesDeleted bool
	RepositoryDeleted       bool
	ImagesDeleted           bool
	Warnings                []string
}

DeletePipelineOutput 은 실제로 무엇이 지워졌는지 알린다.

요청과 결과를 따로 두는 이유는, 지원하지 않는 레지스트리처럼 요청은 했지만 수행하지 못한 경우가 있기 때문이다. 요청만 보고 "지워졌다" 고 표시하면 사용자는 남아 있는 리소스를 영영 모른다.

type DeployOption

type DeployOption func(*DeployPipeline)

func WithBuildDelegate

func WithBuildDelegate(d port.BuildDelegate) DeployOption

WithBuildDelegate 는 러너 위임 경로를 배선한다.

배선되지 않으면 위임 대상 파이프라인의 배포는 오류로 끝난다. 조용히 직접 빌드로 되돌리지 않는다 — API 파드에는 도커 데몬이 없어 그 경로는 실패할 수 없는 경로이고, 되돌리면 사용자는 왜 실패했는지 알 수 없다.

func WithClusterTargetProvider

func WithClusterTargetProvider(p port.ClusterTargetProvider) DeployOption

func WithDeployTimeout

func WithDeployTimeout(d time.Duration) DeployOption

WithDeployTimeout 은 배포 한 번의 상한을 바꾼다. 0 이하면 기본값을 쓴다.

func WithImagePreparer

func WithImagePreparer(p port.ImagePreparer) DeployOption

func WithStackReader

func WithStackReader(r port.StackReader) DeployOption

WithStackReader 는 스택 요약 조회를 배선한다. 배선되지 않으면 배포는 그대로 되고 추적 환경변수만 빠진다 — 관측 배선 때문에 배포가 막히면 안 된다.

type DeployPipeline

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

func NewDeployPipeline

func NewDeployPipeline(
	pipelineRepo port.PipelineRepository,
	deploymentRepo port.DeploymentRepository,
	kubeconfigProvider port.KubeconfigProvider,
	applier port.ManifestApplier,
	opts ...DeployOption,
) *DeployPipeline

func (*DeployPipeline) ApplyAsync

func (uc *DeployPipeline) ApplyAsync(deploymentID string, manifestTypes ...[]string)

ApplyAsync runs the actual K8s deployment in the background.

func (*DeployPipeline) Execute

Execute runs the full synchronous flow (for tests and backward compat).

func (*DeployPipeline) Start

Start creates a Deployment record with status=running and returns immediately.

type DeployPipelineInput

type DeployPipelineInput struct {
	PipelineID    string
	Version       string
	DeployedBy    string
	ManifestTypes []string
}

type DeployPipelineOutput

type DeployPipelineOutput struct {
	Deployment *domain.Deployment
}

type ListPipelines

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

ListPipelines lists all pipelines for an organization.

func NewListPipelines

func NewListPipelines(pipelineRepo port.PipelineRepository) *ListPipelines

NewListPipelines constructs a ListPipelines use case.

func (*ListPipelines) Execute

Execute returns all pipelines for the given organization. When StackID is set, results are filtered to that stack via the dedicated repo method.

type ListPipelinesInput

type ListPipelinesInput struct {
	OrgID   string
	StackID string // optional — filters to pipelines linked to this stack
}

ListPipelinesInput holds the parameters for listing pipelines.

type ListPipelinesOutput

type ListPipelinesOutput struct {
	Pipelines []*domain.Pipeline
}

ListPipelinesOutput holds the result of listing pipelines.

type ProvisionAppProject

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

ProvisionAppProject 는 앱 저장소를 만들고 CI/CD 가 돌 수 있는 상태로 만든다.

소스와 배포 매니페스트가 한 저장소에 함께 산다. CI 가 이미지를 올린 뒤 deploy/ 의 태그를 갱신해 커밋하면 Argo CD 가 그 커밋을 보고 배포한다.

func NewProvisionAppProject

func NewProvisionAppProject(
	scm port.SCMProvisioner,
	pipeline port.PipelineConfigurator,
	registry port.ImageRegistryResolver,
) *ProvisionAppProject

NewProvisionAppProject 는 유스케이스를 만든다.

func (*ProvisionAppProject) Execute

Execute 는 프로젝트 생성 → 이미지 대상 결정 → 스캐폴딩 커밋 → CI 변수 등록을 수행한다.

func (*ProvisionAppProject) WithCIJobs

func (uc *ProvisionAppProject) WithCIJobs(
	jobs port.CIJobProvisioner,
	webhooks port.SCMWebhookProvisioner,
	ciBaseURL, scmURL string,
) *ProvisionAppProject

WithCIJobs 는 CI 서버 job 생성 경로를 배선한다.

Jenkins 처럼 job 이 먼저 존재해야 하는 CI 를 위한 것이다. 배선하지 않으면 job 생성을 건너뛴다 — 리포와 스캐폴딩은 만들어지되 빌드는 돌지 않는다.

func (*ProvisionAppProject) WithCredentialPlane

func (uc *ProvisionAppProject) WithCredentialPlane(plane port.PipelineCredentialPlane) *ProvisionAppProject

WithCredentialPlane 은 CI 변수 저장소가 없는 SCM 의 자격증명 경로를 배선한다.

type ProvisionAppProjectInput

type ProvisionAppProjectInput struct {
	AppName   string
	GroupPath string
	GroupID   string
	// Namespace 는 배포 대상 쿠버네티스 네임스페이스다.
	Namespace string
	Port      int32
	Replicas  int32
	// RepoAccessToken 은 저장소 쓰기에 쓸 토큰이다.
	//
	// 플랫폼이 프로젝트 범위 토큰을 지원하지 않을 때 채워진다(Gitea·GitHub).
	// deploy 단계가 매니페스트 태그를 되쓰려면 필요하다.
	RepoAccessToken string
	// RegistryCredentials 는 외부 레지스트리 자격증명이다.
	// SCM 프로젝트 레지스트리를 쓰는 구성에서는 필요 없다.
	RegistryCredentials map[string]string
	// Platform 은 파이프라인 파일 형식과 토큰 확보 경로를 정한다.
	// 비면 GitLab 으로 본다.
	Platform port.SCMPlatform
	// SharedAccessToken 은 리포 범위 토큰을 발급할 수 없는 플랫폼에서
	// Argo CD 인증에 재사용할 토큰이다 (GitHub 의 조직 PAT).
	SharedAccessToken string
	// AppType 은 어떤 앱을 스캐폴딩할지다. web 이면 바로 도는 React 앱을 만든다.
	AppType domain.AppType
	// AccessDomain / GatewayName / GatewayNamespace 가 있으면
	// 외부 접근용 HTTPRoute 도 스캐폴딩에 포함한다.
	AccessDomain     string
	GatewayName      string
	GatewayNamespace string
	// StackID 는 배포 매니페스트에 스택 라벨로 실린다. 클러스터에서 워크로드가
	// 어느 스택 소속인지 판별하는 유일한 키다.
	StackID string
	// TemplateID 는 배포 매니페스트에 템플릿 라벨로 실린다.
	// 템플릿별 자원 사용 비교나 템플릿 단위 조회에 쓴다.
	TemplateID string
}

ProvisionAppProjectInput 은 애플리케이션 프로젝트 프로비저닝 요청이다.

type ProvisionAppProjectOutput

type ProvisionAppProjectOutput struct {
	Project     *port.SCMProject
	ImageTarget *port.ImageTarget
	// ArgoReadToken 은 Argo CD 가 저장소를 읽는 데 쓸 토큰이다.
	// 발급에 실패하면 비어 있고 Warnings 에 사유가 담긴다.
	ArgoReadToken string
	// MissingVariables 는 파이프라인이 돌기 전에 사람이 채워야 할 변수다.
	MissingVariables []string
	// Warnings 는 치명적이지 않지만 알려야 하는 문제다.
	Warnings []string
	// ScaffoldSkipped 는 이미 있던 저장소라 스캐폴딩을 쓰지 않았음을 알린다.
	ScaffoldSkipped bool
	// CIJobURL 은 만들어진 CI job 의 주소다. CI 가 SCM 과 분리된 플랫폼
	// (Jenkins)에서만 채워진다.
	CIJobURL string
	// CredentialManifests 는 파이프라인 자격증명 ExternalSecret 이다.
	//
	// 여기서 적용하지 않는다 — 클러스터 접근은 상위 유스케이스가 한곳에서
	// 맡는다(Argo CD 리소스와 같은 경로로 적용된다).
	CredentialManifests []string
}

ProvisionAppProjectOutput 은 프로비저닝 결과다.

type ProvisionCommonProject

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

ProvisionCommonProject 는 조직 그룹과 공용 프로젝트를 보장한다.

func NewProvisionCommonProject

func NewProvisionCommonProject(scm port.SCMProvisioner) *ProvisionCommonProject

NewProvisionCommonProject 는 유스케이스를 만든다.

func (*ProvisionCommonProject) Execute

Execute 는 그룹 → 공용 프로젝트 → 사용 안내 문서 순으로 보장한다.

모든 단계가 멱등하므로 스택 설치가 재시도돼도 안전하다.

type ProvisionCommonProjectInput

type ProvisionCommonProjectInput struct {
	// GroupPath 는 조직 그룹 경로다 (예: "acme").
	GroupPath string
	// GroupName 은 그룹 표시 이름이다. 비면 GroupPath 를 쓴다.
	GroupName string
	// ProjectPath 는 공용 프로젝트 경로다. 비면 DefaultCommonProjectPath.
	ProjectPath string
	// Platform 은 안내 문서에 적을 패키지 레지스트리 주소 형식을 정한다.
	// 비면 GitLab 으로 본다.
	Platform port.SCMPlatform
}

ProvisionCommonProjectInput 은 공용 프로젝트 프로비저닝 요청이다.

type ProvisionCommonProjectOutput

type ProvisionCommonProjectOutput struct {
	Group   *port.SCMGroup
	Project *port.SCMProject
	// DocsSkipped 는 이미 있던 프로젝트라 README 를 쓰지 않았음을 알린다.
	DocsSkipped bool
}

ProvisionCommonProjectOutput 은 프로비저닝 결과다.

type ProvisionPipelineRepository

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

ProvisionPipelineRepository 는 파이프라인 하나가 돌기 위한 저장소 일체를 만든다.

공용 프로젝트 → 앱 프로젝트 + 스캐폴딩 → Argo CD Application 순이다. 앞 단계 결과가 뒷 단계 입력이므로 순서가 고정되어 있다.

func NewProvisionPipelineRepository

func NewProvisionPipelineRepository(
	factory port.SCMBundleFactory,
	applier port.ManifestApplier,
	kubeconfig port.KubeconfigProvider,
) *ProvisionPipelineRepository

NewProvisionPipelineRepository 는 유스케이스를 만든다.

func (*ProvisionPipelineRepository) Execute

Execute 는 저장소를 만들고 Argo CD 가 바라보게 한다.

type ProvisionPipelineRepositoryInput

type ProvisionPipelineRepositoryInput struct {
	AppName string
	StackID string
	// TemplateID 는 배포 매니페스트에 템플릿 라벨로 실린다. 비면 라벨을 붙이지 않는다.
	TemplateID string
	// AppType 은 어떤 앱을 스캐폴딩할지다. web 이면 React 앱을 만든다.
	AppType domain.AppType
	// RequestedByEmail 은 파이프라인을 만든 사람의 이메일이다.
	// 저장소를 담은 조직의 멤버로 넣는 데 쓴다. 비면 건너뛴다.
	RequestedByEmail string
	// Namespace 는 배포 대상 쿠버네티스 네임스페이스다.
	Namespace string
	Port      int32
	Replicas  int32
	// CommonProjectPath 는 공용 프로젝트 경로다. 비면 기본값.
	CommonProjectPath string
	// RegistryCredentials 는 외부 레지스트리 자격증명이다.
	RegistryCredentials map[string]string
}

ProvisionPipelineRepositoryInput 은 파이프라인용 저장소 준비 요청이다.

type ProvisionPipelineRepositoryOutput

type ProvisionPipelineRepositoryOutput struct {
	CommonProject *port.SCMProject
	Project       *port.SCMProject
	// RepoURL / ImageRepository 는 파이프라인 레코드에 남길 값이다.
	RepoURL         string
	ImageRepository string

	ArgoApplicationCreated bool
	MissingVariables       []string
	Warnings               []string
	// ScaffoldSkipped 는 이미 있던 저장소라 스캐폴딩을 쓰지 않았음을 알린다.
	ScaffoldSkipped bool
}

ProvisionPipelineRepositoryOutput 은 준비 결과다.

type RepositoryProvisioner

type RepositoryProvisioner interface {
	Execute(ctx context.Context, input ProvisionPipelineRepositoryInput) (*ProvisionPipelineRepositoryOutput, error)
}

RepositoryProvisioner 는 파이프라인용 저장소 일체를 준비한다.

유스케이스끼리 직접 묶지 않고 인터페이스로 받는다 — 배선되지 않은 환경에서도 CreatePipeline 이 그대로 동작해야 한다.

type SyncPipelineRuns

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

SyncPipelineRuns 는 CI 서버의 빌드 이력을 배포 기록으로 들인다.

GitOps 경로에서는 플랫폼이 배포를 실행하지 않는다 — CI 가 빌드하고 Argo CD 가 동기화한다. 그래서 실행 기록이 CI 서버에만 있고, 들이지 않으면 빌드가 성공해도 화면의 실행 통계가 영원히 0 으로 남는다.

멱등하다. 배포 ID 를 job 과 빌드 번호에서 만들어, 같은 빌드를 여러 번 동기화해도 기록이 늘지 않고 상태만 갱신된다(실행 중 → 성공).

func NewSyncPipelineRuns

func NewSyncPipelineRuns(builds port.CIBuildReader, deployments port.DeploymentRepository) *SyncPipelineRuns

NewSyncPipelineRuns 는 SyncPipelineRuns 를 만든다.

func (*SyncPipelineRuns) Execute

func (uc *SyncPipelineRuns) Execute(ctx context.Context, input SyncPipelineRunsInput) (int, error)

Execute 는 최근 빌드를 읽어 배포 기록으로 반영한다.

func (*SyncPipelineRuns) ForPipeline

func (uc *SyncPipelineRuns) ForPipeline(ctx context.Context, pipelineID string) (int, error)

ForPipeline 은 파이프라인 하나의 실행 기록을 들인다.

CI 가 배선되지 않은 파이프라인(GitLab CI·GitHub Actions)은 조용히 건너뛴다 — 그쪽 실행 기록을 들이는 경로는 아직 없다.

func (*SyncPipelineRuns) WithBundleFactory

func (uc *SyncPipelineRuns) WithBundleFactory(
	factory port.SCMBundleFactory,
	pipelines port.PipelineRepository,
) *SyncPipelineRuns

WithBundleFactory 는 파이프라인마다 CI 서버를 찾아 쓰도록 배선한다.

CI 서버는 스택마다 따로 서므로 기동 시점에 하나로 고정할 수 없다.

type SyncPipelineRunsInput

type SyncPipelineRunsInput struct {
	PipelineID string
	JobName    string
	Branch     string
	Limit      int
}

SyncPipelineRunsInput 은 어느 job 의 어느 브랜치를 들일지다.

Jump to

Keyboard shortcuts

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