From 37a6ab49ef883e5a49ad3f8f4d2ade499b4df742 Mon Sep 17 00:00:00 2001 From: Vadim Bauer Date: Tue, 24 Sep 2024 16:13:52 +0200 Subject: [PATCH] cleanup --- .gitignore | 4 +- comments.patch | 177 ------------------------------------------------- 2 files changed, 1 insertion(+), 180 deletions(-) delete mode 100644 comments.patch diff --git a/.gitignore b/.gitignore index bba0048c..4e00192e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,4 @@ go.work /harbor dist/ /dagger.gen.go -/internal/dagger -/internal/querybuilder -/internal/telemetry +/internal/* diff --git a/comments.patch b/comments.patch deleted file mode 100644 index 413ed6a2..00000000 --- a/comments.patch +++ /dev/null @@ -1,177 +0,0 @@ -Subject: [PATCH] comments ---- -Index: main.go -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/main.go b/main.go ---- a/main.go (revision 96fa3fa98fb6ceb760e89eb10f1704e753b888ed) -+++ b/main.go (date 1724857880146) -@@ -3,17 +3,16 @@ - import ( - "context" - "fmt" -- "log" -- "strings" - "github.com/goharbor/harbor-cli/internal/dagger" -+ "log" - ) - - const ( -- GO_VERSION = "1.22.5" -- SYFT_VERSION = "v1.9.0" -+ GO_VERSION = "1.22.5" -+ SYFT_VERSION = "v1.9.0" - GORELEASER_VERSION = "v2.1.0" -- APP_NAME = "dagger-harbor-cli" -- PUBLISH_ADDRESS = "demo.goharbor.io/library/harbor-cli:0.0.3" -+ APP_NAME = "dagger-harbor-cli" -+ PUBLISH_ADDRESS = "demo.goharbor.io/library/harbor-cli:0.0.3" - ) - - type HarborCli struct{} -@@ -46,25 +45,31 @@ - WithMountedDirectory("/src", directoryArg). - WithWorkdir("/src"). - WithExec([]string{"golangci-lint", "run", "--timeout", "5m"}) -- - } - --func (m *HarborCli) BuildHarbor(ctx context.Context, directoryArg *dagger.Directory) *dagger.Directory { -+// Builds the Harbor CLI for multiple OS and architectures -+func (m *HarborCli) Build(ctx context.Context, source *dagger.Directory) *dagger.Directory { -+ - fmt.Println("🛠️ Building with Dagger...") - oses := []string{"linux", "darwin", "windows"} - arches := []string{"amd64", "arm64"} - outputs := dag.Directory() -- golangcont, main_go_path := fetchMainGoPath(ctx, directoryArg) -- - for _, goos := range oses { - for _, goarch := range arches { -- path := fmt.Sprintf("build/%s/%s/", goos, goarch) -- build := golangcont.WithEnvVariable("GOOS", goos). -+ bin_path := fmt.Sprintf("build/%s/%s/", goos, goarch) -+ builder := dag.Container(). -+ From("golang:1.22-alpine"). -+ WithMountedDirectory("/src", source). -+ WithWorkdir("/src"). -+ WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod-122-5")). -+ WithEnvVariable("GOMODCACHE", "/go/pkg/mod"). -+ WithMountedCache("/go/build-cache", dag.CacheVolume("go-build-122-5")). -+ WithEnvVariable("GOCACHE", "/go/build-cache"). -+ WithEnvVariable("GOOS", goos). - WithEnvVariable("GOARCH", goarch). -- WithExec([]string{"go", "build", "-o", path + "harbor", main_go_path}) -- -+ WithExec([]string{"go", "build", "-o", bin_path + "harbor", "/src/cmd/harbor/main.go"}) - // Get reference to build output directory in container -- outputs = outputs.WithDirectory(path, build.Directory(path)) -+ outputs = outputs.WithDirectory(bin_path, builder.Directory(bin_path)) - } - } - return outputs -@@ -90,44 +95,26 @@ - log.Println("Release tasks completed successfully 🎉") - } - --func (m *HarborCli) DockerPublish(ctx context.Context, directoryArg *dagger.Directory, regUsername string, regPassword *dagger.Secret, privateKey *dagger.Secret, cosignPassword *dagger.Secret) string { -+func (m *HarborCli) DockerPublish(ctx context.Context, source *dagger.Directory) string { - --builder, main_go_path := fetchMainGoPath(ctx, directoryArg) --builder = builder.WithWorkdir("/src").WithExec([]string{"go", "build", "-o", "harbor", main_go_path}) -+ builder := m.Build(ctx, source) - --// Create a minimal runtime container --runtime := dag.Container(). --From("alpine:latest"). --WithWorkdir("/root/"). --WithFile("/root/harbor", builder.File("/src/harbor")). --WithEntrypoint([]string{"./harbor"}) -+ // Create a minimal runtime container -+ runtime := dag.Container(). -+ From("alpine:latest"). -+ WithWorkdir("/root/"). -+ WithFile("/root/harbor", builder.File("/src/harbor")). -+ WithEntrypoint([]string{"./harbor"}) - --addr, _ := runtime.Publish(ctx,PUBLISH_ADDRESS) --_ , err := dag.Cosign().Sign(ctx,privateKey,cosignPassword,[]string{addr},dagger.CosignSignOpts{RegistryUsername: regUsername, RegistryPassword: regPassword}) --if err != nil { -- panic(err) --} --fmt.Printf("Published to %s 🎉\n", addr) --return addr -+ addr, _ := runtime.Publish(ctx, PUBLISH_ADDRESS) -+ //_, err := dag.Cosign().Sign(ctx, privateKey, cosignPassword, []string{addr}, dagger.CosignSignOpts{RegistryUsername: regUsername, RegistryPassword: regPassword}) -+ //if err != nil { -+ // panic(err) -+ //} -+ fmt.Printf("Published to %s 🎉\n", addr) -+ return addr - } - --func fetchMainGoPath(ctx context.Context, directoryArg *dagger.Directory) (*dagger.Container, string) { -- -- container := dag.Container(). -- From("golang:1.22-alpine"). -- WithMountedDirectory("/src", directoryArg). -- WithWorkdir("/src"). -- WithExec([]string{"sh", "-c", "export MAIN_GO_PATH=$(find ./cmd -type f -name 'main.go' -print -quit) && echo $MAIN_GO_PATH > main_go_path.txt"}) -- -- // Reading the content of main_go_path.txt file and fetching the actual path of main.go -- main_go_txt_file, _ := container.File("main_go_path.txt").Contents(ctx) -- trimmedPath := strings.TrimPrefix(main_go_txt_file, "./") -- result := "/src/" + trimmedPath -- main_go_path := strings.TrimRight(result, "\n") -- -- return container, main_go_path --} -- - func goreleaserContainer(directoryArg *dagger.Directory, githubToken string) *dagger.Container { - token := dag.SetSecret("github_token", githubToken) - -Index: dagger.json -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/dagger.json b/dagger.json ---- a/dagger.json (revision 96fa3fa98fb6ceb760e89eb10f1704e753b888ed) -+++ b/dagger.json (date 1724762958963) -@@ -8,5 +8,5 @@ - } - ], - "source": ".", -- "engineVersion": "v0.12.3" -+ "engineVersion": "v0.12.5" - } -Index: README.md -IDEA additional info: -Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP -<+>UTF-8 -=================================================================== -diff --git a/README.md b/README.md ---- a/README.md (revision 96fa3fa98fb6ceb760e89eb10f1704e753b888ed) -+++ b/README.md (date 1724851803391) -@@ -102,11 +102,16 @@ - - ## Build From Source - -+For building the Harbor CLI locally, we recommend using [Dagger](https://docs.dagger.io/). -+Make sure you have also a container runtime like Docker or Podman installed on your system. -+ - ```bash - git clone https://github.com/goharbor/harbor-cli.git --cd harbor-cli/cmd/harbor --go build . --sudo mv harbor /usr/local/bin/ -+dagger functions # to see all existing operations without looking into code -+dagger call build --source=. # to create a harbor cli binary -+ls -la build/ # to see the binary for your platform -+ -+ - ``` - - ## Linux and MacOS