Skip to content

Commit

Permalink
modules can not be stored in multiple files using the gen-modules type
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin committed May 5, 2023
1 parent a20cbb7 commit d58e2c2
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 11 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Each module specifies a specific step needed to build the image. Each module has
```yaml
name: module-name
type: module-type
path: modules-path
source:
packages: module-source-packages
path: module-source-path
Expand All @@ -52,7 +53,8 @@ modules: {}
### Description of Fields

* `name`: a string representing the name of the module. This will be used as the identifier for the module so it must be unique.
* `type`: a string indicating the type of module. Currently, the supported types are "apt", "cmake", "dpkg", "dpkg-buildpackage", "go", "make" and "meson".
* `type`: a string indicating the type of module. Currently, the supported types are "apt", "cmake", "dpkg", "dpkg-buildpackage", "go", "make", "meson" and "gen-modules".
* `path`: a string indicating the path where the modules to generate are located. Only used if type is "gen-modules".
* `source`: an object containing the information necessary to retrieve the source code for the module. The fields within this object depend on the module type.
* `packages`: a string indicating the name of the package(s) to install, only used if type is "apt".
* `paths`: a list of strings indicating the path to .deb files (or just a list of prefixes to search for .deb files) when used with"dpkg" or "dpkg-buildpackage", or a list of paths to .inst files which contain a list of packages to install when used with "apt".
Expand Down
54 changes: 54 additions & 0 deletions core/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,59 @@ func LoadRecipe(path string) (*Recipe, error) {
}
}

// here we expand modules of type "gen-modules"
newRecipeModules := []Module{}

for _, module := range recipe.Modules {
if module.Type == "gen-modules" {
genModulePaths, err := filepath.Glob(filepath.Join(recipe.ParentPath, module.Path, "*.yml"))
if err != nil {
return nil, err
}

genModules := []Module{}

for _, genModulePath := range genModulePaths {
genModule, err := GenModule(genModulePath)

if err != nil {
return nil, err
}

genModules = append(genModules, genModule)
}

newRecipeModules = append(newRecipeModules, genModules...)
continue
}

newRecipeModules = append(newRecipeModules, module)
}

recipe.Modules = newRecipeModules

return recipe, nil
}

// GenModule generate a Module struct from a module path
func GenModule(modulePath string) (Module, error) {
module := &Module{}

moduleFile, err := os.Open(modulePath)
if err != nil {
return *module, err
}
defer moduleFile.Close()

moduleYAML, err := io.ReadAll(moduleFile)
if err != nil {
return *module, err
}

err = yaml.Unmarshal(moduleYAML, module)
if err != nil {
return *module, err
}

return *module, nil
}
1 change: 1 addition & 0 deletions core/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Recipe struct {
type Module struct {
Name string `json:"name"`
Type string `json:"type"`
Path string `json:"path"`
Source Source `json:"source"`
Modules []Module `json:"modules"`
BuildFlags string `json:"buildFlags"`
Expand Down
4 changes: 3 additions & 1 deletion example/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ ADD includes.container /
ADD sources /sources
RUN apt install -y libbtrfs-dev
RUN cd /sources/abroot-git && go build -o abroot-git
RUN apt install -y base-files apx abroot ikaros vanilla-system-operator
RUN apt install -y curl
RUN apt install -y base-files apx abroot ikaros vanilla-system-operator
RUN apt install -y nano
10 changes: 8 additions & 2 deletions example/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ args:
DEBIAN_FRONTEND: noninteractive
runs:
- echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/01norecommends

modules:
- name: abroot-git
type: go
Expand All @@ -21,8 +22,13 @@ modules:
source:
packages:
- libbtrfs-dev
- name: vanilla-packages

- name: packages
type: apt
source:
paths:
- inst/00-vanilla
- inst/00-test

- name: packages-modules
type: gen-modules
path: modules
1 change: 1 addition & 0 deletions example/inst/00-test.inst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl
6 changes: 0 additions & 6 deletions example/inst/00-vanilla.inst

This file was deleted.

10 changes: 10 additions & 0 deletions example/modules/00-vanilla.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: vanilla-packages
type: apt
source:
packages:
- base-files
- apx
- abroot
- ikaros
- vanilla-system-operator

6 changes: 6 additions & 0 deletions example/modules/10-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: test
type: apt
source:
packages:
- nano

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

var (
Version = "0.1.0"
Version = "0.2.0"
)

func main() {
Expand Down

0 comments on commit d58e2c2

Please sign in to comment.