Skip to content

Commit

Permalink
CLOUDP-237136: [mongocli] fix packing (#2761)
Browse files Browse the repository at this point in the history
Co-authored-by: Filipe Constantinov Menezes <filipe.menezes@mongodb.com>
  • Loading branch information
jeroenvervaeke and fmenezes committed Mar 12, 2024
1 parent e2a224a commit f76e194
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 139 deletions.
2 changes: 1 addition & 1 deletion build/ci/evergreen-generate-tasks.sh
Expand Up @@ -16,4 +16,4 @@

set -Eeou pipefail

go run tools/genevergreen/main.go -tool_name "mongocli" -tasks "${task_type:?}" >tasks.json
go run tools/genevergreen/main.go -tasks "${task_type:?}" >tasks.json
2 changes: 1 addition & 1 deletion build/package/generate-msi.sh
Expand Up @@ -33,7 +33,7 @@ COMMIT=$(git log -n1 --format=format:"%H")
SOURCE_FILES=./cmd/mongocli
PACKAGE_NAME=mongocli_${VERSION_NAME}_windows_x86_64.msi
OUTPUT=./bin/mongocli.exe
LINKER_FLAGS="-s -w -X github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/version.Version=${VERSION_GIT} -X github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/version.GitCommit=${COMMIT} -X github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/config.ToolName=mongocli"
LINKER_FLAGS="-s -w -X github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/version.Version=${VERSION_GIT} -X github.com/mongodb/mongodb-atlas-cli/mongocli/v2/internal/version.GitCommit=${COMMIT}"
WIX_MANIFEST_FILE="./build/package/wix/mongocli.json"

env GOOS=windows GOARCH=amd64 go build \
Expand Down
122 changes: 25 additions & 97 deletions tools/genevergreen/generate/generate.go
Expand Up @@ -70,28 +70,21 @@ var (
}
)

func newDependency(toolName, os, serverVersion, repo string) shrub.TaskDependency {
func newDependency(os, serverVersion, repo string) shrub.TaskDependency {
return shrub.TaskDependency{
Name: fmt.Sprintf("push_%s_%s_%s_%s_%s_stable", toolName, newOs[os], repo, x86_64, strings.ReplaceAll(serverVersion, ".", "")),
Variant: fmt.Sprintf("generated_release_%s_publish_%s", toolName, strings.ReplaceAll(serverVersion, ".", "")),
Name: fmt.Sprintf("push_mongocli_%s_%s_%s_%s_stable", newOs[os], repo, x86_64, strings.ReplaceAll(serverVersion, ".", "")),
Variant: fmt.Sprintf("generated_release_mongocli_publish_%s", strings.ReplaceAll(serverVersion, ".", "")),
}
}

func RepoTasks(c *shrub.Configuration, toolName string) {
func RepoTasks(c *shrub.Configuration) {
for _, serverVersion := range serverVersions {
v := &shrub.Variant{
BuildName: fmt.Sprintf("test_repo_%v_%v", toolName, serverVersion),
BuildDisplayName: fmt.Sprintf("Test %v on repo %v", toolName, serverVersion),
BuildName: fmt.Sprintf("test_repo_mongocli_%v", serverVersion),
BuildDisplayName: fmt.Sprintf("Test mongocli on repo %v", serverVersion),
DistroRunOn: []string{runOn},
}

pkg := "mongodb-atlas-cli"
entrypoint := "atlas"
if toolName == mongocli {
pkg = mongocli
entrypoint = mongocli
}

for _, os := range oses {
for _, repo := range repos {
mongoRepo := "https://repo.mongodb.com"
Expand All @@ -100,16 +93,16 @@ func RepoTasks(c *shrub.Configuration, toolName string) {
}

t := &shrub.Task{
Name: fmt.Sprintf("test_repo_%v_%v_%v_%v", toolName, os, repo, serverVersion),
Name: fmt.Sprintf("test_repo_mongocli_%v_%v_%v", os, repo, serverVersion),
}
t = t.Stepback(false).
GitTagOnly(true).
Dependency(newDependency(toolName, os, serverVersion, repo)).
Dependency(newDependency(os, serverVersion, repo)).
Function("clone").
FunctionWithVars("docker build repo", map[string]string{
"server_version": serverVersion,
"package": pkg,
"entrypoint": entrypoint,
"package": "mongocli",
"entrypoint": "mongocli",
"image": os,
"mongo_package": fmt.Sprintf("mongodb-%v", repo),
"mongo_repo": mongoRepo,
Expand All @@ -123,23 +116,22 @@ func RepoTasks(c *shrub.Configuration, toolName string) {
}
}

func PostPkgTasks(c *shrub.Configuration, toolName string) {
func PostPkgTasks(c *shrub.Configuration) {
v := &shrub.Variant{
BuildName: fmt.Sprintf("pkg_smoke_tests_docker_%v_generated", toolName),
BuildDisplayName: fmt.Sprintf("Generated post packaging smoke tests (Docker / %v)", toolName),
BuildName: "pkg_smoke_tests_docker_mongocli_generated",
BuildDisplayName: "Generated post packaging smoke tests (Docker / mongocli)",
DistroRunOn: []string{runOn},
}

for _, os := range oses {
t := &shrub.Task{
Name: fmt.Sprintf("pkg_test_%v_docker_%v", toolName, os),
Name: fmt.Sprintf("pkg_test_mongocli_docker_%v", os),
}
t = t.Dependency(shrub.TaskDependency{
Name: "package_goreleaser",
Variant: fmt.Sprintf("goreleaser_%v_snapshot", toolName),
Variant: "goreleaser_mongocli_snapshot",
}).Function("clone").FunctionWithVars("docker build", map[string]string{
"tool_name": toolName,
"image": postPkgImg[os],
"image": postPkgImg[os],
})
c.Tasks = append(c.Tasks, t)
v.AddTasks(t.Name)
Expand All @@ -148,57 +140,26 @@ func PostPkgTasks(c *shrub.Configuration, toolName string) {
c.Variants = append(c.Variants, v)
}

func PostPkgMetaTasks(c *shrub.Configuration, toolName string) {
if toolName != atlascli {
return
}

v := &shrub.Variant{
BuildName: fmt.Sprintf("pkg_smoke_tests_docker_meta_%s_generated", toolName),
BuildDisplayName: fmt.Sprintf("Generated post packaging smoke tests (Meta / %s)", toolName),
DistroRunOn: []string{runOn},
}

for _, os := range oses {
t := &shrub.Task{
Name: fmt.Sprintf("pkg_test_%s_meta_docker_%s", toolName, os),
}
t = t.Dependency(shrub.TaskDependency{
Name: "package_goreleaser",
Variant: fmt.Sprintf("goreleaser_%v_snapshot", toolName),
}).Function("clone").
FunctionWithVars("docker build meta", map[string]string{
"tool_name": toolName,
"image": postPkgImg[os],
})
c.Tasks = append(c.Tasks, t)
v.AddTasks(t.Name)
}

c.Variants = append(c.Variants, v)
}

func PublishStableTasks(c *shrub.Configuration, toolName string) {
func PublishStableTasks(c *shrub.Configuration) {
dependency := []shrub.TaskDependency{
{
Name: fmt.Sprintf("compile_%s", toolName),
Name: "compile",
Variant: "code_health",
},
{
Name: "package_goreleaser",
Variant: fmt.Sprintf("release_%s_github", toolName),
Variant: "release_mongocli_github",
},
}
for _, sv := range serverVersions {
v := &shrub.Variant{
BuildName: fmt.Sprintf("generated_release_%s_publish_%s", toolName, strings.ReplaceAll(sv, ".", "")),
BuildDisplayName: fmt.Sprintf("Publish %s yum/apt %s", toolName, sv),
BuildName: fmt.Sprintf("generated_release_mongocli_publish_%s", strings.ReplaceAll(sv, ".", "")),
BuildDisplayName: fmt.Sprintf("Publish mongocli yum/apt %s", sv),
DistroRunOn: []string{"rhel80-small"},
}
publishVariant(
c,
v,
toolName,
sv,
"_stable",
dependency,
Expand All @@ -207,57 +168,24 @@ func PublishStableTasks(c *shrub.Configuration, toolName string) {
}
}

func PublishSnapshotTasks(c *shrub.Configuration, toolName string) {
func PublishSnapshotTasks(c *shrub.Configuration) {
dependency := []shrub.TaskDependency{
{
Name: fmt.Sprintf("compile_%s", toolName),
Name: "compile",
Variant: "code_health",
},
{
Name: "package_goreleaser",
Variant: fmt.Sprintf("goreleaser_%s_snapshot", toolName),
Variant: "goreleaser_mongocli_snapshot",
},
}
v := c.Variant(fmt.Sprintf("publish_%s_snapshot", toolName))
v := c.Variant("publish_mongocli_snapshot")
publishVariant(
c,
v,
toolName,
"5.0",
"",
dependency,
false,
)
}

func LocalDeploymentTasks(c *shrub.Configuration, toolName string) {
if toolName != atlascli {
return
}

for _, runOn := range []string{
"rhel8.7-small",
"rhel8.8-small",
"rhel90-small",
"rhel91-small",
} {
v := &shrub.Variant{
BuildName: fmt.Sprintf("e2e_generated_local_deployments_%v", strings.ReplaceAll(runOn, ".", "_")),
BuildDisplayName: fmt.Sprintf("Generated local deployments tests (%s)", runOn),
DistroRunOn: []string{runOn},
Expansions: expansions(),
}

v.AddTasks(".e2e .deployments .local .run")

c.Variants = append(c.Variants, v)
}
}

func expansions() map[string]interface{} {
return map[string]interface{}{
"go_root": "/opt/golang/go1.21",
"go_bin": "/opt/golang/go1.21/bin",
"go_base_path": "",
}
}
20 changes: 8 additions & 12 deletions tools/genevergreen/generate/generate_test.go
Expand Up @@ -24,19 +24,15 @@ import (
)

func TestPublishSnapshotTasks(t *testing.T) {
t.Run(mongocli, func(t *testing.T) {
c := &shrub.Configuration{}
PublishSnapshotTasks(c, mongocli)
assert.Len(t, c.Tasks, 34)
assert.Len(t, c.Variants, 2)
})
c := &shrub.Configuration{}
PublishSnapshotTasks(c)
assert.Len(t, c.Tasks, 34)
assert.Len(t, c.Variants, 2)
}

func TestPublishStableTasks(t *testing.T) {
t.Run(mongocli, func(t *testing.T) {
c := &shrub.Configuration{}
PublishStableTasks(c, mongocli)
assert.Len(t, c.Variants, 4)
assert.Len(t, c.Tasks, 136)
})
c := &shrub.Configuration{}
PublishStableTasks(c)
assert.Len(t, c.Variants, 4)
assert.Len(t, c.Tasks, 136)
}
9 changes: 4 additions & 5 deletions tools/genevergreen/generate/publish.go
Expand Up @@ -74,7 +74,7 @@ var distros = map[string]Platform{
},
}

func newPublishTask(taskName, toolName, extension, edition, distro, taskServerVersion, notaryKey, arch string, stable bool, dependency []shrub.TaskDependency) *shrub.Task {
func newPublishTask(taskName, extension, edition, distro, taskServerVersion, notaryKey, arch string, stable bool, dependency []shrub.TaskDependency) *shrub.Task {
t := &shrub.Task{
Name: taskName,
}
Expand All @@ -85,7 +85,6 @@ func newPublishTask(taskName, toolName, extension, edition, distro, taskServerVe
Function("clone").
Function("install curator").
FunctionWithVars("push", map[string]string{
"tool_name": toolName,
"distro": distro,
"ext": extension,
"server_version": taskServerVersion,
Expand All @@ -96,7 +95,7 @@ func newPublishTask(taskName, toolName, extension, edition, distro, taskServerVe
return t
}

func publishVariant(c *shrub.Configuration, v *shrub.Variant, toolName, sv, stableSuffix string, dependency []shrub.TaskDependency, stable bool) {
func publishVariant(c *shrub.Configuration, v *shrub.Variant, sv, stableSuffix string, dependency []shrub.TaskDependency, stable bool) {
taskServerVersion := fmt.Sprintf("%s.0", sv)
notaryKey := fmt.Sprintf("server-%s", sv)
taskSv := "_" + sv
Expand All @@ -107,8 +106,8 @@ func publishVariant(c *shrub.Configuration, v *shrub.Variant, toolName, sv, stab
for _, r := range repos {
for k, d := range distros {
for _, a := range d.architectures {
taskName := fmt.Sprintf("push_%s_%s_%s_%s%s%s", toolName, k, r, a, strings.ReplaceAll(taskSv, ".", ""), stableSuffix)
t := newPublishTask(taskName, toolName, d.extension, r, k, taskServerVersion, notaryKey, a, stable, dependency)
taskName := fmt.Sprintf("push_mongocli_%s_%s_%s%s%s", k, r, a, strings.ReplaceAll(taskSv, ".", ""), stableSuffix)
t := newPublishTask(taskName, d.extension, r, k, taskServerVersion, notaryKey, a, stable, dependency)
c.Tasks = append(c.Tasks, t)
v.AddTasks(t.Name)
}
Expand Down
28 changes: 5 additions & 23 deletions tools/genevergreen/main.go
Expand Up @@ -25,31 +25,16 @@ import (
"github.com/mongodb/mongodb-atlas-cli/mongocli/v2/tools/genevergreen/generate"
)

const (
atlascli = "atlascli"
mongocli = "mongocli"
)

var (
ErrMissingOption = errors.New("missing option")
)

func run() error {
var toolName, taskType string
var taskType string

flag.StringVar(&taskType, "tasks", "", "type of task to be generated")
flag.StringVar(&toolName, "tool_name", "", fmt.Sprintf("Tool to generate tasks for (%s or %s)", atlascli, mongocli))

flag.Parse()

if toolName == "" {
return fmt.Errorf("%w: %s", ErrMissingOption, "tool_name")
}

if toolName != atlascli && toolName != mongocli {
return fmt.Errorf("-tool_name must be either %q or %q", atlascli, mongocli)
}

if taskType == "" {
return fmt.Errorf("%w: %s", ErrMissingOption, "tasks")
}
Expand All @@ -58,16 +43,13 @@ func run() error {

switch taskType {
case "repo":
generate.RepoTasks(c, toolName)
generate.RepoTasks(c)
case "postpkg":
generate.PostPkgTasks(c, toolName)
generate.PostPkgMetaTasks(c, toolName)
generate.PostPkgTasks(c)
case "snapshot":
generate.PublishSnapshotTasks(c, toolName)
generate.PublishSnapshotTasks(c)
case "publish":
generate.PublishStableTasks(c, toolName)
case "local":
generate.LocalDeploymentTasks(c, toolName)
generate.PublishStableTasks(c)
default:
return errors.New("-tasks is invalid")
}
Expand Down

0 comments on commit f76e194

Please sign in to comment.