Skip to content

Commit

Permalink
feat(action): pass env vars into coreboot container
Browse files Browse the repository at this point in the history
Signed-off-by: AtomicFS <[email protected]>
  • Loading branch information
AtomicFS committed Jan 8, 2025
1 parent 254a9c5 commit 70450ac
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion action/recipes/coreboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"dagger.io/dagger"
"github.com/9elements/firmware-action/action/container"
"github.com/9elements/firmware-action/action/environment"
"github.com/9elements/firmware-action/action/filesystem"
"github.com/9elements/firmware-action/action/logging"
)
Expand Down Expand Up @@ -378,7 +379,15 @@ func (opts CorebootOpts) buildFirmware(ctx context.Context, client *dagger.Clien
)

// Setup environment variables in the container
envVars := map[string]string{}
// envVars := map[string]string{}
envVars, err := crebootPassEnvVars(opts.RepoPath)
if err != nil {
slog.Error(
"Failed to extract environment variables from current environment",
slog.Any("error", err),
)
return myContainerPrevious, fmt.Errorf("coreboot build failed: %w", err)
}
for key, value := range envVars {
myContainer = myContainer.WithEnvVariable(key, value)
}
Expand All @@ -401,3 +410,41 @@ func (opts CorebootOpts) buildFirmware(ctx context.Context, client *dagger.Clien
// Extract artifacts
return myContainer, container.GetArtifacts(ctx, myContainer, opts.CommonOpts.GetArtifacts())
}

func crebootPassEnvVars(repoPath string) (map[string]string, error) {
passVariables := []string{"KERNELVERSION", "BUILD_TIMELESS"}
envVariables := environment.FetchEnvVars(passVariables)

// Get current working directory
pwd, err := os.Getwd()
if err != nil {
return nil, err
}

// If KERNELVERSION is not defined in current environment
if _, ok := envVariables["KERNELVERSION"]; ok {
// Check if repoPath differs from PWD
if pwd != filepath.Join(pwd, repoPath) {
// This means that the target repository is sub-directory
// (possibly a git submodule)
// coreboot make will fail to run 'git describe' because of
// missing '.git' directory once the content of repoPath
// is copied into the container
// Run 'git describe' now and create a new environment variable
// to pass over into the container
// This way, the compiled coreboot binary will not have unknown version

// To check for coreboot version:
// $ cbfstool build/coreboot.rom extract -n build_info -f /tmp/foo
// $ grep COREBOOT_VERSION /tmp/foo

describe, err := filesystem.GitDescribeCoreboot(repoPath)
if err != nil {
return nil, err
}
envVariables["KERNELVERSION"] = describe
}
}

return envVariables, nil
}

0 comments on commit 70450ac

Please sign in to comment.