-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add DirStructure type Signed-off-by: Atanas Dinov <[email protected]> * Decouple dir structure handling from Builder Signed-off-by: Atanas Dinov <[email protected]> * Remove BuildConfig type Signed-off-by: Atanas Dinov <[email protected]> * Rename DirStructure type to Context Signed-off-by: Atanas Dinov <[email protected]> * Move CleanUpBuildDir out of the Context type Signed-off-by: Atanas Dinov <[email protected]> --------- Signed-off-by: Atanas Dinov <[email protected]>
- Loading branch information
1 parent
5cf336d
commit 52147f3
Showing
15 changed files
with
259 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type Context struct { | ||
// ImageConfigDir is the root directory storing all configuration files. | ||
ImageConfigDir string | ||
// BuildDir is the directory used for assembling the different components used in a build. | ||
BuildDir string | ||
// CombustionDir is a subdirectory under BuildDir containing the Combustion script and all related files. | ||
CombustionDir string | ||
// DeleteBuildDir indicates whether the BuildDir should be cleaned up after the image is built. | ||
DeleteBuildDir bool | ||
} | ||
|
||
func NewContext(imageConfigDir, buildDir string, deleteBuildDir bool) (*Context, error) { | ||
if buildDir == "" { | ||
tmpDir, err := os.MkdirTemp("", "eib-") | ||
if err != nil { | ||
return nil, fmt.Errorf("creating a temporary build directory: %w", err) | ||
} | ||
buildDir = tmpDir | ||
} | ||
combustionDir := filepath.Join(buildDir, "combustion") | ||
|
||
if err := os.MkdirAll(combustionDir, os.ModePerm); err != nil { | ||
return nil, fmt.Errorf("creating the combustion directory: %w", err) | ||
} | ||
|
||
return &Context{ | ||
ImageConfigDir: imageConfigDir, | ||
BuildDir: buildDir, | ||
CombustionDir: combustionDir, | ||
DeleteBuildDir: deleteBuildDir, | ||
}, nil | ||
} | ||
|
||
func CleanUpBuildDir(c *Context) error { | ||
if c.DeleteBuildDir { | ||
err := os.RemoveAll(c.BuildDir) | ||
if err != nil { | ||
return fmt.Errorf("deleting build directory: %w", err) | ||
} | ||
} | ||
return nil | ||
} |
Oops, something went wrong.