commit d489ed2bd731f01a78eef3f545cb4541dbee4905
parent 843d1756063f76f8feab39dcca28aff851b659d1
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Thu, 14 Aug 2025 07:57:46 +0200
feat(packer): add naive packer build
Diffstat:
2 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/BuildahBud.groovy b/src/BuildahBud.groovy
@@ -7,7 +7,7 @@ class BuildahBud implements Serializable {
}
// Build with named buildArgs (first)
- // Mandatory: Image name and tag
+ // Mandatory: Image context and name
// Optional: Image tag, architecture, registry, ..
void execute(Map buildArgs = [],
String imgContext,
diff --git a/src/PackerBuild.groovy b/src/PackerBuild.groovy
@@ -0,0 +1,44 @@
+// A class to describe the packer build stage
+class PackerBuild implements Serializable {
+ private final Script script
+
+ PackerBuild(Script script) {
+ this.script = script
+ }
+
+ // Build with named buildVars (first)
+ // Mandatory: Build template
+ // Optional: Build vars, PACKER_LOG
+ void execute(Map buildVars = [],
+ String buildTemplate,
+ Integer packerLog = 0,
+ String stageName = 'build') {
+
+ def varList = buildVars.collect{ k, v -> "-var '${k}=${v}'" }.join(' ')
+ def shInitCmd = sprintf(
+ '''
+ PACKER_NO_COLOR=1 /usr/local/bin/packer init %s
+ ''',
+ buildTemplate
+ )
+ def shBuildCmd = sprintf(
+ '''
+ PACKER_NO_COLOR=1 PACKER_LOG=%d /usr/local/bin/packer build %s %s
+ ''',
+ packerLog, varList, buildTemplate, varList
+ )
+
+ script.stage(stageName) {
+ //script.echo "User ID inside script stage '$stageName':"
+ //script.sh "id"
+ //script.echo "Available lxc download templates:"
+ //script.sh "/usr/share/lxc/templates/lxc-download -l"
+
+ script.echo "Initializing from template ${buildTemplate}..."
+ script.sh shInitCmd
+
+ script.echo "Building from template ${buildTemplate}..."
+ script.sh shBuildCmd
+ }
+ }
+}