-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cleanup combustion
- Loading branch information
Showing
5 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package combustion | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/suse-edge/edge-image-builder/pkg/fileio" | ||
"github.com/suse-edge/edge-image-builder/pkg/image" | ||
"github.com/suse-edge/edge-image-builder/pkg/log" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const ( | ||
cleanupScriptName = "cleanup-combustion.sh" | ||
cleanupComponentName = "cleanup" | ||
) | ||
|
||
//go:embed templates/cleanup-combustion.sh | ||
var cleanupScript string | ||
|
||
func configureCleanup(ctx *image.Context) ([]string, error) { | ||
if ctx.ImageDefinition.Image.ImageType != image.TypeRAW { | ||
log.AuditComponentSkipped(cleanupComponentName) | ||
zap.S().Info("skipping cleanup component, image type is not raw") | ||
return nil, nil | ||
} | ||
|
||
cleanupScriptFilename := filepath.Join(ctx.CombustionDir, cleanupScriptName) | ||
if err := os.WriteFile(cleanupScriptFilename, []byte(cleanupScript), fileio.ExecutablePerms); err != nil { | ||
return nil, fmt.Errorf("writing cleanup files script %s: %w", cleanupScriptName, err) | ||
} | ||
|
||
log.AuditComponentSuccessful(cleanupComponentName) | ||
return []string{cleanupScriptName}, nil | ||
} |
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,52 @@ | ||
package combustion | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/suse-edge/edge-image-builder/pkg/image" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConfigureCleanupRaw(t *testing.T) { | ||
// Setup | ||
ctx, teardown := setupContext(t) | ||
defer teardown() | ||
ctx.ImageDefinition.Image.ImageType = image.TypeRAW | ||
|
||
// Test | ||
scriptNames, err := configureCleanup(ctx) | ||
|
||
// Verify | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, []string{cleanupScriptName}, scriptNames) | ||
|
||
// -- Combustion Script | ||
expectedCombustionScript := filepath.Join(ctx.CombustionDir, cleanupScriptName) | ||
contents, err := os.ReadFile(expectedCombustionScript) | ||
require.NoError(t, err) | ||
assert.Contains(t, string(contents), "rm -r /artefacts") | ||
} | ||
|
||
func TestConfigureCleanupISO(t *testing.T) { | ||
// Setup | ||
ctx, teardown := setupContext(t) | ||
defer teardown() | ||
ctx.ImageDefinition.Image.ImageType = image.TypeISO | ||
|
||
// Test | ||
scriptNames, err := configureCleanup(ctx) | ||
|
||
// Verify | ||
require.NoError(t, err) | ||
|
||
assert.NotEqual(t, []string{cleanupScriptName}, scriptNames) | ||
|
||
// -- Combustion Script | ||
expectedCombustionScript := filepath.Join(ctx.CombustionDir, cleanupScriptName) | ||
assert.NoFileExists(t, expectedCombustionScript) | ||
} |
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,8 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
rm -r /combustion | ||
|
||
if test -d /artefacts; then | ||
rm -r /artefacts | ||
fi |