From cfd0b67bd3919f2cdefd81a58f81ca516b68b556 Mon Sep 17 00:00:00 2001 From: Dean Roehrich Date: Tue, 16 May 2023 13:44:52 -0500 Subject: [PATCH] Allow the nnf-mfu release to be specified. (#64) Allow the nnf-mfu release to be specified. Allow a build environment to be specified for the repositories. Add an environment variable to indicate which version of nnf-mfu should be used. Signed-off-by: Dean Roehrich --- config/config.go | 32 +++++++++++++++++----------- config/repositories.yaml | 12 +++++++++++ go.mod | 2 +- go.sum | 4 ++-- main.go | 45 +++++++++++++++++++++++++++------------- nnf-dm | 2 +- nnf-sos | 2 +- 7 files changed, 68 insertions(+), 31 deletions(-) diff --git a/config/config.go b/config/config.go index d7b58240..7497acd4 100644 --- a/config/config.go +++ b/config/config.go @@ -1,5 +1,5 @@ /* - * Copyright 2021, 2022 Hewlett Packard Enterprise Development LP + * Copyright 2021-2023 Hewlett Packard Enterprise Development LP * Other additional copyright holders may be indicated within. * * The entirety of this work is licensed under the Apache License, @@ -171,43 +171,51 @@ func (system *System) Verify() error { } type RepositoryConfigFile struct { - Repositories []Repository `yaml:"repositories"` + Repositories []Repository `yaml:"repositories"` + BuildConfig BuildConfiguration `yaml:"buildConfiguration"` } type Repository struct { - Name string - Overlays []string `yaml:",flow"` - Development string - Master string - UseRemoteK bool `yaml:"useRemoteK,omitempty"` + Name string `yaml:"name"` + Overlays []string `yaml:"overlays,flow"` + Development string `yaml:"development"` + Master string `yaml:"master"` + UseRemoteK bool `yaml:"useRemoteK,omitempty"` RemoteReference struct { Build string `yaml:"build"` Url string `yaml:"url"` } `yaml:"remoteReference,omitempty"` } -func FindRepository(module string) (*Repository, error) { +type BuildConfiguration struct { + Env []struct { + Name string `yaml:"name"` + Value string `yaml:"value"` + } `yaml:"env"` +} + +func FindRepository(module string) (*Repository, *BuildConfiguration, error) { configFile, err := os.ReadFile(DefaultRepoCfgPath) if err != nil { configFile, err = os.ReadFile(filepath.Join("..", DefaultRepoCfgPath)) if err != nil { - return nil, err + return nil, nil, err } } config := new(RepositoryConfigFile) if err := yaml.UnmarshalStrict(configFile, config); err != nil { - return nil, err + return nil, nil, err } for _, repository := range config.Repositories { if module == repository.Name { - return &repository, nil + return &repository, &config.BuildConfig, nil } } - return nil, fmt.Errorf("Repository '%s' Not Found", module) + return nil, nil, fmt.Errorf("Repository '%s' Not Found", module) } type Daemon struct { diff --git a/config/repositories.yaml b/config/repositories.yaml index f46fa1eb..09e6ee9f 100644 --- a/config/repositories.yaml +++ b/config/repositories.yaml @@ -42,3 +42,15 @@ repositories: remoteReference: build: v0.0.3 url: https://github.com/NearNodeFlash/lustre-fs-operator.git/config/default/?ref=%s + +buildConfiguration: + # Environment variables to set when calling the any 'make' or 'deploy' + # command in a submodule. + env: + # The nnf-mfu container to use. + # Example values: + # - A specific release build: 0.0.1 (without the "v" prefix) + # - The most recent build from the master branch: master + - name: NNFMFU_VERSION + value: 0.0.1 + diff --git a/go.mod b/go.mod index 47000ccb..43294e14 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( ) require ( - github.com/NearNodeFlash/nnf-ec v0.0.0-20230427164720-dc73727a986f // indirect + github.com/NearNodeFlash/nnf-ec v0.0.0-20230512221456-5fa47fb42560 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 30e8e4f4..71fded0d 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/NearNodeFlash/nnf-ec v0.0.0-20230427164720-dc73727a986f h1:kJetY6ACr44dAKEbJkXCwDdbnqqx4KKx63cjXPCHktQ= -github.com/NearNodeFlash/nnf-ec v0.0.0-20230427164720-dc73727a986f/go.mod h1:11Ol46sAWdqlj3WmIFTzKO+UxQX3lvWBqpe6yaiMEIg= +github.com/NearNodeFlash/nnf-ec v0.0.0-20230512221456-5fa47fb42560 h1:ewsW6a7EFrueIrjoMgS7oBCiaAU0Nc7wKwl5fW95NLg= +github.com/NearNodeFlash/nnf-ec v0.0.0-20230512221456-5fa47fb42560/go.mod h1:11Ol46sAWdqlj3WmIFTzKO+UxQX3lvWBqpe6yaiMEIg= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0= github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4= diff --git a/main.go b/main.go index 7f821512..e328b096 100644 --- a/main.go +++ b/main.go @@ -180,8 +180,18 @@ func runMakeCommand(ctx *Context, system *config.System, module string, command return err } + fmt.Print(" Finding Repository...") + repo, buildConfig, err := config.FindRepository(module) + if err != nil { + return err + } + fmt.Printf(" %s\n", repo.Name) + for idx := range buildConfig.Env { + cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", buildConfig.Env[idx].Name, buildConfig.Env[idx].Value)) + } + if len(overlay) != 0 { - cmd.Env = append(os.Environ(), + cmd.Env = append(cmd.Env, "OVERLAY="+overlay, ) } @@ -267,7 +277,7 @@ func (cmd *InstallCmd) Run(ctx *Context) error { if !cmd.NoBuild && d.Bin != "" { cmd := exec.Command("go", "build", "-o", d.Bin) - cmd.Env = append(os.Environ(), + cmd.Env = append(cmd.Env, "CGO_ENABLED=0", "GOOS=linux", "GOARCH=amd64", @@ -468,7 +478,7 @@ func (cmd *InitCmd) Run(ctx *Context) error { for _, module := range modulesAllowedRemote { var applyK string - repo, err := config.FindRepository(module) + repo, _, err := config.FindRepository(module) if err != nil { return err } @@ -738,7 +748,7 @@ func addTag(tag string) error { func getOverlay(system *config.System, module string) (string, error) { - repo, err := config.FindRepository(module) + repo, _, err := config.FindRepository(module) if err != nil { return "", err } @@ -784,6 +794,16 @@ func deployModule(ctx *Context, system *config.System, module string) error { return err } + fmt.Print(" Finding Repository...") + repo, buildConfig, err := config.FindRepository(module) + if err != nil { + return err + } + fmt.Printf(" %s\n", repo.Name) + for idx := range buildConfig.Env { + cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", buildConfig.Env[idx].Name, buildConfig.Env[idx].Value)) + } + if system.Name == "kind" { // TODO: Do a sanity check to make sure the image is present on the kind nodes. This ensures // that a "kind-push" was done. This would _not_ guarantee that a docker-build was done with @@ -791,19 +811,12 @@ func deployModule(ctx *Context, system *config.System, module string) error { // images present on a cluster node by using `docker exec -it [NODE NAME] crictl images` if len(overlay) != 0 { - cmd.Env = append(os.Environ(), + cmd.Env = append(cmd.Env, "OVERLAY="+overlay) } } else { - fmt.Print(" Finding Repository...") - repo, err := config.FindRepository(module) - if err != nil { - return err - } - fmt.Printf(" %s\n", repo.Name) - fmt.Printf(" Loading Current Branch...") branch, err := currentBranch() if err != nil { @@ -833,7 +846,7 @@ func deployModule(ctx *Context, system *config.System, module string) error { version := commit imageTagBase := strings.TrimSuffix(strings.TrimPrefix(url, "https://"), "/") // According to Tony; docker assumes a secure repo and prepends https when it fetches the image; so we drop it here. - cmd.Env = append(os.Environ(), + cmd.Env = append(cmd.Env, "IMAGE_TAG_BASE="+imageTagBase, "VERSION="+version, "OVERLAY="+overlay, @@ -848,9 +861,13 @@ func deployModule(ctx *Context, system *config.System, module string) error { func runCommand(ctx *Context, cmd *exec.Cmd) ([]byte, error) { if ctx.DryRun { fmt.Printf(" Dry-Run: Skipping command '%s'\n", cmd.String()) + fmt.Printf(" Additional env: %v\n", cmd.Env) return nil, nil } + if len(cmd.Env) > 0 { + cmd.Env = append(cmd.Env, os.Environ()...) + } stdoutStderr, err := cmd.CombinedOutput() if err != nil { fmt.Printf("%s\n", stdoutStderr) @@ -892,7 +909,7 @@ func shouldSkipModule(module string, permittedModulesOrEmpty []string) bool { // Modules that are being installed via remote should be skipped. for _, remoteModule := range modulesAllowedRemote { if module == remoteModule { - repo, err := config.FindRepository(module) + repo, _, err := config.FindRepository(module) if err != nil { return true } diff --git a/nnf-dm b/nnf-dm index d6b3864f..43ad71fc 160000 --- a/nnf-dm +++ b/nnf-dm @@ -1 +1 @@ -Subproject commit d6b3864f6026ba2a219c7d6d481f35df26cca031 +Subproject commit 43ad71fc5f2f0d1e66630447c390b8601c44051e diff --git a/nnf-sos b/nnf-sos index cbf389ea..53e0ee30 160000 --- a/nnf-sos +++ b/nnf-sos @@ -1 +1 @@ -Subproject commit cbf389ea60a8411ea8500eb4c7be62ea3eae2d87 +Subproject commit 53e0ee306040ace4811963d768311a647f981ee4