Skip to content

Commit

Permalink
feat [close #111]: Add version key to recipe
Browse files Browse the repository at this point in the history
Adds a version key to the recipe to ensure the passed recipe is supported by the vib version being used
  • Loading branch information
axtloss committed Dec 19, 2024
1 parent a383988 commit 3bbd79d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- name: Build
run: |
./set_new_version ${{ github.ref_name }}
go get ./...
make build
Expand Down
1 change: 1 addition & 0 deletions api/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Source struct {
type Recipe struct {
Name string
Id string
Vibversion string
Stages []Stage
Path string
ParentPath string
Expand Down
10 changes: 5 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import (
"github.com/spf13/cobra"
)

var Version = "0.7.4"
var Version = "0.0.0"
var IsRoot = false
var OrigUID = 1000
var OrigGID = 1000
var OrigUser = "user"

var rootCmd = &cobra.Command{
Use: "vib",
Short: "Vib is a tool to build container images from recipes using modules",
Long: "Vib is a tool to build container images from YAML recipes using modules to define the steps to build the image.",
Use: "vib",
Short: "Vib is a tool to build container images from recipes using modules",
Long: "Vib is a tool to build container images from YAML recipes using modules to define the steps to build the image.",
SilenceUsage: true,
Version: Version,
Version: Version,
}

// Initialize the root command with build, test, and compile commands
Expand Down
25 changes: 25 additions & 0 deletions core/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import (
"net/http"
"os"
"path/filepath"
"strconv"
"strings"

"github.com/vanilla-os/vib/api"
"gopkg.in/yaml.v3"
)

var Min_Recipe_Version = []uint8{1, 0, 0}

// LoadRecipe loads a recipe from a file and returns a Recipe
// Does not validate the recipe but it will catch some errors
// a proper validation will be done in the future
Expand Down Expand Up @@ -44,6 +47,28 @@ func LoadRecipe(path string) (*api.Recipe, error) {
return nil, err
}

if len(strings.TrimSpace(recipe.Vibversion)) <= 0 {
return nil, fmt.Errorf("version key not found in recipe file, assuming outdated recipe")
}

recipeVersionS := strings.Split(recipe.Vibversion, ".")
if len(recipeVersionS) != 3 {
return nil, fmt.Errorf("invalid version format, expected x.x.x, got %s", recipe.Vibversion)
}

recipeVersion := []uint8{0, 0, 0}
for i := 0; i < len(recipeVersion); i++ {
versionInt, err := strconv.ParseUint(recipeVersionS[i], 10, 0)
if err != nil {
return nil, err
}
recipeVersion[i] = uint8(versionInt)

Check failure

Code scanning / CodeQL

Incorrect conversion between integer types High

Incorrect conversion of an integer with architecture-dependent bit size from
strconv.ParseUint
to a lower bit size type uint8 without an upper bound check.
Incorrect conversion of an integer with architecture-dependent bit size from
strconv.ParseUint
to a lower bit size type uint8 without an upper bound check.
}

if recipeVersion[0] < Min_Recipe_Version[0] || recipeVersion[1] < Min_Recipe_Version[1] || recipeVersion[2] < Min_Recipe_Version[2] {
return nil, fmt.Errorf("outdated recipe, this version of vib supports recipes starting at version %s", strings.Join(strings.Fields(fmt.Sprint(Min_Recipe_Version)), "."))
}

// the recipe path is stored in the recipe itself
// for convenience
recipe.Path = recipePath
Expand Down

0 comments on commit 3bbd79d

Please sign in to comment.