Skip to content

Commit

Permalink
feat: deploy modules to different namespaces
Browse files Browse the repository at this point in the history
Signed-off-by: hanshal101 <[email protected]>
  • Loading branch information
hanshal101 authored and hanshal101 committed Jul 8, 2024
1 parent e299b67 commit 392f667
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var BuildCmd = &cobra.Command{
os.Exit(1)
}

err = generate.Generate(fh, sc)
err = generate.Generate(fh, sc, nil)
if err != nil {
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/develop/develop.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var DevCmd = &cobra.Command{
os.Exit(1)
}

err = generate.Generate(fh, sc)
err = generate.Generate(fh, sc, nil)
if err != nil {
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/dockerfile/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ var DFCmd = &cobra.Command{
os.Exit(1)
}

err = generate.Generate(fh, sc)
err = generate.Generate(fh, sc, nil)
if err != nil {
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion cmd/init/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (m *model) processStages(stage int) error {
return err
}

err = generate.Generate(fh, m.sc)
err = generate.Generate(fh, m.sc, nil)
if err != nil {
m.stageMsg = errorStyle(err.Error())
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/nixgenerate/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (m *model) processStages(stage int) error {
defer fh.FlakeFile.Close()
defer fh.DefFlakeFile.Close()

err = generate.Generate(fh, m.sc)
err = generate.Generate(fh, m.sc, nil)
if err != nil {
m.stageMsg = errorStyle("Failed to generate files: ", err.Error())
return err
Expand Down
10 changes: 7 additions & 3 deletions cmd/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,26 @@ var OCICmd = &cobra.Command{
os.Exit(1)
}
platform = p
nameMap := make(map[string]string)
originalName := artifact.Name
newName := artifact.Name

if tag != "" {
if strings.Contains(artifact.Name, ":") {
parts := strings.Split(artifact.Name, ":")
artifact.Name = fmt.Sprintf("%s:%s", parts[0], tag)
newName = fmt.Sprintf("%s:%s", parts[0], tag)
} else {
artifact.Name = fmt.Sprintf("%s:%s", artifact.Name, tag)
newName = fmt.Sprintf("%s:%s", artifact.Name, tag)
}
}
nameMap[originalName] = newName

sc, fh, err := binit.GetBSFInitializers()
if err != nil {
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
os.Exit(1)
}
err = generate.Generate(fh, sc)
err = generate.Generate(fh, sc, nameMap)

if err != nil {
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
Expand Down
2 changes: 1 addition & 1 deletion cmd/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ var UpdateCmd = &cobra.Command{
os.Exit(1)
}

err = generate.Generate(fh, sc)
err = generate.Generate(fh, sc, nil)
if err != nil {
fmt.Println(styles.ErrorStyle.Render("Error generating files: %s", err.Error()))
os.Exit(1)
Expand Down
10 changes: 9 additions & 1 deletion pkg/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

// Generate reads bsf.hcl, resolves dependencies and generates bsf.lock, bsf/flake.nix, bsf/default.nix, etc.
func Generate(fh *hcl2nix.FileHandlers, sc buildsafev1.SearchServiceClient) error {
func Generate(fh *hcl2nix.FileHandlers, sc buildsafev1.SearchServiceClient, nameMap map[string]string) error {
data, err := os.ReadFile("bsf.hcl")
if err != nil {
return err
Expand All @@ -29,6 +29,14 @@ func Generate(fh *hcl2nix.FileHandlers, sc buildsafev1.SearchServiceClient) erro
return fmt.Errorf("%v", &dstErr)
}

if len(nameMap) > 0 {
for _, artifact := range conf.OCIArtifact {
if newName, ok := nameMap[artifact.Name]; ok {
artifact.Name = newName
}
}
}

ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
defer cancel()

Expand Down

0 comments on commit 392f667

Please sign in to comment.