mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
98 lines
3.9 KiB
Go
98 lines
3.9 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
"github.com/hanzoai/cd/reposerver/apiclient"
|
|
"github.com/hanzoai/cd/util/db"
|
|
utilio "github.com/hanzoai/cd/util/io"
|
|
)
|
|
|
|
type argoCDService struct {
|
|
getRepository func(ctx context.Context, url, project string) (*v1alpha1.Repository, error)
|
|
submoduleEnabled bool
|
|
newFileGlobbingEnabled bool
|
|
getGitFilesFromRepoServer func(ctx context.Context, req *apiclient.GitFilesRequest) (*apiclient.GitFilesResponse, error)
|
|
getGitDirectoriesFromRepoServer func(ctx context.Context, req *apiclient.GitDirectoriesRequest) (*apiclient.GitDirectoriesResponse, error)
|
|
}
|
|
|
|
type Repos interface {
|
|
// GetFiles returns content of files (not directories) within the target repo
|
|
GetFiles(ctx context.Context, repoURL, revision, project, pattern string, noRevisionCache bool, sourceIntegrity *v1alpha1.SourceIntegrity) (map[string][]byte, error)
|
|
|
|
// GetDirectories returns a list of directories (not files) within the target repo
|
|
GetDirectories(ctx context.Context, repoURL, revision, project string, noRevisionCache bool, sourceIntegrity *v1alpha1.SourceIntegrity) ([]string, error)
|
|
}
|
|
|
|
func NewArgoCDService(db db.DB, submoduleEnabled bool, repoClientset apiclient.Clientset, newFileGlobbingEnabled bool) Repos {
|
|
return &argoCDService{
|
|
getRepository: db.GetRepository,
|
|
submoduleEnabled: submoduleEnabled,
|
|
newFileGlobbingEnabled: newFileGlobbingEnabled,
|
|
getGitFilesFromRepoServer: func(ctx context.Context, fileRequest *apiclient.GitFilesRequest) (*apiclient.GitFilesResponse, error) {
|
|
closer, client, err := repoClientset.NewRepoServerClient()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error initializing new repo server client: %w", err)
|
|
}
|
|
defer utilio.Close(closer)
|
|
return client.GetGitFiles(ctx, fileRequest)
|
|
},
|
|
getGitDirectoriesFromRepoServer: func(ctx context.Context, dirRequest *apiclient.GitDirectoriesRequest) (*apiclient.GitDirectoriesResponse, error) {
|
|
closer, client, err := repoClientset.NewRepoServerClient()
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error initialising new repo server client: %w", err)
|
|
}
|
|
defer utilio.Close(closer)
|
|
return client.GetGitDirectories(ctx, dirRequest)
|
|
},
|
|
}
|
|
}
|
|
|
|
func (a *argoCDService) GetFiles(ctx context.Context, repoURL, revision, project, pattern string, noRevisionCache bool, sourceIntegrity *v1alpha1.SourceIntegrity) (map[string][]byte, error) {
|
|
repo, err := a.getRepository(ctx, repoURL, project)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error in GetRepository: %w", err)
|
|
}
|
|
|
|
fileRequest := &apiclient.GitFilesRequest{
|
|
Repo: repo,
|
|
SubmoduleEnabled: a.submoduleEnabled,
|
|
Revision: revision,
|
|
Path: pattern,
|
|
NewGitFileGlobbingEnabled: a.newFileGlobbingEnabled,
|
|
NoRevisionCache: noRevisionCache,
|
|
SourceIntegrity: sourceIntegrity,
|
|
VerifyCommit: sourceIntegrity != nil, // nolint:staticcheck
|
|
}
|
|
|
|
fileResponse, err := a.getGitFilesFromRepoServer(ctx, fileRequest)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error retrieving Git files: %w", err)
|
|
}
|
|
return fileResponse.GetMap(), nil
|
|
}
|
|
|
|
func (a *argoCDService) GetDirectories(ctx context.Context, repoURL, revision, project string, noRevisionCache bool, sourceIntegrity *v1alpha1.SourceIntegrity) ([]string, error) {
|
|
repo, err := a.getRepository(ctx, repoURL, project)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error in GetRepository: %w", err)
|
|
}
|
|
|
|
dirRequest := &apiclient.GitDirectoriesRequest{
|
|
Repo: repo,
|
|
SubmoduleEnabled: a.submoduleEnabled,
|
|
Revision: revision,
|
|
NoRevisionCache: noRevisionCache,
|
|
SourceIntegrity: sourceIntegrity,
|
|
VerifyCommit: sourceIntegrity != nil,
|
|
}
|
|
|
|
dirResponse, err := a.getGitDirectoriesFromRepoServer(ctx, dirRequest)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error retrieving Git Directories: %w", err)
|
|
}
|
|
return dirResponse.GetPaths(), nil
|
|
}
|