Skip to content

Commit 5ecbcb4

Browse files
fix: platform bug (#12)
Signed-off-by: Rakshit Gondwal <rakshitgondwal3@gmail.com>
1 parent 6066348 commit 5ecbcb4

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

cmd/dockerfile/df.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@ var DFCmd = &cobra.Command{
4040
fmt.Println(styles.HintStyle.Render("hint:", "run `bsf dockerfile <environment name>` to export the environment"))
4141
os.Exit(1)
4242
}
43-
env, err := ocicmd.ProcessPlatformAndConfig(platform, args[0])
43+
env, p, err := ocicmd.ProcessPlatformAndConfig(platform, args[0])
4444
if err != nil {
4545
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
4646
os.Exit(1)
4747
}
48+
platform = p
4849

4950
sc, fh, err := binit.GetBSFInitializers()
5051
if err != nil {

cmd/oci/oci.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ var OCICmd = &cobra.Command{
4545
os.Exit(1)
4646
}
4747

48-
env, err := ProcessPlatformAndConfig(platform, args[0])
48+
env, p, err := ProcessPlatformAndConfig(platform, args[0])
4949
if err != nil {
5050
fmt.Println(styles.ErrorStyle.Render("error: ", err.Error()))
5151
os.Exit(1)
5252
}
53+
platform = p
5354

5455
sc, fh, err := binit.GetBSFInitializers()
5556
if err != nil {
@@ -180,31 +181,31 @@ func findPlatform(platform string) (string, string) {
180181
}
181182

182183
// ProcessPlatformAndConfig processes the platform and config file
183-
func ProcessPlatformAndConfig(platform string, envName string) (hcl2nix.OCIArtifact, error) {
184-
if platform == "" {
185-
tos, tarch := findPlatform(platform)
186-
platform = tos + "/" + tarch
184+
func ProcessPlatformAndConfig(plat string, envName string) (hcl2nix.OCIArtifact, string, error) {
185+
if plat == "" {
186+
tos, tarch := findPlatform(plat)
187+
plat = tos + "/" + tarch
187188
}
188189

189190
pfound := false
190191
for _, sp := range supportedPlatforms {
191-
if strings.Contains(platform, sp) {
192+
if strings.Contains(plat, sp) {
192193
pfound = true
193194
break
194195
}
195196
}
196197
if !pfound {
197-
return hcl2nix.OCIArtifact{}, fmt.Errorf("Platform %s is not supported. Supported platforms are %s", platform, strings.Join(supportedPlatforms, ", "))
198+
return hcl2nix.OCIArtifact{}, "", fmt.Errorf("Platform %s is not supported. Supported platforms are %s", platform, strings.Join(supportedPlatforms, ", "))
198199
}
199200
data, err := os.ReadFile("bsf.hcl")
200201
if err != nil {
201-
return hcl2nix.OCIArtifact{}, fmt.Errorf("error: %s", err.Error())
202+
return hcl2nix.OCIArtifact{}, "", fmt.Errorf("error: %s", err.Error())
202203
}
203204

204205
var dstErr bytes.Buffer
205206
conf, err := hcl2nix.ReadConfig(data, &dstErr)
206207
if err != nil {
207-
return hcl2nix.OCIArtifact{}, fmt.Errorf(dstErr.String())
208+
return hcl2nix.OCIArtifact{}, "", fmt.Errorf(dstErr.String())
208209
}
209210

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

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

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

231-
return env, nil
232+
return env, plat, nil
232233
}
233234

234235
func genOCIAttrName(env, platform string) string {

0 commit comments

Comments
 (0)