Skip to content

Commit

Permalink
fix gc build & add validation for dagger build
Browse files Browse the repository at this point in the history
Signed-off-by: bupd <[email protected]>
  • Loading branch information
bupd committed Sep 22, 2024
1 parent aaa9653 commit 0b27c5d
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 65 deletions.
13 changes: 8 additions & 5 deletions ci/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ func (m *HarborSatellite) Build(
// +optional
// +defaultPath="./"
source *dagger.Directory,
component string) *dagger.Directory {
return m.build(source, component)
component string,
) (*dagger.Directory, error) {
if component == "satellite" || component == "ground-control" {
return m.build(source, component), nil
}
return nil, fmt.Errorf("error: please provide component as either satellite or ground-control")
}

// Release function would release the build to the github with the tags provided. Directory should be "." for both the satellite and the ground control.
func (m *HarborSatellite) Release(ctx context.Context, directory *dagger.Directory, token, name string,
// +optional
// +default="patch"
release_type string) (string, error) {

release_type string,
) (string, error) {
container := dag.Container().
From("alpine/git").
WithEnvVariable("GITHUB_TOKEN", token).
Expand Down Expand Up @@ -66,7 +70,6 @@ func (m *HarborSatellite) Release(ctx context.Context, directory *dagger.Directo
WithExec([]string{"git", "tag", release_tag}).
WithExec([]string{"goreleaser", "release", "-f", pathToMain, "--clean"}).
Stderr(ctx)

if err != nil {
slog.Error("Failed to release: ", err, ".")
slog.Error("Release Output:", release_output, ".")
Expand Down
21 changes: 13 additions & 8 deletions ci/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func (m *HarborSatellite) Service(
AsService()
}

// Would build the project with the source provided. The name should be the name of the project.
func (m *HarborSatellite) build(source *dagger.Directory, name string) *dagger.Directory {
fmt.Printf("Building %s\n", name)
// builds given component from source
func (m *HarborSatellite) build(source *dagger.Directory, component string) *dagger.Directory {
fmt.Printf("Building %s\n", component)

gooses := []string{"linux", "darwin"}
goarches := []string{"amd64", "arm64"}
Expand All @@ -85,8 +85,13 @@ func (m *HarborSatellite) build(source *dagger.Directory, name string) *dagger.D
WithMountedCache("/go/build-cache", dag.CacheVolume("go-build")).
WithEnvVariable("GOCACHE", "/go/build-cache").
WithEnvVariable("GOOS", goos).
WithEnvVariable("GOARCH", goarch).
WithExec([]string{"go", "build", "-o", outputBinary})
WithEnvVariable("GOARCH", goarch)
if component == "ground-control" {
build = build.WithWorkdir("./ground-control/").
WithExec([]string{"go", "build", "-o", outputBinary})
} else {
build = build.WithExec([]string{"go", "build", "-o", outputBinary})
}

// add build to outputs
outputs = outputs.WithDirectory(component, build.Directory(component))
Expand All @@ -101,15 +106,15 @@ func (m *HarborSatellite) build(source *dagger.Directory, name string) *dagger.D
func (m *HarborSatellite) get_release_tag(ctx context.Context, git_container *dagger.Container, source *dagger.Directory, name string,
// +optional
// +default="patch"
release_type string) (string, error) {
release_type string,
) (string, error) {
/// This would get the last tag that was created. Empty string if no tag was created.
getTagsOutput, err := git_container.
WithExec([]string{
"/bin/sh", "-c",
fmt.Sprintf(`git tag --list "v*%s" | sort -V | tail -n 1`, name),
}).
Stdout(ctx)

if err != nil {
slog.Error("Failed to get tags: ", err, ".")
slog.Error("Get Tags Output:", getTagsOutput, ".")
Expand Down Expand Up @@ -151,7 +156,7 @@ func generateNewTag(latestTag, suffix, release_type string) (string, error) {
slog.Error("Failed to convert patch version to integer: ", err.Error(), ".")
return "", err
}
// Increment the version according to the release type
// Increment the version accordin ground-control")g to the release type
switch release_type {
case "major":
major++
Expand Down
2 changes: 1 addition & 1 deletion dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "harbor-satellite",
"sdk": "go",
"source": "ci",
"engineVersion": "v0.13.1"
"engineVersion": "v0.13.3"
}
26 changes: 13 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/google/go-containerregistry v0.19.2
github.com/joho/godotenv v1.5.1
github.com/prometheus/client_golang v1.19.1
golang.org/x/sync v0.7.0
golang.org/x/sync v0.8.0
// use go get zotregistry.dev/zot@main to get package
zotregistry.dev/zot v1.4.4-0.20240604183918-a4b6892a9c27
)
Expand All @@ -20,7 +20,7 @@ require (
github.com/stretchr/testify v1.9.0
)

require golang.org/x/oauth2 v0.20.0 // indirect
require golang.org/x/oauth2 v0.22.0 // indirect

require (
cloud.google.com/go v0.112.1 // indirect
Expand Down Expand Up @@ -64,7 +64,7 @@ require (
github.com/ThalesIgnite/crypto11 v1.2.5 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/adrg/xdg v0.5.0 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
Expand Down Expand Up @@ -118,7 +118,7 @@ require (
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/briandowns/spinner v1.23.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chai2010/gettext-go v1.0.2 // indirect
github.com/chartmuseum/auth v0.5.0 // indirect
github.com/cheggaaa/pb/v3 v3.1.5 // indirect
Expand Down Expand Up @@ -220,7 +220,7 @@ require (
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gosuri/uitable v0.0.4 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-getter v1.7.4 // indirect
Expand Down Expand Up @@ -405,21 +405,21 @@ require (
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/term v0.24.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.172.0 // indirect
google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/grpc v1.64.0
google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
Expand Down
Loading

0 comments on commit 0b27c5d

Please sign in to comment.