Skip to content

Commit

Permalink
fix: platform bug (#12)
Browse files Browse the repository at this point in the history
Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com>
  • Loading branch information
rakshitgondwal committed Jun 7, 2024
1 parent 6066348 commit 5ecbcb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion cmd/dockerfile/df.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ var DFCmd = &cobra.Command{
fmt.Println(styles.HintStyle.Render("hint:", "run `bsf dockerfile <environment name>` to export the environment"))
os.Exit(1)
}
env, err := ocicmd.ProcessPlatformAndConfig(platform, args[0])
env, p, err := ocicmd.ProcessPlatformAndConfig(platform, args[0])
if err != nil {
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
os.Exit(1)
}
platform = p

sc, fh, err := binit.GetBSFInitializers()
if err != nil {
Expand Down
25 changes: 13 additions & 12 deletions cmd/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ var OCICmd = &cobra.Command{
os.Exit(1)
}

env, err := ProcessPlatformAndConfig(platform, args[0])
env, p, err := ProcessPlatformAndConfig(platform, args[0])
if err != nil {
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
os.Exit(1)
}
platform = p

sc, fh, err := binit.GetBSFInitializers()
if err != nil {
Expand Down Expand Up @@ -180,31 +181,31 @@ func findPlatform(platform string) (string, string) {
}

// ProcessPlatformAndConfig processes the platform and config file
func ProcessPlatformAndConfig(platform string, envName string) (hcl2nix.OCIArtifact, error) {
if platform == "" {
tos, tarch := findPlatform(platform)
platform = tos + "/" + tarch
func ProcessPlatformAndConfig(plat string, envName string) (hcl2nix.OCIArtifact, string, error) {
if plat == "" {
tos, tarch := findPlatform(plat)
plat = tos + "/" + tarch
}

pfound := false
for _, sp := range supportedPlatforms {
if strings.Contains(platform, sp) {
if strings.Contains(plat, sp) {
pfound = true
break
}
}
if !pfound {
return hcl2nix.OCIArtifact{}, fmt.Errorf("Platform %s is not supported. Supported platforms are %s", platform, strings.Join(supportedPlatforms, ", "))
return hcl2nix.OCIArtifact{}, "", fmt.Errorf("Platform %s is not supported. Supported platforms are %s", platform, strings.Join(supportedPlatforms, ", "))
}
data, err := os.ReadFile("bsf.hcl")
if err != nil {
return hcl2nix.OCIArtifact{}, fmt.Errorf("error: %s", err.Error())
return hcl2nix.OCIArtifact{}, "", fmt.Errorf("error: %s", err.Error())
}

var dstErr bytes.Buffer
conf, err := hcl2nix.ReadConfig(data, &dstErr)
if err != nil {
return hcl2nix.OCIArtifact{}, fmt.Errorf(dstErr.String())
return hcl2nix.OCIArtifact{}, "", fmt.Errorf(dstErr.String())
}

envNames := make([]string, 0, len(conf.OCIArtifact))
Expand All @@ -213,7 +214,7 @@ func ProcessPlatformAndConfig(platform string, envName string) (hcl2nix.OCIArtif
for _, ec := range conf.OCIArtifact {
errStr := ec.Validate(conf)
if errStr != nil {
return hcl2nix.OCIArtifact{}, fmt.Errorf("Config for export block %s is invalid\n Error: %s", ec.Name, *errStr)
return hcl2nix.OCIArtifact{}, "", fmt.Errorf("Config for export block %s is invalid\n Error: %s", ec.Name, *errStr)
}

if ec.Environment == envName {
Expand All @@ -225,10 +226,10 @@ func ProcessPlatformAndConfig(platform string, envName string) (hcl2nix.OCIArtif
}

if !found {
return hcl2nix.OCIArtifact{}, fmt.Errorf("error: No such environment found. Valid oci environment that can be built are: %s", strings.Join(envNames, ", "))
return hcl2nix.OCIArtifact{}, "", fmt.Errorf("error: No such environment found. Valid oci environment that can be built are: %s", strings.Join(envNames, ", "))
}

return env, nil
return env, plat, nil
}

func genOCIAttrName(env, platform string) string {
Expand Down

0 comments on commit 5ecbcb4

Please sign in to comment.